@dreki-gg/pi-code-reviewer 0.2.0 → 0.3.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.
@@ -7,9 +7,9 @@ export function registerReviewLensesCommand(pi: ExtensionAPI) {
7
7
  pi.registerCommand('review-lenses', {
8
8
  description: 'List available review lenses for this project',
9
9
  handler: async (_args, ctx) => {
10
- const config = loadConfig(ctx.cwd);
10
+ const config = await loadConfig(ctx.cwd);
11
11
  const lensDir = getLensDir(ctx.cwd, config);
12
- const available = discoverLenses(lensDir);
12
+ const available = await discoverLenses(lensDir);
13
13
 
14
14
  if (available.size === 0) {
15
15
  ctx.ui.notify(
@@ -40,9 +40,9 @@ export function registerReviewTool(pi: ExtensionAPI) {
40
40
 
41
41
  async execute(_toolCallId, params, signal, onUpdate, ctx) {
42
42
  const cwd = ctx.cwd;
43
- const config = loadConfig(cwd);
43
+ const config = await loadConfig(cwd);
44
44
  const lensDir = getLensDir(cwd, config);
45
- const available = discoverLenses(lensDir);
45
+ const available = await discoverLenses(lensDir);
46
46
 
47
47
  if (available.size === 0) {
48
48
  return {
@@ -85,7 +85,7 @@ export function registerReviewTool(pi: ExtensionAPI) {
85
85
  });
86
86
 
87
87
  const lens = available.get(name)!;
88
- const content = getLensContent(lensDir, name) ?? '';
88
+ const content = (await getLensContent(lensDir, name)) ?? '';
89
89
  const result = await reviewWithLens(pi, ctx, cwd, lens, content, diff, signal);
90
90
  results.push(result);
91
91
  }
@@ -12,9 +12,9 @@ export function registerReviewCommand(pi: ExtensionAPI) {
12
12
  'Run a multi-lens code review on working directory changes. Usage: /review [--lens name,...] [--base ref] [--staged]',
13
13
  handler: async (args, ctx) => {
14
14
  const cwd = ctx.cwd;
15
- const config = loadConfig(cwd);
15
+ const config = await loadConfig(cwd);
16
16
  const lensDir = getLensDir(cwd, config);
17
- const available = discoverLenses(lensDir);
17
+ const available = await discoverLenses(lensDir);
18
18
 
19
19
  if (available.size === 0) {
20
20
  ctx.ui.notify(
@@ -55,7 +55,7 @@ export function registerReviewCommand(pi: ExtensionAPI) {
55
55
  ctx.ui.setStatus('code-review', `🔍 Lens ${i + 1}/${lensNames.length}: ${name}`);
56
56
 
57
57
  const lens = available.get(name)!;
58
- const content = getLensContent(lensDir, name) ?? '';
58
+ const content = (await getLensContent(lensDir, name)) ?? '';
59
59
  const result = await reviewWithLens(pi, ctx, cwd, lens, content, diff);
60
60
 
61
61
  if (result._lensSection) {
@@ -1,30 +1,47 @@
1
- import { readFileSync, existsSync } from 'node:fs';
1
+ /**
2
+ * Review configuration loader.
3
+ *
4
+ * Reading `.code-review.json` is an Effect program against the FileSystem
5
+ * service; a missing or malformed file falls back to defaults (never fails).
6
+ * The Promise wrapper provides the live service for imperative call sites.
7
+ */
8
+
9
+ import { Effect } from 'effect';
2
10
  import { resolve } from 'node:path';
11
+
12
+ import { FileSystem, nodeFileSystemService } from './effects/filesystem';
3
13
  import type { ReviewConfig } from './types';
4
14
 
5
15
  const CONFIG_FILE = '.code-review.json';
6
16
  const DEFAULT_LENS_DIR = '.code-review/lenses';
7
17
 
8
- export function loadConfig(cwd: string): ReviewConfig {
9
- const configPath = resolve(cwd, CONFIG_FILE);
18
+ function defaultConfig(): ReviewConfig {
19
+ return { lensDir: DEFAULT_LENS_DIR, defaultLenses: [] };
20
+ }
21
+
22
+ export function loadConfigEffect(cwd: string): Effect.Effect<ReviewConfig, never, FileSystem> {
23
+ return Effect.gen(function* () {
24
+ const fs = yield* FileSystem;
25
+ const raw = yield* fs.readTextFile(getConfigPath(cwd)).pipe(Effect.either);
26
+ if (raw._tag === 'Left') return defaultConfig();
10
27
 
11
- if (existsSync(configPath)) {
12
28
  try {
13
- const raw = readFileSync(configPath, 'utf-8');
14
- const parsed = JSON.parse(raw) as Partial<ReviewConfig>;
29
+ const parsed = JSON.parse(raw.right) as Partial<ReviewConfig>;
15
30
  return {
16
31
  lensDir: parsed.lensDir ?? DEFAULT_LENS_DIR,
17
32
  defaultLenses: parsed.defaultLenses ?? [],
18
33
  };
19
34
  } catch {
20
- // Malformed config — fall back to defaults
35
+ // Malformed config — fall back to defaults.
36
+ return defaultConfig();
21
37
  }
22
- }
38
+ });
39
+ }
23
40
 
24
- return {
25
- lensDir: DEFAULT_LENS_DIR,
26
- defaultLenses: [],
27
- };
41
+ export function loadConfig(cwd: string): Promise<ReviewConfig> {
42
+ return Effect.runPromise(
43
+ loadConfigEffect(cwd).pipe(Effect.provideService(FileSystem, nodeFileSystemService)),
44
+ );
28
45
  }
29
46
 
30
47
  export function getLensDir(cwd: string, config: ReviewConfig): string {
@@ -1,4 +1,15 @@
1
+ /**
2
+ * Diff collection.
3
+ *
4
+ * Git invocations run through the Executor service as typed Effects. The
5
+ * Promise wrappers build a live Executor from `pi` for imperative call sites.
6
+ */
7
+
1
8
  import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
9
+ import { Effect } from 'effect';
10
+
11
+ import { Executor, makeExecutorService } from './effects/exec';
12
+ import type { ExecError } from './errors';
2
13
 
3
14
  export type DiffSource = {
4
15
  diff: string;
@@ -6,73 +17,88 @@ export type DiffSource = {
6
17
  label: string;
7
18
  };
8
19
 
20
+ export type DiffOptions = { base?: string; staged?: boolean };
21
+
22
+ function git(args: string[], cwd: string): Effect.Effect<string, ExecError, Executor> {
23
+ return Effect.gen(function* () {
24
+ const executor = yield* Executor;
25
+ const result = yield* executor.exec('git', args, { cwd });
26
+ return result.stdout;
27
+ });
28
+ }
29
+
9
30
  /** Collect the diff from the working directory or a specific base ref. */
10
- export async function collectDiff(
11
- pi: ExtensionAPI,
31
+ export function collectDiffEffect(
12
32
  cwd: string,
13
- options: { base?: string; staged?: boolean },
14
- ): Promise<DiffSource> {
15
- if (options.staged) {
16
- const diff = await pi.exec('git', ['diff', '--staged'], { cwd });
17
- const stat = await pi.exec('git', ['diff', '--staged', '--stat'], { cwd });
18
- return {
19
- diff: diff.stdout,
20
- stat: stat.stdout,
21
- label: 'staged changes',
22
- };
23
- }
33
+ options: DiffOptions,
34
+ ): Effect.Effect<DiffSource, ExecError, Executor> {
35
+ return Effect.gen(function* () {
36
+ if (options.staged) {
37
+ const diff = yield* git(['diff', '--staged'], cwd);
38
+ const stat = yield* git(['diff', '--staged', '--stat'], cwd);
39
+ return { diff, stat, label: 'staged changes' };
40
+ }
24
41
 
25
- if (options.base) {
26
- const diff = await pi.exec('git', ['diff', options.base], { cwd });
27
- const stat = await pi.exec('git', ['diff', options.base, '--stat'], { cwd });
28
- return {
29
- diff: diff.stdout,
30
- stat: stat.stdout,
31
- label: `changes since ${options.base}`,
32
- };
33
- }
42
+ if (options.base) {
43
+ const diff = yield* git(['diff', options.base], cwd);
44
+ const stat = yield* git(['diff', options.base, '--stat'], cwd);
45
+ return { diff, stat, label: `changes since ${options.base}` };
46
+ }
34
47
 
35
- // Default: working directory changes (unstaged + staged)
36
- const diff = await pi.exec('git', ['diff', 'HEAD'], { cwd });
37
- const stat = await pi.exec('git', ['diff', 'HEAD', '--stat'], { cwd });
48
+ // Default: working directory changes (unstaged + staged) relative to HEAD.
49
+ const diff = yield* git(['diff', 'HEAD'], cwd);
38
50
 
39
- // If no HEAD diff, fall back to just working directory
40
- if (!diff.stdout.trim()) {
41
- const wdDiff = await pi.exec('git', ['diff'], { cwd });
42
- const wdStat = await pi.exec('git', ['diff', '--stat'], { cwd });
43
- return {
44
- diff: wdDiff.stdout,
45
- stat: wdStat.stdout,
46
- label: 'working directory changes',
47
- };
48
- }
51
+ // If no HEAD diff, fall back to just the working directory.
52
+ if (!diff.trim()) {
53
+ const wdDiff = yield* git(['diff'], cwd);
54
+ const wdStat = yield* git(['diff', '--stat'], cwd);
55
+ return { diff: wdDiff, stat: wdStat, label: 'working directory changes' };
56
+ }
49
57
 
50
- return {
51
- diff: diff.stdout,
52
- stat: stat.stdout,
53
- label: 'all uncommitted changes',
54
- };
58
+ const stat = yield* git(['diff', 'HEAD', '--stat'], cwd);
59
+ return { diff, stat, label: 'all uncommitted changes' };
60
+ });
55
61
  }
56
62
 
57
63
  /** Get a list of changed file paths from the diff. */
58
- export async function getChangedFiles(
59
- pi: ExtensionAPI,
64
+ export function getChangedFilesEffect(
60
65
  cwd: string,
61
- options: { base?: string; staged?: boolean },
62
- ): Promise<string[]> {
63
- const args = ['diff', '--name-only'];
66
+ options: DiffOptions,
67
+ ): Effect.Effect<string[], ExecError, Executor> {
68
+ return Effect.gen(function* () {
69
+ const args = ['diff', '--name-only'];
70
+ if (options.staged) args.push('--staged');
71
+ else if (options.base) args.push(options.base);
72
+ else args.push('HEAD');
64
73
 
65
- if (options.staged) {
66
- args.push('--staged');
67
- } else if (options.base) {
68
- args.push(options.base);
69
- } else {
70
- args.push('HEAD');
71
- }
74
+ const stdout = yield* git(args, cwd);
75
+ return stdout
76
+ .split('\n')
77
+ .map((f) => f.trim())
78
+ .filter(Boolean);
79
+ });
80
+ }
72
81
 
73
- const result = await pi.exec('git', args, { cwd });
74
- return result.stdout
75
- .split('\n')
76
- .map((f) => f.trim())
77
- .filter(Boolean);
82
+ // ── Promise wrappers (live Executor from pi) ──────────────────────────────────
83
+
84
+ export function collectDiff(
85
+ pi: Pick<ExtensionAPI, 'exec'>,
86
+ cwd: string,
87
+ options: DiffOptions,
88
+ ): Promise<DiffSource> {
89
+ return Effect.runPromise(
90
+ collectDiffEffect(cwd, options).pipe(Effect.provideService(Executor, makeExecutorService(pi))),
91
+ );
92
+ }
93
+
94
+ export function getChangedFiles(
95
+ pi: Pick<ExtensionAPI, 'exec'>,
96
+ cwd: string,
97
+ options: DiffOptions,
98
+ ): Promise<string[]> {
99
+ return Effect.runPromise(
100
+ getChangedFilesEffect(cwd, options).pipe(
101
+ Effect.provideService(Executor, makeExecutorService(pi)),
102
+ ),
103
+ );
78
104
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Executor service — wraps `pi.exec` so shelling out (git, lens tools) becomes
3
+ * an injectable, typed Effect. Tests provide a fake executor instead of running
4
+ * real subprocesses.
5
+ */
6
+
7
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
8
+ import { Context, Effect } from 'effect';
9
+
10
+ import { ExecError } from '../errors';
11
+
12
+ export interface ExecOptions {
13
+ cwd?: string;
14
+ timeout?: number;
15
+ signal?: AbortSignal;
16
+ }
17
+
18
+ export interface ExecResult {
19
+ stdout: string;
20
+ stderr: string;
21
+ }
22
+
23
+ export interface ExecutorService {
24
+ readonly exec: (
25
+ command: string,
26
+ args: string[],
27
+ options?: ExecOptions,
28
+ ) => Effect.Effect<ExecResult, ExecError>;
29
+ }
30
+
31
+ export class Executor extends Context.Tag('CodeReviewer/Executor')<Executor, ExecutorService>() {}
32
+
33
+ type ExecCapableApi = Pick<ExtensionAPI, 'exec'>;
34
+
35
+ /** Build a live Executor backed by `pi.exec`. */
36
+ export function makeExecutorService(pi: ExecCapableApi): ExecutorService {
37
+ return {
38
+ exec: (command, args, options) =>
39
+ Effect.tryPromise({
40
+ try: async () => {
41
+ const result = await pi.exec(command, args, options);
42
+ return { stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
43
+ },
44
+ catch: (cause) => new ExecError({ command, args, cause }),
45
+ }),
46
+ };
47
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * FileSystem service — the only place the code-reviewer reads disk.
3
+ *
4
+ * Wrapping Node's `fs/promises` behind an Effect service keeps config and lens
5
+ * loading pure and injectable: tests swap in an in-memory implementation, and
6
+ * read failures surface as typed `FileReadError` values.
7
+ */
8
+
9
+ import { Context, Effect } from 'effect';
10
+ import { readFile, readdir } from 'node:fs/promises';
11
+
12
+ import { FileReadError } from '../errors';
13
+
14
+ export interface FileSystemService {
15
+ /** Read a UTF-8 file, failing with FileReadError when unreadable/missing. */
16
+ readonly readTextFile: (path: string) => Effect.Effect<string, FileReadError>;
17
+ /** List directory entries, failing with FileReadError when the dir is missing. */
18
+ readonly readDirectory: (path: string) => Effect.Effect<string[], FileReadError>;
19
+ }
20
+
21
+ export class FileSystem extends Context.Tag('CodeReviewer/FileSystem')<
22
+ FileSystem,
23
+ FileSystemService
24
+ >() {}
25
+
26
+ export const nodeFileSystemService: FileSystemService = {
27
+ readTextFile: (path) =>
28
+ Effect.tryPromise({
29
+ try: () => readFile(path, 'utf-8'),
30
+ catch: (cause) => new FileReadError({ path, cause }),
31
+ }),
32
+
33
+ readDirectory: (path) =>
34
+ Effect.tryPromise({
35
+ try: () => readdir(path),
36
+ catch: (cause) => new FileReadError({ path, cause }),
37
+ }),
38
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Live Effect layers for the code-reviewer extension.
3
+ *
4
+ * `fileSystemLayer` covers disk-only programs (config + lens loading).
5
+ * `makeRuntimeLayer(pi)` adds the `pi.exec`-backed Executor for git/diff and
6
+ * lens-tool programs.
7
+ */
8
+
9
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
10
+ import { Layer } from 'effect';
11
+
12
+ import { Executor, makeExecutorService } from './exec';
13
+ import { FileSystem, nodeFileSystemService } from './filesystem';
14
+
15
+ export const fileSystemLayer = Layer.succeed(FileSystem, nodeFileSystemService);
16
+
17
+ export function makeRuntimeLayer(pi: Pick<ExtensionAPI, 'exec'>) {
18
+ return Layer.mergeAll(fileSystemLayer, Layer.succeed(Executor, makeExecutorService(pi)));
19
+ }
20
+
21
+ export type CodeReviewerServices = FileSystem | Executor;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Tagged error types for the code-reviewer extension.
3
+ *
4
+ * Modeled with Effect's `Data.TaggedError` so failures are typed and carry
5
+ * structured context. Helpers convert them into human-readable messages and
6
+ * native `Error`s when an Effect crosses back into Promise-land.
7
+ */
8
+
9
+ import { Data } from 'effect';
10
+
11
+ export class FileReadError extends Data.TaggedError('FileReadError')<{
12
+ readonly path: string;
13
+ readonly cause: unknown;
14
+ }> {
15
+ get message(): string {
16
+ return `Failed to read ${this.path}: ${causeMessage(this.cause)}`;
17
+ }
18
+ }
19
+
20
+ export class ExecError extends Data.TaggedError('ExecError')<{
21
+ readonly command: string;
22
+ readonly args: readonly string[];
23
+ readonly cause: unknown;
24
+ }> {
25
+ get message(): string {
26
+ const cmd = [this.command, ...this.args].join(' ');
27
+ return `Command failed: ${cmd}: ${causeMessage(this.cause)}`;
28
+ }
29
+ }
30
+
31
+ export type CodeReviewerError = FileReadError | ExecError;
32
+
33
+ // ── Helpers ───────────────────────────────────────────────────────────────
34
+
35
+ export function causeMessage(cause: unknown): string {
36
+ if (cause instanceof Error) return cause.message;
37
+ return String(cause);
38
+ }
39
+
40
+ export function errorMessage(error: unknown): string {
41
+ if (error instanceof Error) return error.message;
42
+ if (typeof error === 'object' && error !== null && 'message' in error) {
43
+ const message = (error as { message?: unknown }).message;
44
+ if (typeof message === 'string') return message;
45
+ }
46
+ return String(error);
47
+ }
48
+
49
+ /** Convert a tagged/unknown error into a native Error for Promise rejection. */
50
+ export function toNativeError(error: unknown): Error {
51
+ if (error instanceof Error) return error;
52
+ const native = new Error(errorMessage(error));
53
+ if (typeof error === 'object' && error !== null && '_tag' in error) {
54
+ native.name = String((error as { _tag: unknown })._tag);
55
+ }
56
+ return native;
57
+ }
@@ -1,5 +1,7 @@
1
- import { readFileSync, readdirSync, existsSync } from 'node:fs';
2
- import { resolve, basename } from 'node:path';
1
+ import { Effect } from 'effect';
2
+ import { basename, resolve } from 'node:path';
3
+
4
+ import { FileSystem, nodeFileSystemService } from './effects/filesystem';
3
5
  import type { LensConfig, LensSeverity } from './types';
4
6
 
5
7
  type SectionKind = 'top' | 'criteria' | 'tools' | 'severity';
@@ -91,27 +93,52 @@ function parseSeverityRule(trimmed: string, rules: Record<LensSeverity, string>)
91
93
  }
92
94
  }
93
95
 
94
- /** Discover all lens files in a directory. */
95
- export function discoverLenses(lensDir: string): Map<string, LensConfig> {
96
- const lenses = new Map<string, LensConfig>();
96
+ /** Discover all lens files in a directory (missing dir → empty map). */
97
+ export function discoverLensesEffect(
98
+ lensDir: string,
99
+ ): Effect.Effect<Map<string, LensConfig>, never, FileSystem> {
100
+ return Effect.gen(function* () {
101
+ const fs = yield* FileSystem;
102
+ const lenses = new Map<string, LensConfig>();
103
+
104
+ const entries = yield* fs.readDirectory(lensDir).pipe(Effect.either);
105
+ if (entries._tag === 'Left') return lenses;
106
+
107
+ for (const file of entries.right.filter((f) => f.endsWith('.md'))) {
108
+ const content = yield* fs.readTextFile(resolve(lensDir, file)).pipe(Effect.either);
109
+ if (content._tag === 'Left') continue;
110
+ const key = basename(file, '.md');
111
+ lenses.set(key, parseLensFile(content.right, file));
112
+ }
97
113
 
98
- if (!existsSync(lensDir)) return lenses;
114
+ return lenses;
115
+ });
116
+ }
99
117
 
100
- const files = readdirSync(lensDir).filter((f) => f.endsWith('.md'));
118
+ /** Get raw markdown content for a lens to pass to the reviewer agent. */
119
+ export function getLensContentEffect(
120
+ lensDir: string,
121
+ lensName: string,
122
+ ): Effect.Effect<string | null, never, FileSystem> {
123
+ return Effect.gen(function* () {
124
+ const fs = yield* FileSystem;
125
+ const content = yield* fs.readTextFile(resolve(lensDir, `${lensName}.md`)).pipe(Effect.either);
126
+ return content._tag === 'Right' ? content.right : null;
127
+ });
128
+ }
101
129
 
102
- for (const file of files) {
103
- const content = readFileSync(resolve(lensDir, file), 'utf-8');
104
- const config = parseLensFile(content, file);
105
- const key = basename(file, '.md');
106
- lenses.set(key, config);
107
- }
130
+ // ── Promise wrappers (live FileSystem provided) ──────────────────────────────
108
131
 
109
- return lenses;
132
+ export function discoverLenses(lensDir: string): Promise<Map<string, LensConfig>> {
133
+ return Effect.runPromise(
134
+ discoverLensesEffect(lensDir).pipe(Effect.provideService(FileSystem, nodeFileSystemService)),
135
+ );
110
136
  }
111
137
 
112
- /** Get raw markdown content for a lens to pass to the reviewer agent. */
113
- export function getLensContent(lensDir: string, lensName: string): string | null {
114
- const filePath = resolve(lensDir, `${lensName}.md`);
115
- if (!existsSync(filePath)) return null;
116
- return readFileSync(filePath, 'utf-8');
138
+ export function getLensContent(lensDir: string, lensName: string): Promise<string | null> {
139
+ return Effect.runPromise(
140
+ getLensContentEffect(lensDir, lensName).pipe(
141
+ Effect.provideService(FileSystem, nodeFileSystemService),
142
+ ),
143
+ );
117
144
  }
@@ -1,36 +1,39 @@
1
1
  import { platform } from 'node:os';
2
2
  import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
3
+ import { Effect } from 'effect';
4
+
3
5
  import type { DiffSource } from './diff';
6
+ import { Executor, makeExecutorService } from './effects/exec';
4
7
  import type { LensConfig, LensResult } from './types';
5
8
 
6
9
  const isWindows = platform() === 'win32';
7
10
 
8
11
  /** Run project tools specified by a lens and collect their output. */
9
- async function runLensTools(
10
- pi: ExtensionAPI,
12
+ function runLensToolsEffect(
11
13
  cwd: string,
12
14
  tools: string[],
13
15
  signal?: AbortSignal,
14
- ): Promise<Record<string, string>> {
15
- const outputs: Record<string, string> = {};
16
+ ): Effect.Effect<Record<string, string>, never, Executor> {
17
+ return Effect.gen(function* () {
18
+ const executor = yield* Executor;
19
+ const outputs: Record<string, string> = {};
16
20
 
17
- for (const tool of tools) {
18
- if (signal?.aborted) break;
21
+ for (const tool of tools) {
22
+ if (signal?.aborted) break;
19
23
 
20
- try {
21
24
  const [shell, shellArgs] = isWindows ? ['cmd', ['/c', tool]] : ['sh', ['-c', tool]];
22
- const result = await pi.exec(shell, shellArgs, {
23
- cwd,
24
- timeout: 60_000,
25
- signal,
26
- });
27
- outputs[tool] = result.stdout || result.stderr || '(no output)';
28
- } catch {
29
- outputs[tool] = `(tool failed or timed out: ${tool})`;
25
+ const result = yield* executor
26
+ .exec(shell, shellArgs as string[], { cwd, timeout: 60_000, signal })
27
+ .pipe(Effect.either);
28
+
29
+ outputs[tool] =
30
+ result._tag === 'Right'
31
+ ? result.right.stdout || result.right.stderr || '(no output)'
32
+ : `(tool failed or timed out: ${tool})`;
30
33
  }
31
- }
32
34
 
33
- return outputs;
35
+ return outputs;
36
+ });
34
37
  }
35
38
 
36
39
  /** Build the shared diff section of the review prompt (included once). */
@@ -125,9 +128,31 @@ function buildReviewPrompt(
125
128
  return parts.join('\n');
126
129
  }
127
130
 
128
- /** Execute a review for a single lens using the subagent tool. */
129
- export async function reviewWithLens(
130
- pi: ExtensionAPI,
131
+ /** Execute a review for a single lens: run its tools, then build the prompt. */
132
+ export function reviewWithLensEffect(
133
+ cwd: string,
134
+ lens: LensConfig,
135
+ lensContent: string,
136
+ diff: DiffSource,
137
+ signal?: AbortSignal,
138
+ ): Effect.Effect<LensResult, never, Executor> {
139
+ return Effect.gen(function* () {
140
+ const toolOutputs = yield* runLensToolsEffect(cwd, lens.tools, signal);
141
+
142
+ return {
143
+ lens: lens.name,
144
+ findings: [],
145
+ summary: '',
146
+ toolOutputs,
147
+ _prompt: buildReviewPrompt(lens, lensContent, diff, toolOutputs),
148
+ _lensSection: buildLensSection(lens, lensContent, toolOutputs),
149
+ };
150
+ });
151
+ }
152
+
153
+ /** Promise wrapper building a live Executor from `pi`. */
154
+ export function reviewWithLens(
155
+ pi: Pick<ExtensionAPI, 'exec'>,
131
156
  _ctx: unknown,
132
157
  cwd: string,
133
158
  lens: LensConfig,
@@ -135,19 +160,9 @@ export async function reviewWithLens(
135
160
  diff: DiffSource,
136
161
  signal?: AbortSignal,
137
162
  ): Promise<LensResult> {
138
- // Run lens tools first
139
- const toolOutputs = await runLensTools(pi, cwd, lens.tools, signal);
140
-
141
- // Build the prompt
142
- const prompt = buildReviewPrompt(lens, lensContent, diff, toolOutputs);
143
- const lensSection = buildLensSection(lens, lensContent, toolOutputs);
144
-
145
- return {
146
- lens: lens.name,
147
- findings: [],
148
- summary: '',
149
- toolOutputs,
150
- _prompt: prompt,
151
- _lensSection: lensSection,
152
- };
163
+ return Effect.runPromise(
164
+ reviewWithLensEffect(cwd, lens, lensContent, diff, signal).pipe(
165
+ Effect.provideService(Executor, makeExecutorService(pi)),
166
+ ),
167
+ );
153
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreki-gg/pi-code-reviewer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Multi-lens code review extension for pi — configurable review criteria per project",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -21,9 +21,10 @@
21
21
  "type": "module",
22
22
  "scripts": {
23
23
  "typecheck": "tsc --noEmit",
24
- "lint": "oxlint extensions",
25
- "format": "oxfmt --write extensions",
26
- "format:check": "oxfmt --check extensions"
24
+ "test": "bun test",
25
+ "lint": "oxlint extensions test",
26
+ "format": "oxfmt --write extensions test",
27
+ "format:check": "oxfmt --check extensions test"
27
28
  },
28
29
  "pi": {
29
30
  "extensions": [
@@ -33,8 +34,12 @@
33
34
  "./skills"
34
35
  ]
35
36
  },
37
+ "dependencies": {
38
+ "effect": "^3.21.2"
39
+ },
36
40
  "devDependencies": {
37
41
  "@types/node": "24",
42
+ "bun-types": "latest",
38
43
  "oxfmt": "^0.43.0",
39
44
  "oxlint": "^1.58.0",
40
45
  "typescript": "^6.0.0"