@yearofthedan/warp 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -1,69 +1,40 @@
1
1
  # warp
2
2
 
3
- **Audience:** anyone running warp on a project, or deciding whether to.
4
- **Purpose:** what warp does today and how to run it, with links to the pages for writing a config and wiring warp in.
3
+ warp checks a TypeScript codebase against a declared model of its modules. A `warp.config.ts` names the modules and
4
+ what each may use, and warp reports the code that steps outside it:
5
5
 
6
- Architectural fitness checks for TypeScript codebases. A config declares the codebase's modules and what each
7
- may use. warp builds a model from it and the import graph, and reports findings against it, as text
8
- for people, JSON or SARIF for tools, and hook responses for coding agents. `diff` reports only what a change made new
9
- or worse, and with `--since-last-run` only what the last edit did, so it can run after every edit. It covers dependency direction and package use, module surfaces and
10
- re-exports, cycles, cohesion and cognitive complexity.
6
+ - imports outside a module's reach, including packages it doesn't list.
7
+ - imports and re-exports that go around a module's surface.
8
+ - import loops between files and between modules.
9
+ - files and functions that are too large or too tangled to follow.
10
+ - parts of the config that the code no longer uses.
11
11
 
12
- ## Run it
12
+ `warp diff` reports only what a change made new or worse, so it can run on a pull request or after every edit of a
13
+ coding agent.
13
14
 
14
- Needs Node 26 or later. Add warp to the project as a dev dependency:
15
+ ## Quick start
15
16
 
16
- ```sh
17
- pnpm add -D @yearofthedan/warp
18
- ```
19
-
20
- Add a `warp.config.ts` next to the project's `tsconfig.json`, then:
17
+ warp needs Node 26 or later. Add it to the project as a dev dependency:
21
18
 
22
19
  ```sh
23
- pnpm exec warp check # every finding in the working tree
24
- pnpm exec warp diff HEAD # new or worse findings in the working tree since HEAD
25
- pnpm exec warp diff main..feature # new or worse findings between two refs
26
- pnpm exec warp diff main... # new or worse findings since the working tree's branch left main
27
- pnpm exec warp model # the modules the config finds, and the module each file is in
20
+ pnpm add -D @yearofthedan/warp
28
21
  ```
29
22
 
30
- | Flag | Effect |
31
- | --- | --- |
32
- | `--config <file>` | Config path. The project root is its directory. Default: the first of `warp.config.ts`, `.mts`, `.js` and `.mjs` in the current directory. |
33
- | `--ruleset <name>` | Check with one of the config's [rulesets](docs/config.md#rulesets). Default: the one named `default`, if any. |
34
- | `--since-last-run` | With `diff` and no head, compare the working tree with its findings at the last run with this flag. The first run, and the first after `HEAD` moves, compares with the base. |
35
- | `--rules` | With `model`, list the rule settings each module changes. |
36
- | `--json` | With `model`, print the model as JSON, with every module's resolved rule settings. |
37
- | `--reporter <name>` | Output format, default `text`. |
38
- | `--fail` | Exit 1 when there are findings (`check`) or new or worse ones (`diff`). Without it, both exit 0. |
39
-
40
- | Reporter | Output |
41
- | --- | --- |
42
- | `text` | One line per finding, then for `check` the findings counted by rule and module, and a total. For `diff`, findings are marked `new` or `worse (was N)`. |
43
- | `json` | `{ findings }` for `check`; `{ added, worsened, resolved }` for `diff`. Each finding has the same `message`. |
44
- | `sarif` | SARIF 2.1.0 for GitHub code scanning: the findings to act on, with paths from the repository root. |
45
- | `claude-hook` | A Claude Code PostToolUse hook response, or nothing when there is nothing to act on. |
46
- | `omp` | An omp `tool_result` handler result, or nothing when there is nothing to act on. |
47
-
48
- "To act on" means every finding for `check` and the new and worse ones for `diff`.
49
-
50
- ## A starter config
51
-
52
- A starter for a hexagonal layout, to adjust to the project's folders:
23
+ Describe the codebase as it is, one module per folder under `src/`, in a `warp.config.ts` next to the project's
24
+ `tsconfig.json`:
53
25
 
54
26
  ```ts
55
27
  // warp.config.ts
56
- import { all, archetype, defineConfig, exposes, files, pkg, ruleset, using } from '@yearofthedan/warp';
28
+ import { all, archetype, defineConfig, dir, exposes, files, pkg, ruleset, using } from '@yearofthedan/warp';
57
29
 
58
30
  const app = archetype('app')
59
- .contains((m) =>
60
- m
61
- .module('domain', files('src/domain/**'), exposes(all()))
62
- .module('application', files('src/app/**'), exposes(all()).using((m) => [m.domain]))
63
- .module('adapters', files('src/adapters/**'), exposes(all()).using((m) => [m.domain, m.application, pkg('*')]))
64
- .module('lib', files('src/lib/**'), exposes(all()))
65
- .module('entry', files('src/main.ts', 'src/index.ts'), using((m) => [m.domain, m.application, m.adapters, m.lib])),
31
+ .contains((c) =>
32
+ c
33
+ .module('utils', dir('src/utils'), exposes(all()))
34
+ .module('db', dir('src/db'), exposes(all()))
35
+ .module('api', dir('src/api'), exposes(all()).using((m) => [m.db, m.utils, pkg('*')])),
66
36
  )
37
+ .entry(files('src/index.ts'))
67
38
  .tests(using([pkg('vitest')]));
68
39
 
69
40
  const base = ruleset().on(app.modules.tests, { 'function-cohesion': false });
@@ -71,28 +42,32 @@ const base = ruleset().on(app.modules.tests, { 'function-cohesion': false });
71
42
  export default defineConfig({ root: app, tests: files('src/**/*.test.ts'), rulesets: { default: base } });
72
43
  ```
73
44
 
74
- The tests belong to the root module, so they see every module's files, what each module uses, and the test runner.
75
- `function-cohesion` is off for them, because a `describe` callback holds `it` calls that share no locals, which the
76
- rule would ask to split.
45
+ Then check it, and after an edit, see what the edit broke:
77
46
 
78
- Run `warp check` and add modules until no `unclassified` findings are left. The other findings it reports are the
79
- existing baseline, which `diff` leaves out, so they need no fixing first. Commit the config.
47
+ ```sh
48
+ pnpm exec warp check # every finding in the working tree
49
+ pnpm exec warp diff HEAD # what changed since the last commit made new or worse
50
+ ```
80
51
 
81
- - [docs/concepts.md](docs/concepts.md): what warp's terms mean, from module to finding.
82
- - [docs/config.md](docs/config.md): the config, custom rules, rulesets and the rules.
83
- - [docs/agents-and-ci.md](docs/agents-and-ci.md): how `diff` works, and running warp from Claude Code or GitHub code
84
- scanning.
85
- - [integrations/omp/README.md](integrations/omp/README.md): running warp from omp.
52
+ ```text
53
+ new: src/utils/slug.ts:1 [dependency-direction] src/utils/slug.ts (app.utils src/utils) imports src/db/client.ts (app.db src/db), which is outside utils's reach: utils may use nothing. Add what holds src/db/client.ts to a using if the dependency is intended, or move the code.
54
+ ```
86
55
 
87
- ## Compiler
56
+ ## Read next
88
57
 
89
- Analysis uses the TypeScript 7.1 API (`typescript/sync`), pinned to `7.1.0-beta`, which runs the native compiler in a
90
- child process. A spike confirmed it gives the AST, module resolution, and checker symbols with alias resolution, which
91
- is what resolving through barrels needs, so ts-morph and a 5.x/6.x compiler were not needed. Each file's identifiers
92
- are resolved in one batched checker call. The API is beta: expect to adjust when 7.1 ships.
58
+ - [Getting started](docs/getting-started.md): from this config to a clean `warp check` and a first `diff`, step by
59
+ step.
60
+ - [Fixing findings](docs/fixing-findings.md): how to read a finding and decide between changing the code and changing
61
+ the config.
62
+ - [Concepts](docs/concepts.md): what each of warp's terms means.
63
+ - [Config](docs/config.md) and [CLI](docs/cli.md): the reference for each.
64
+ - [Rules](docs/rules.md): every rule warp checks, each with its page.
65
+ - [Agents and CI](docs/agents-and-ci.md): running warp after each edit of Claude Code or omp, and on pull requests.
66
+ - [Hexagonal layout](docs/examples/hexagonal.md): a stricter config, for ports and adapters.
93
67
 
94
68
  ## Limits
95
69
 
96
- - Dynamic `import()`, `require()` and `import x = require()` are not edges yet.
70
+ - warp follows static `import` and `export … from` declarations. Dependencies through `import()`, `require()` and
71
+ `import x = require()` go unchecked.
97
72
  - A namespace import (`import * as x`) points at the module the specifier resolves to, a barrel included.
98
- - Class methods are not checked for cohesion against each other; each method gets the function rules.
73
+ - Each class method is checked as a function of its own, and a class is one member of its file.
@@ -34,7 +34,7 @@ const refused = (context, from, to, refusal, edges) => {
34
34
  details: {
35
35
  from: source.id,
36
36
  to: target.id,
37
- reason: refusal.reason,
37
+ reason: isLoose(model, to) ? 'loose' : refusal.reason,
38
38
  ...(refusal.reason === 'private' ? { hiddenBy: refusal.hiddenBy.id } : {}),
39
39
  edges,
40
40
  },
@@ -42,6 +42,8 @@ const refused = (context, from, to, refusal, edges) => {
42
42
  };
43
43
  const explain = ({ config, model, verdicts }, from, to, refusal) => {
44
44
  const source = model.moduleOf(from);
45
+ if (isLoose(model, to))
46
+ return `which is in no module yet. Add a module that holds ${to}, then add it to a using if the dependency is intended.`;
45
47
  if (refusal.reason === 'test')
46
48
  return 'a test file. Production code never imports tests: move what both need out of the test file into the module it tests.';
47
49
  if (refusal.reason === 'private') {
@@ -58,8 +60,9 @@ const explain = ({ config, model, verdicts }, from, to, refusal) => {
58
60
  const uses = Map.groupBy(verdicts.reach(from).filter((grant) => grant.ref !== undefined), (grant) => grant.owner);
59
61
  const reaches = uses.size > 0
60
62
  ? `: ${[...uses].map(([by, grants]) => `${by} uses ${grants.map((grant) => grant.ref).join(', ')}`).join('; ')}`
61
- : ', its own files only';
63
+ : `: ${owner} may use nothing`;
62
64
  return (`which is outside ${owner}'s reach${reaches}. ` +
63
65
  `Add what holds ${to} to a using if the dependency is intended, or move the code.`);
64
66
  };
67
+ const isLoose = (model, file) => model.moduleOf(file).looseFiles.includes(file);
65
68
  const namedArchetype = (config, name) => config.archetypes[name].inline ? namedArchetype(config, name.slice(0, name.lastIndexOf('.'))) : name;
package/dist/cli.js CHANGED
@@ -27,15 +27,15 @@ check reports every finding in the working tree.
27
27
  diff reports findings that are new or worse at <head> than at <base>. Without <head>, compares the working tree.
28
28
  <base>...<head> compares from where <head> left <base>, as git does.
29
29
  With --since-last-run, compares the working tree with the last such run, or with <base> if there is none.
30
- model prints the modules the config finds, and which part each file is in.
30
+ model prints the modules the config finds, and which module each file is in.
31
31
 
32
32
  --config path to the config file (default: the first of warp.config.ts, .mts, .js, .mjs)
33
33
  --ruleset one of the config's rulesets (default: the one named default, if any)
34
34
  --reporter ${[...reporters.keys()].join(', ')} (default: text)
35
35
  --since-last-run with diff, compare with the last diff run that had this flag
36
36
  --fail exit 1 when there are findings (check) or new or worse findings (diff)
37
- --rules with model, list each module's and part's rule settings that differ from the defaults
38
- --json print the model as JSON, with every module's and part's resolved rule settings`;
37
+ --rules with model, list each module's rule settings that differ from the defaults
38
+ --json print the model as JSON, with every module's resolved rule settings`;
39
39
  const adaptersAt = (root) => {
40
40
  const adapters = { analyzer: typescriptAnalyzer, foldersAt: diskFolders };
41
41
  try {
@@ -13,17 +13,11 @@ export const gitRepository = (projectRoot) => {
13
13
  mergeBase: (a, b) => git('merge-base', a, b),
14
14
  changedLines: (base, head) => changedLines(git, base, head),
15
15
  checkout(commit, requiredFile) {
16
- const dir = mkdtempSync(join(tmpdir(), 'warp-'));
17
- const dispose = () => {
18
- try {
19
- git('worktree', 'remove', '--force', dir);
20
- }
21
- finally {
22
- rmSync(dir, { recursive: true, force: true });
23
- }
24
- };
16
+ const scratch = mkdtempSync(join(tmpdir(), 'warp-'));
17
+ const dir = join(scratch, 'tree');
18
+ const dispose = () => rmSync(scratch, { recursive: true, force: true });
25
19
  try {
26
- git('worktree', 'add', '--detach', '--quiet', dir, commit);
20
+ exportTree(top, commit, scratch, dir);
27
21
  const root = join(dir, projectPath);
28
22
  if (!existsSync(join(root, requiredFile)))
29
23
  return { dispose };
@@ -36,17 +30,18 @@ export const gitRepository = (projectRoot) => {
36
30
  return { projectRoot: root, dispose };
37
31
  }
38
32
  catch (error) {
39
- try {
40
- dispose();
41
- }
42
- catch {
43
- throw error;
44
- }
33
+ dispose();
45
34
  throw error;
46
35
  }
47
36
  },
48
37
  };
49
38
  };
39
+ const exportTree = (cwd, commit, scratch, dir) => {
40
+ const env = { ...process.env, GIT_INDEX_FILE: join(scratch, 'index'), GIT_LFS_SKIP_SMUDGE: '1' };
41
+ const git = (...args) => execFileSync('git', args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
42
+ git('read-tree', commit);
43
+ git('checkout-index', '--all', `--prefix=${dir}${sep}`);
44
+ };
50
45
  export const projectPathOf = (projectRoot) => {
51
46
  try {
52
47
  return gitRepository(projectRoot).projectPath();
@@ -272,12 +272,16 @@ const filesModule = (resolution, module, archetype, candidates, file) => {
272
272
  return undefined;
273
273
  const best = matches.reduce((top, match) => (match.score > top.score ? match : top));
274
274
  const tied = matches.filter((match) => match.module !== best.module && match.score === best.score);
275
- if (tied.length > 0) {
276
- const names = [best, ...tied].map((match) => `${match.module} ('${match.pattern}')`).join(' and ');
277
- resolution.errors.add(`${file}: ${archetype.name}'s files modules ${names} are equally specific; narrow one of the patterns`);
278
- }
275
+ if (tied.length > 0)
276
+ resolution.errors.add(`${file}: ${archetype.name}'s ${tie([best, ...tied])}`);
279
277
  return best.module;
280
278
  };
279
+ const tie = (clash) => {
280
+ const names = clash.map((match) => `${match.module} ('${match.pattern}')`).join(' and ');
281
+ const folders = clash.every((match) => match.pattern.endsWith('/**'));
282
+ const fix = folders ? 'declare the folders with dir(), where the deeper folder wins' : 'narrow one of the patterns';
283
+ return `files modules ${names} are equally specific; ${fix}`;
284
+ };
281
285
  export const specificity = (pattern) => {
282
286
  if (!pattern.includes('*'))
283
287
  return Number.POSITIVE_INFINITY;
@@ -0,0 +1,4 @@
1
+ import { type Report } from './reporter.ts';
2
+ export declare const shownFindings = 20;
3
+ export declare const shownChars = 500;
4
+ export declare const agentContext: (report: Report) => string;
@@ -0,0 +1,24 @@
1
+ import { actionable, ruleDocs } from './reporter.js';
2
+ import { diffLines, diffSummary, line } from './text.js';
3
+ export const shownFindings = 20;
4
+ export const shownChars = 500;
5
+ export const agentContext = (report) => {
6
+ const body = report.mode === 'diff'
7
+ ? [
8
+ 'New or worse architecture fitness findings. Address them if this edit caused them:',
9
+ ...shown(diffLines(report.delta)),
10
+ '',
11
+ diffSummary(report.delta),
12
+ ]
13
+ : ['Architecture fitness findings:', ...shown(report.findings.map(line))];
14
+ const docs = ruleDocs(actionable(report));
15
+ return [
16
+ ...body,
17
+ ...(docs.length === 0 ? [] : ['', 'Rule docs:', ...docs.map(([rule, url]) => `- ${rule}: ${url}`)]),
18
+ ].join('\n');
19
+ };
20
+ const shown = (lines) => [
21
+ ...lines.slice(0, shownFindings).map(clipped),
22
+ ...(lines.length > shownFindings ? [`...and ${lines.length - shownFindings} more, not shown here.`] : []),
23
+ ];
24
+ const clipped = (text) => (text.length > shownChars ? `${text.slice(0, shownChars)}...` : text);
@@ -1,10 +1,10 @@
1
- import { actionable, agentContext, unavailable } from './reporter.js';
2
- import { diffText, line } from './text.js';
1
+ import { actionable, unavailable } from './reporter.js';
2
+ import { agentContext } from './agent.js';
3
3
  const warnWithoutBlocking = 1;
4
4
  const response = (additionalContext) => JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext } });
5
5
  export const claudeHookReporter = {
6
6
  id: 'claude-hook',
7
- render: (report) => actionable(report).length === 0 ? '' : response(agentContext(report, { delta: diffText, finding: line })),
7
+ render: (report) => (actionable(report).length === 0 ? '' : response(agentContext(report))),
8
8
  renderFailure: (problem) => response(unavailable(problem)),
9
9
  failureExitCode: warnWithoutBlocking,
10
10
  };
@@ -1,8 +1,6 @@
1
- import { actionable, agentContext } from './reporter.js';
2
- import { diffText, line } from './text.js';
1
+ import { actionable } from './reporter.js';
2
+ import { agentContext } from './agent.js';
3
3
  export const ompReporter = {
4
4
  id: 'omp',
5
- render: (report) => actionable(report).length === 0
6
- ? ''
7
- : JSON.stringify({ additionalContext: agentContext(report, { delta: diffText, finding: line }) }),
5
+ render: (report) => actionable(report).length === 0 ? '' : JSON.stringify({ additionalContext: agentContext(report) }),
8
6
  };
@@ -19,8 +19,4 @@ export interface Reporter {
19
19
  }
20
20
  export declare const unavailable: (problem: string) => string;
21
21
  export declare const actionable: (report: Report) => Finding[];
22
- export declare const agentContext: (report: Report, render: {
23
- delta: (delta: Delta) => string;
24
- finding: (finding: Finding) => string;
25
- }) => string;
26
22
  export declare const ruleDocs: (findings: Finding[]) => [string, string][];
@@ -1,14 +1,5 @@
1
1
  export const unavailable = (problem) => `Warp architecture feedback is unavailable, so edits are not checked: ${problem}`;
2
2
  export const actionable = (report) => report.mode === 'check' ? report.findings : [...report.delta.added, ...report.delta.worsened];
3
- export const agentContext = (report, render) => {
4
- const body = report.mode === 'diff'
5
- ? `New or worse architecture fitness findings. Address them if this edit caused them:\n${render.delta(report.delta)}`
6
- : `Architecture fitness findings:\n${report.findings.map(render.finding).join('\n')}`;
7
- const docs = ruleDocs(actionable(report));
8
- return docs.length === 0
9
- ? body
10
- : `${body}\n\nRule docs:\n${docs.map(([rule, url]) => `- ${rule}: ${url}`).join('\n')}`;
11
- };
12
3
  export const ruleDocs = (findings) => [
13
4
  ...new Map(findings.flatMap((finding) => (finding.docs ? [[finding.rule, finding.docs]] : []))),
14
5
  ];
@@ -3,4 +3,6 @@ import type { Finding } from '../rules/rule.ts';
3
3
  import type { Reporter } from './reporter.ts';
4
4
  export declare const textReporter: Reporter;
5
5
  export declare const diffText: (delta: Delta) => string;
6
+ export declare const diffLines: (delta: Delta) => string[];
7
+ export declare const diffSummary: (delta: Delta) => string;
6
8
  export declare const line: (finding: Finding) => string;
@@ -15,7 +15,7 @@ const checkText = (findings) => findings.length === 0
15
15
  const summary = (findings) => {
16
16
  const groups = Map.groupBy(findings, (finding) => `${finding.rule}\t${finding.module ?? finding.file}`);
17
17
  const rows = [...groups]
18
- .map(([group, members]) => [...group.split('\t'), String(members.length)])
18
+ .map(([group, members]) => [...group.split('\t').map(escaped), String(members.length)])
19
19
  .toSorted(([rule, module, n], [otherRule, otherModule, other]) => {
20
20
  const byCount = Number(other) - Number(n);
21
21
  return byCount || rule.localeCompare(otherRule) || module.localeCompare(otherModule);
@@ -24,12 +24,16 @@ const summary = (findings) => {
24
24
  return rows.map(([rule, module, n]) => ` ${rule.padEnd(width(0))} ${module.padEnd(width(1))} ${n.padStart(width(2))}`);
25
25
  };
26
26
  export const diffText = (delta) => {
27
- const lines = [
28
- ...delta.added.map((finding) => `new: ${line(finding)}`),
29
- ...delta.worsened.map((finding) => `worse (was ${finding.was}): ${line(finding)}`),
30
- ];
31
- const summary = `${count(delta.added.length, 'new finding')}, ${delta.worsened.length} worsened, ${delta.resolved.length} resolved.`;
32
- return [...lines, ...(lines.length > 0 ? [''] : []), summary].join('\n');
27
+ const lines = diffLines(delta);
28
+ return [...lines, ...(lines.length > 0 ? [''] : []), diffSummary(delta)].join('\n');
33
29
  };
34
- export const line = (finding) => `${finding.file}:${finding.line} [${finding.rule}] ${finding.message}`;
30
+ export const diffLines = (delta) => [
31
+ ...delta.added.map((finding) => `new: ${line(finding)}`),
32
+ ...delta.worsened.map((finding) => `worse (was ${finding.was}): ${line(finding)}`),
33
+ ];
34
+ export const diffSummary = (delta) => `${count(delta.added.length, 'new finding')}, ${delta.worsened.length} worsened, ${delta.resolved.length} resolved.`;
35
+ export const line = (finding) => escaped(`${finding.file}:${finding.line} [${finding.rule}] ${finding.message}`);
36
+ const escaped = (text) => text.replaceAll(/[\p{Cc}\u2028\u2029]/gu, (char) => JSON.stringify(char).length === 4
37
+ ? JSON.stringify(char).slice(1, -1)
38
+ : `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
35
39
  const count = (n, noun) => `${n} ${noun}${n === 1 ? '' : 's'}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yearofthedan/warp",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Architectural fitness checks for TypeScript codebases",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,8 +11,7 @@
11
11
  "warp": "./dist/cli.js"
12
12
  },
13
13
  "files": [
14
- "dist",
15
- "integrations/omp/warp.ts"
14
+ "dist"
16
15
  ],
17
16
  "type": "module",
18
17
  "exports": {
@@ -1,40 +0,0 @@
1
- type ToolResultEvent = { toolName: string; isError: boolean };
2
- type ToolResultEventResult = { additionalContext?: string };
3
- type ExecResult = { stdout: string; stderr: string; code: number };
4
- type Context = { cwd: string };
5
-
6
- export type Extension = {
7
- on(
8
- event: 'tool_result',
9
- handler: (event: ToolResultEvent, context: Context) => Promise<ToolResultEventResult | undefined>,
10
- ): void;
11
- exec(command: string, args: string[], options?: { cwd?: string; timeout?: number }): Promise<ExecResult>;
12
- };
13
-
14
- export const editTools = new Set(['edit', 'write', 'ast_edit', 'apply_patch']);
15
-
16
- export default function warp(pi: Extension, env: Record<string, string | undefined> = process.env): void {
17
- const [command, ...prefix] = (env.WARP_COMMAND ?? 'warp').trim().split(/\s+/);
18
- const base = env.WARP_BASE ?? 'HEAD';
19
- const ruleset = env.WARP_RULESET ? ['--ruleset', env.WARP_RULESET] : [];
20
- let reported: string | undefined;
21
- const health = (problem: string | undefined): ToolResultEventResult | undefined => {
22
- const changed = problem !== reported;
23
- reported = problem;
24
- return problem && changed
25
- ? { additionalContext: `Warp architecture feedback is unavailable, so edits are not checked: ${problem}` }
26
- : undefined;
27
- };
28
- pi.on('tool_result', async (event, context) => {
29
- if (event.isError || !editTools.has(event.toolName)) return undefined;
30
- const run = await pi
31
- .exec(command, [...prefix, 'diff', base, '--since-last-run', ...ruleset, '--reporter', 'omp'], {
32
- cwd: context.cwd,
33
- timeout: 60_000,
34
- })
35
- .catch((error: unknown): ExecResult => ({ stdout: '', stderr: String(error), code: -1 }));
36
- if (run.code !== 0) return health(run.stderr.trim() || `${command} exited with code ${run.code}`);
37
- health(undefined);
38
- return run.stdout.trim() === '' ? undefined : (JSON.parse(run.stdout) as ToolResultEventResult);
39
- });
40
- }