@effect-agent/pr-review 0.1.0-beta.6 → 0.1.0-beta.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"testing.mjs","names":[],"sources":["../src/internal/scripted.ts","../src/internal/fan-out-scripted.ts","../src/internal/fixtures.ts"],"sourcesContent":["import { Effect, Layer, Ref, Schema, Stream } from \"effect\";\nimport { LanguageModel, Model, type Response } from \"effect/unstable/ai\";\n\nimport { CodeReview } from \"./review-agent.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic offline model for the flat reviewer: a prompt-aware scripted\n// model that walks the real tool surface — list, diff, read — then returns\n// the scripted review as its terminal JSON. Decisions key on committed\n// history in the prompt, never on call order, so replays stay honest.\n// ---------------------------------------------------------------------------\n\nexport const OFFLINE_LIST_CALL_ID = \"list-1\";\nexport const OFFLINE_DIFF_CALL_ID = \"diff-1\";\nexport const OFFLINE_READ_CALL_ID = \"read-1\";\n\n/** Usage attached to EVERY scripted model turn; tests pin exact aggregates. */\nexport const SCRIPTED_TURN_USAGE = { inputTokens: 64, outputTokens: 48 } as const;\n\nconst scriptedUsage = {\n inputTokens: { total: SCRIPTED_TURN_USAGE.inputTokens },\n outputTokens: { total: SCRIPTED_TURN_USAGE.outputTokens },\n};\n\nexport const scriptedToolTurn = (\n ...calls: ReadonlyArray<Response.StreamPartEncoded>\n): ReadonlyArray<Response.StreamPartEncoded> => [\n ...calls,\n { type: \"finish\", reason: \"tool-calls\", usage: scriptedUsage },\n];\n\nexport const scriptedFinalParts = (text: string): ReadonlyArray<Response.StreamPartEncoded> => [\n { type: \"text-start\", id: \"code-review\" },\n { type: \"text-delta\", id: \"code-review\", delta: text },\n { type: \"text-end\", id: \"code-review\" },\n { type: \"finish\", reason: \"stop\", usage: scriptedUsage },\n];\n\n/** A prompt-keyed scripted LanguageModel with call and prompt observability. */\nexport const makePromptKeyedModel = (\n name: string,\n decide: (promptJson: string) => ReadonlyArray<Response.StreamPartEncoded>,\n) =>\n Effect.gen(function* () {\n const calls = yield* Ref.make(0);\n const prompts = yield* Ref.make<ReadonlyArray<string>>([]);\n const model = Model.make(\n \"scripted\",\n name,\n Layer.effect(\n LanguageModel.LanguageModel,\n LanguageModel.make({\n generateText: () => Effect.succeed([]),\n streamText: (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Ref.update(calls, (value) => value + 1);\n const promptJson = JSON.stringify(request.prompt);\n yield* Ref.update(prompts, (previous) => [...previous, promptJson]);\n return Stream.fromIterable(decide(promptJson));\n }),\n ),\n }),\n ),\n );\n return { model, calls: Ref.get(calls), prompts: Ref.get(prompts) };\n });\n\n/**\n * Build the offline scripted reviewer model. Turn 1 lists the changeset,\n * Turn 2 reads one file diff, Turn 3 reads head context, Turn 4 returns the\n * scripted review JSON.\n */\nexport const makeOfflineReviewerModel = (script: {\n readonly diffPath: string;\n readonly readPath: string;\n readonly review: CodeReview;\n}) =>\n makePromptKeyedModel(\"pr-review-offline\", (promptJson) => {\n if (promptJson.includes(OFFLINE_READ_CALL_ID)) {\n return scriptedFinalParts(JSON.stringify(Schema.encodeSync(CodeReview)(script.review)));\n }\n if (promptJson.includes(OFFLINE_DIFF_CALL_ID)) {\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_READ_CALL_ID,\n name: \"read_file\",\n params: { path: script.readPath },\n providerExecuted: false,\n });\n }\n if (promptJson.includes(OFFLINE_LIST_CALL_ID)) {\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_DIFF_CALL_ID,\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n });\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_LIST_CALL_ID,\n name: \"list_changed_files\",\n params: { scope: \"all\" },\n providerExecuted: false,\n });\n });\n","import { Effect, Layer, Ref, Schema, Stream } from \"effect\";\nimport { LanguageModel, Model, type Response } from \"effect/unstable/ai\";\n\nimport { FileReviewReport } from \"./fan-out.ts\";\nimport { CodeReview } from \"./review-agent.ts\";\nimport { makePromptKeyedModel, scriptedFinalParts, scriptedToolTurn } from \"./scripted.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic offline models for the fan-out reviewer: prompt-keyed\n// scripted models for BOTH the coordinator and the file-reviewer children.\n// Both key every decision on committed history in the prompt (tool-call ids\n// and briefed unit ids), never on call order, so concurrent children and\n// replays stay honest.\n// ---------------------------------------------------------------------------\n\nexport const OFFLINE_UNITS_CALL_ID = \"units-1\";\n\n/** The delegation Tool Call id the scripted coordinator uses for one unit. */\nexport const offlineUnitCallId = (unitId: string): string => `delegate-${unitId}`;\n\n/** The diff Tool Call id the scripted child uses for one unit. */\nexport const offlineChildDiffCallId = (unitId: string): string => `fanout-diff-${unitId}`;\n\n/** One scripted delegation the offline coordinator declares. */\nexport interface OfflineUnitCall {\n readonly unitId: string;\n readonly paths: ReadonlyArray<string>;\n}\n\n/**\n * Build the offline scripted coordinator model. Turn 1 lists the review\n * units, Turn 2 declares one delegation Tool Call per scripted unit in one\n * batch, Turn 3 returns the scripted merged review JSON. Decisions key on\n * tool-call ids already committed to the prompt.\n */\nexport const makeOfflineFanOutCoordinatorModel = (script: {\n readonly unitCalls: ReadonlyArray<OfflineUnitCall>;\n readonly review: CodeReview;\n}) => {\n const firstUnitCallId = offlineUnitCallId(script.unitCalls[0]?.unitId ?? \"unit-none\");\n return makePromptKeyedModel(\"pr-fanout-coordinator-offline\", (promptJson) => {\n if (promptJson.includes(firstUnitCallId)) {\n return scriptedFinalParts(JSON.stringify(Schema.encodeSync(CodeReview)(script.review)));\n }\n if (promptJson.includes(OFFLINE_UNITS_CALL_ID)) {\n return scriptedToolTurn(\n ...script.unitCalls.map(\n (unit): Response.StreamPartEncoded => ({\n type: \"tool-call\",\n id: offlineUnitCallId(unit.unitId),\n name: \"delegate_file_review\",\n params: { unitId: unit.unitId, paths: unit.paths },\n providerExecuted: false,\n }),\n ),\n );\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_UNITS_CALL_ID,\n name: \"list_review_units\",\n params: { scope: \"all\" },\n providerExecuted: false,\n });\n });\n};\n\n/** How one scripted child behaves for its briefed unit. */\nexport type OfflineUnitOutcome =\n /** Read one diff, then return the scripted report. */\n | { readonly _tag: \"findings\"; readonly report: FileReviewReport }\n /** Read one diff, then return non-JSON — the child fails typed (AgentOutputError). */\n | { readonly _tag: \"malformed-output\" }\n /**\n * Declare more Tool Calls than the child's AgentPolicy allows in one turn —\n * the child fails typed (AgentPolicyError \"tool-calls\") before any executes.\n */\n | { readonly _tag: \"budget-runaway\"; readonly declaredCalls: number };\n\nexport interface OfflineUnitScript {\n readonly unitId: string;\n /** The one file the scripted child reads the diff of. */\n readonly diffPath: string;\n readonly outcome: OfflineUnitOutcome;\n}\n\n/**\n * Build the offline scripted file-reviewer model shared by every delegated\n * child. Each child Run builds the Model Layer inside its own scope; the\n * script entry is selected by the briefed unitId present in the child's OWN\n * prompt, and the turn is selected by whether that unit's diff Tool Call id\n * is already committed there — content-keyed on both axes, so concurrent\n * children never interfere. First-turn child prompts are recorded for\n * context-isolation assertions.\n */\nexport const makeOfflineFileReviewerModel = (scripts: ReadonlyArray<OfflineUnitScript>) =>\n Effect.gen(function* () {\n const calls = yield* Ref.make(0);\n const prompts = yield* Ref.make<ReadonlyArray<string>>([]);\n const decide = (promptJson: string): ReadonlyArray<Response.StreamPartEncoded> | undefined => {\n const script = scripts.find((candidate) => promptJson.includes(candidate.unitId));\n if (script === undefined) return undefined;\n switch (script.outcome._tag) {\n case \"budget-runaway\": {\n return scriptedToolTurn(\n ...Array.from(\n { length: script.outcome.declaredCalls },\n (_, index): Response.StreamPartEncoded => ({\n type: \"tool-call\",\n id: `runaway-${script.unitId}-${index + 1}`,\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n }),\n ),\n );\n }\n case \"malformed-output\":\n case \"findings\": {\n if (promptJson.includes(offlineChildDiffCallId(script.unitId))) {\n return scriptedFinalParts(\n script.outcome._tag === \"findings\"\n ? JSON.stringify(Schema.encodeSync(FileReviewReport)(script.outcome.report))\n : \"this is not the JSON you are looking for\",\n );\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: offlineChildDiffCallId(script.unitId),\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n });\n }\n }\n };\n const model = Model.make(\n \"scripted\",\n \"pr-fanout-file-reviewer-offline\",\n Layer.effect(\n LanguageModel.LanguageModel,\n LanguageModel.make({\n generateText: () => Effect.succeed([]),\n streamText: (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Ref.update(calls, (value) => value + 1);\n const promptJson = JSON.stringify(request.prompt);\n yield* Ref.update(prompts, (previous) => [...previous, promptJson]);\n const parts = decide(promptJson);\n if (parts === undefined) {\n return yield* Effect.die(\n new Error(\"The child prompt names no scripted review unit\"),\n );\n }\n return Stream.fromIterable(parts);\n }),\n ),\n }),\n ),\n );\n return { model, calls: Ref.get(calls), prompts: Ref.get(prompts) };\n });\n","import { Effect, Layer, Option, Ref, Schema } from \"effect\";\n\nimport { ChangedFile } from \"./diff.ts\";\nimport {\n PriorReviewLookupFailure,\n PriorReviews,\n PublishedReview,\n ReviewPublisher,\n} from \"./github.ts\";\nimport type { ReviewPublicationPlan } from \"./render.ts\";\nimport type { ReviewHeadComparison, ReviewState } from \"./review-state.ts\";\nimport {\n MAX_CHANGED_FILES,\n MAX_FILE_CHARS,\n normalizeRepoRelativePath,\n PullRequestMetadata,\n PullRequestSource,\n ReviewInputViolation,\n} from \"./source.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic in-memory adapters for both ports: a fixture pull request\n// serving the PullRequestSource, and a collecting ReviewPublisher recording\n// every plan. Tests, dry runs, and live smokes run against these with no\n// network and no credentials.\n// ---------------------------------------------------------------------------\n\n/** One fixture file: its changeset entry plus optional head content. */\nexport class FixtureFile extends Schema.Class<FixtureFile>(\"@effect-agent/pr-review/FixtureFile\")({\n file: ChangedFile,\n headContent: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(MAX_FILE_CHARS))),\n}) {}\n\n/** A complete in-memory pull request for tests, dry runs, and live smokes. */\nexport class FixturePullRequest extends Schema.Class<FixturePullRequest>(\n \"@effect-agent/pr-review/FixturePullRequest\",\n)({\n metadata: PullRequestMetadata,\n files: Schema.Array(FixtureFile).check(Schema.isMaxLength(MAX_CHANGED_FILES)),\n}) {}\n\nconst requireChanged = (\n fixture: FixturePullRequest,\n path: string,\n): Effect.Effect<FixtureFile, ReviewInputViolation> => {\n const entry = fixture.files.find((candidate) => candidate.file.path === path);\n return entry === undefined\n ? Effect.fail(\n ReviewInputViolation.make({\n input: path,\n reason: \"Path is not part of this pull request's changeset.\",\n }),\n )\n : Effect.succeed(entry);\n};\n\n/** Deterministic `PullRequestSource` over one fixture pull request. */\nexport const fixturePullRequestSourceLayer = (\n fixture: FixturePullRequest,\n): Layer.Layer<PullRequestSource> =>\n Layer.succeed(PullRequestSource)(\n PullRequestSource.of({\n metadata: Effect.succeed(fixture.metadata),\n changedFiles: Effect.succeed(fixture.files.map((entry) => entry.file)),\n anchorFiles: Effect.succeed(fixture.files.map((entry) => entry.file)),\n readFile: (path) =>\n Effect.gen(function* () {\n const relative = yield* normalizeRepoRelativePath(path);\n const entry = yield* requireChanged(fixture, relative);\n if (entry.headContent === undefined) {\n return yield* ReviewInputViolation.make({\n input: relative,\n reason: \"No head content is available for this file.\",\n });\n }\n return entry.headContent;\n }),\n }),\n );\n\n/** In-memory publisher: records every plan and mints a deterministic receipt. */\nexport const collectingReviewPublisherLayer = (\n published: Ref.Ref<ReadonlyArray<ReviewPublicationPlan>>,\n): Layer.Layer<ReviewPublisher> =>\n Layer.succeed(ReviewPublisher)(\n ReviewPublisher.of({\n publish: (plan) =>\n Ref.update(published, (plans) => [...plans, plan]).pipe(\n Effect.flatMap(() => Ref.get(published)),\n Effect.map((plans) =>\n PublishedReview.make({\n reviewId: plans.length,\n url: `memory://review/${plans.length}`,\n event: plan.event,\n inlineComments: plan.comments.length,\n }),\n ),\n ),\n }),\n );\n\n/** Static `PriorReviews` service for tests: fixed history and comparisons. */\nexport const staticPriorReviews = (\n fingerprint: Option.Option<string>,\n options: {\n readonly state?: Option.Option<ReviewState> | undefined;\n readonly comparison?: ReviewHeadComparison | undefined;\n } = {},\n): PriorReviews[\"Service\"] =>\n PriorReviews.of({\n latestFingerprint: Effect.succeed(fingerprint),\n latestState: Effect.succeed(options.state ?? Option.none()),\n compareHeads: () =>\n options.comparison === undefined\n ? Effect.fail(PriorReviewLookupFailure.make({ reason: \"no fixture comparison\" }))\n : Effect.succeed(options.comparison),\n });\n\n/** Layer form for consumers whose Effect explicitly requires `PriorReviews`. */\nexport const staticPriorReviewsLayer = (\n fingerprint: Option.Option<string>,\n options: {\n readonly state?: Option.Option<ReviewState> | undefined;\n readonly comparison?: ReviewHeadComparison | undefined;\n } = {},\n): Layer.Layer<PriorReviews> =>\n Layer.succeed(PriorReviews)(staticPriorReviews(fingerprint, options));\n"],"mappings":";;;;AAYA,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;;AAGpC,MAAa,sBAAsB;CAAE,aAAa;CAAI,cAAc;AAAG;AAEvE,MAAM,gBAAgB;CACpB,aAAa,EAAE,OAAO,oBAAoB,YAAY;CACtD,cAAc,EAAE,OAAO,oBAAoB,aAAa;AAC1D;AAEA,MAAa,oBACX,GAAG,UAC2C,CAC9C,GAAG,OACH;CAAE,MAAM;CAAU,QAAQ;CAAc,OAAO;AAAc,CAC/D;AAEA,MAAa,sBAAsB,SAA4D;CAC7F;EAAE,MAAM;EAAc,IAAI;CAAc;CACxC;EAAE,MAAM;EAAc,IAAI;EAAe,OAAO;CAAK;CACrD;EAAE,MAAM;EAAY,IAAI;CAAc;CACtC;EAAE,MAAM;EAAU,QAAQ;EAAQ,OAAO;CAAc;AACzD;;AAGA,MAAa,wBACX,MACA,WAEA,OAAO,IAAI,aAAa;CACtB,MAAM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,QAAQ,QAAQ,SAAS,OAAO,KAAK,CAAC;CAC1D,oBACE,QAAQ,eAAe,KAAA,IACnB,OAAO,KAAK,yBAAyB,KAAK,EAAE,QAAQ,wBAAwB,CAAC,CAAC,IAC9E,OAAO,QAAQ,QAAQ,UAAU;AACzC,CAAC;;AAGH,MAAa,2BACX,aACA,UAGI,CAAC,MAEL,MAAM,QAAQ,YAAY,CAAC,CAAC,mBAAmB,aAAa,OAAO,CAAC"}
1
+ {"version":3,"file":"testing.mjs","names":[],"sources":["../src/internal/scripted.ts","../src/internal/fan-out-scripted.ts","../src/internal/fixtures.ts"],"sourcesContent":["import { Effect, Layer, Ref, Schema, Stream } from \"effect\";\nimport { LanguageModel, Model, type Response } from \"effect/unstable/ai\";\n\nimport { CodeReview } from \"./review-agent.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic offline model for the flat reviewer: a prompt-aware scripted\n// model that walks the real tool surface — list, diff, read — then returns\n// the scripted review as its terminal JSON. Decisions key on committed\n// history in the prompt, never on call order, so replays stay honest.\n// ---------------------------------------------------------------------------\n\nexport const OFFLINE_LIST_CALL_ID = \"list-1\";\nexport const OFFLINE_DIFF_CALL_ID = \"diff-1\";\nexport const OFFLINE_READ_CALL_ID = \"read-1\";\n\n/** Usage attached to EVERY scripted model turn; tests pin exact aggregates. */\nexport const SCRIPTED_TURN_USAGE = { inputTokens: 64, outputTokens: 48 } as const;\n\nconst scriptedUsage = {\n inputTokens: { total: SCRIPTED_TURN_USAGE.inputTokens },\n outputTokens: { total: SCRIPTED_TURN_USAGE.outputTokens },\n};\n\nexport const scriptedToolTurn = (\n ...calls: ReadonlyArray<Response.StreamPartEncoded>\n): ReadonlyArray<Response.StreamPartEncoded> => [\n ...calls,\n { type: \"finish\", reason: \"tool-calls\", usage: scriptedUsage },\n];\n\nexport const scriptedFinalParts = (text: string): ReadonlyArray<Response.StreamPartEncoded> => [\n { type: \"text-start\", id: \"code-review\" },\n { type: \"text-delta\", id: \"code-review\", delta: text },\n { type: \"text-end\", id: \"code-review\" },\n { type: \"finish\", reason: \"stop\", usage: scriptedUsage },\n];\n\n/** A prompt-keyed scripted LanguageModel with call and prompt observability. */\nexport const makePromptKeyedModel = (\n name: string,\n decide: (promptJson: string) => ReadonlyArray<Response.StreamPartEncoded>,\n) =>\n Effect.gen(function* () {\n const calls = yield* Ref.make(0);\n const prompts = yield* Ref.make<ReadonlyArray<string>>([]);\n const model = Model.make(\n \"scripted\",\n name,\n Layer.effect(\n LanguageModel.LanguageModel,\n LanguageModel.make({\n generateText: () => Effect.succeed([]),\n streamText: (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Ref.update(calls, (value) => value + 1);\n const promptJson = JSON.stringify(request.prompt);\n yield* Ref.update(prompts, (previous) => [...previous, promptJson]);\n return Stream.fromIterable(decide(promptJson));\n }),\n ),\n }),\n ),\n );\n return { model, calls: Ref.get(calls), prompts: Ref.get(prompts) };\n });\n\n/**\n * Build the offline scripted reviewer model. Turn 1 lists the changeset,\n * Turn 2 reads one file diff, Turn 3 reads head context, Turn 4 returns the\n * scripted review JSON.\n */\nexport const makeOfflineReviewerModel = (script: {\n readonly diffPath: string;\n readonly readPath: string;\n readonly review: CodeReview;\n}) =>\n makePromptKeyedModel(\"pr-review-offline\", (promptJson) => {\n if (promptJson.includes(OFFLINE_READ_CALL_ID)) {\n return scriptedFinalParts(JSON.stringify(Schema.encodeSync(CodeReview)(script.review)));\n }\n if (promptJson.includes(OFFLINE_DIFF_CALL_ID)) {\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_READ_CALL_ID,\n name: \"read_file\",\n params: { path: script.readPath },\n providerExecuted: false,\n });\n }\n if (promptJson.includes(OFFLINE_LIST_CALL_ID)) {\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_DIFF_CALL_ID,\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n });\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_LIST_CALL_ID,\n name: \"list_changed_files\",\n params: { scope: \"all\" },\n providerExecuted: false,\n });\n });\n","import { Effect, Layer, Ref, Schema, Stream } from \"effect\";\nimport { LanguageModel, Model, type Response } from \"effect/unstable/ai\";\n\nimport { FileReviewReport } from \"./fan-out.ts\";\nimport { CodeReview } from \"./review-agent.ts\";\nimport { makePromptKeyedModel, scriptedFinalParts, scriptedToolTurn } from \"./scripted.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic offline models for the fan-out reviewer: prompt-keyed\n// scripted models for BOTH the coordinator and the file-reviewer children.\n// Both key every decision on committed history in the prompt (tool-call ids\n// and briefed unit ids), never on call order, so concurrent children and\n// replays stay honest.\n// ---------------------------------------------------------------------------\n\nexport const OFFLINE_UNITS_CALL_ID = \"units-1\";\n\n/** The delegation Tool Call id the scripted coordinator uses for one unit. */\nexport const offlineUnitCallId = (unitId: string): string => `delegate-${unitId}`;\n\n/** The diff Tool Call id the scripted child uses for one unit. */\nexport const offlineChildDiffCallId = (unitId: string): string => `fanout-diff-${unitId}`;\n\n/** One scripted delegation the offline coordinator declares. */\nexport interface OfflineUnitCall {\n readonly unitId: string;\n readonly paths: ReadonlyArray<string>;\n}\n\n/**\n * Build the offline scripted coordinator model. Turn 1 lists the review\n * units, Turn 2 declares one delegation Tool Call per scripted unit in one\n * batch, Turn 3 returns the scripted merged review JSON. Decisions key on\n * tool-call ids already committed to the prompt.\n */\nexport const makeOfflineFanOutCoordinatorModel = (script: {\n readonly unitCalls: ReadonlyArray<OfflineUnitCall>;\n readonly review: CodeReview;\n}) => {\n const firstUnitCallId = offlineUnitCallId(script.unitCalls[0]?.unitId ?? \"unit-none\");\n return makePromptKeyedModel(\"pr-fanout-coordinator-offline\", (promptJson) => {\n if (promptJson.includes(firstUnitCallId)) {\n return scriptedFinalParts(JSON.stringify(Schema.encodeSync(CodeReview)(script.review)));\n }\n if (promptJson.includes(OFFLINE_UNITS_CALL_ID)) {\n return scriptedToolTurn(\n ...script.unitCalls.map(\n (unit): Response.StreamPartEncoded => ({\n type: \"tool-call\",\n id: offlineUnitCallId(unit.unitId),\n name: \"delegate_file_review\",\n params: { unitId: unit.unitId, paths: unit.paths },\n providerExecuted: false,\n }),\n ),\n );\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: OFFLINE_UNITS_CALL_ID,\n name: \"list_review_units\",\n params: { scope: \"all\" },\n providerExecuted: false,\n });\n });\n};\n\n/** How one scripted child behaves for its briefed unit. */\nexport type OfflineUnitOutcome =\n /** Read one diff, then return the scripted report. */\n | { readonly _tag: \"findings\"; readonly report: FileReviewReport }\n /** Read one diff, then return non-JSON — the child fails typed (AgentOutputError). */\n | { readonly _tag: \"malformed-output\" }\n /**\n * Declare more Tool Calls than the child's AgentPolicy allows in one turn —\n * none executes and the child fails typed (AgentPolicyError \"tool-calls\",\n * the reviewer's deliberate `onExhaustion: \"fail\"` pin).\n */\n | { readonly _tag: \"budget-runaway\"; readonly declaredCalls: number };\n\nexport interface OfflineUnitScript {\n readonly unitId: string;\n /** The one file the scripted child reads the diff of. */\n readonly diffPath: string;\n readonly outcome: OfflineUnitOutcome;\n}\n\n/**\n * Build the offline scripted file-reviewer model shared by every delegated\n * child. Each child Run builds the Model Layer inside its own scope; the\n * script entry is selected by the briefed unitId present in the child's OWN\n * prompt, and the turn is selected by whether that unit's diff Tool Call id\n * is already committed there — content-keyed on both axes, so concurrent\n * children never interfere. First-turn child prompts are recorded for\n * context-isolation assertions.\n */\nexport const makeOfflineFileReviewerModel = (scripts: ReadonlyArray<OfflineUnitScript>) =>\n Effect.gen(function* () {\n const calls = yield* Ref.make(0);\n const prompts = yield* Ref.make<ReadonlyArray<string>>([]);\n const decide = (promptJson: string): ReadonlyArray<Response.StreamPartEncoded> | undefined => {\n const script = scripts.find((candidate) => promptJson.includes(candidate.unitId));\n if (script === undefined) return undefined;\n switch (script.outcome._tag) {\n case \"budget-runaway\": {\n return scriptedToolTurn(\n ...Array.from(\n { length: script.outcome.declaredCalls },\n (_, index): Response.StreamPartEncoded => ({\n type: \"tool-call\",\n id: `runaway-${script.unitId}-${index + 1}`,\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n }),\n ),\n );\n }\n case \"malformed-output\":\n case \"findings\": {\n if (promptJson.includes(offlineChildDiffCallId(script.unitId))) {\n return scriptedFinalParts(\n script.outcome._tag === \"findings\"\n ? JSON.stringify(Schema.encodeSync(FileReviewReport)(script.outcome.report))\n : \"this is not the JSON you are looking for\",\n );\n }\n return scriptedToolTurn({\n type: \"tool-call\",\n id: offlineChildDiffCallId(script.unitId),\n name: \"read_file_diff\",\n params: { path: script.diffPath },\n providerExecuted: false,\n });\n }\n }\n };\n const model = Model.make(\n \"scripted\",\n \"pr-fanout-file-reviewer-offline\",\n Layer.effect(\n LanguageModel.LanguageModel,\n LanguageModel.make({\n generateText: () => Effect.succeed([]),\n streamText: (request) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Ref.update(calls, (value) => value + 1);\n const promptJson = JSON.stringify(request.prompt);\n yield* Ref.update(prompts, (previous) => [...previous, promptJson]);\n const parts = decide(promptJson);\n if (parts === undefined) {\n return yield* Effect.die(\n new Error(\"The child prompt names no scripted review unit\"),\n );\n }\n return Stream.fromIterable(parts);\n }),\n ),\n }),\n ),\n );\n return { model, calls: Ref.get(calls), prompts: Ref.get(prompts) };\n });\n","import { DateTime, Effect, Layer, Option, Ref, Schema } from \"effect\";\n\nimport { ChangedFile } from \"./diff.ts\";\nimport {\n PriorReviewLookupFailure,\n PriorReviews,\n PublishedReview,\n ReviewPublisher,\n} from \"./github.ts\";\nimport type { ReviewPublicationPlan } from \"./render.ts\";\nimport type { ReviewHeadComparison, ReviewState } from \"./review-state.ts\";\nimport {\n MAX_CHANGED_FILES,\n MAX_FILE_CHARS,\n normalizeRepoRelativePath,\n PullRequestMetadata,\n PullRequestSource,\n ReviewInputViolation,\n} from \"./source.ts\";\n\n// ---------------------------------------------------------------------------\n// Deterministic in-memory adapters for both ports: a fixture pull request\n// serving the PullRequestSource, and a collecting ReviewPublisher recording\n// every plan. Tests, dry runs, and live smokes run against these with no\n// network and no credentials.\n// ---------------------------------------------------------------------------\n\n/** One fixture file: its changeset entry plus optional head content. */\nexport class FixtureFile extends Schema.Class<FixtureFile>(\"@effect-agent/pr-review/FixtureFile\")({\n file: ChangedFile,\n headContent: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(MAX_FILE_CHARS))),\n}) {}\n\n/** A complete in-memory pull request for tests, dry runs, and live smokes. */\nexport class FixturePullRequest extends Schema.Class<FixturePullRequest>(\n \"@effect-agent/pr-review/FixturePullRequest\",\n)({\n metadata: PullRequestMetadata,\n files: Schema.Array(FixtureFile).check(Schema.isMaxLength(MAX_CHANGED_FILES)),\n}) {}\n\nconst requireChanged = (\n fixture: FixturePullRequest,\n path: string,\n): Effect.Effect<FixtureFile, ReviewInputViolation> => {\n const entry = fixture.files.find((candidate) => candidate.file.path === path);\n return entry === undefined\n ? Effect.fail(\n ReviewInputViolation.make({\n input: path,\n reason: \"Path is not part of this pull request's changeset.\",\n }),\n )\n : Effect.succeed(entry);\n};\n\n/** Deterministic `PullRequestSource` over one fixture pull request. */\nexport const fixturePullRequestSourceLayer = (\n fixture: FixturePullRequest,\n): Layer.Layer<PullRequestSource> =>\n Layer.succeed(PullRequestSource)(\n PullRequestSource.of({\n metadata: Effect.succeed(fixture.metadata),\n changedFiles: Effect.succeed(fixture.files.map((entry) => entry.file)),\n anchorFiles: Effect.succeed(fixture.files.map((entry) => entry.file)),\n readFile: (path) =>\n Effect.gen(function* () {\n const relative = yield* normalizeRepoRelativePath(path);\n const entry = yield* requireChanged(fixture, relative);\n if (entry.headContent === undefined) {\n return yield* ReviewInputViolation.make({\n input: relative,\n reason: \"No head content is available for this file.\",\n });\n }\n return entry.headContent;\n }),\n }),\n );\n\n/** In-memory publisher: records every plan and mints a deterministic receipt. */\nexport const collectingReviewPublisherLayer = (\n published: Ref.Ref<ReadonlyArray<ReviewPublicationPlan>>,\n): Layer.Layer<ReviewPublisher> =>\n Layer.succeed(ReviewPublisher)(\n ReviewPublisher.of({\n publish: (plan) =>\n Ref.update(published, (plans) => [...plans, plan]).pipe(\n Effect.flatMap(() => Ref.get(published)),\n Effect.map((plans) =>\n PublishedReview.make({\n reviewId: plans.length,\n url: `memory://review/${plans.length}`,\n event: plan.event,\n inlineComments: plan.comments.length,\n authorNodeId: \"BOT_memory-reviewer\",\n submittedAt: DateTime.makeUnsafe(\n `2026-01-01T00:00:${String(plans.length).padStart(2, \"0\")}Z`,\n ),\n }),\n ),\n ),\n }),\n );\n\n/** Static `PriorReviews` service for tests: fixed history and comparisons. */\nexport const staticPriorReviews = (\n fingerprint: Option.Option<string>,\n options: {\n readonly state?: Option.Option<ReviewState> | undefined;\n readonly comparison?: ReviewHeadComparison | undefined;\n } = {},\n): PriorReviews[\"Service\"] =>\n PriorReviews.of({\n latestFingerprint: Effect.succeed(fingerprint),\n latestState: Effect.succeed(options.state ?? Option.none()),\n compareHeads: () =>\n options.comparison === undefined\n ? Effect.fail(PriorReviewLookupFailure.make({ reason: \"no fixture comparison\" }))\n : Effect.succeed(options.comparison),\n });\n\n/** Layer form for consumers whose Effect explicitly requires `PriorReviews`. */\nexport const staticPriorReviewsLayer = (\n fingerprint: Option.Option<string>,\n options: {\n readonly state?: Option.Option<ReviewState> | undefined;\n readonly comparison?: ReviewHeadComparison | undefined;\n } = {},\n): Layer.Layer<PriorReviews> =>\n Layer.succeed(PriorReviews)(staticPriorReviews(fingerprint, options));\n"],"mappings":";;;;AAYA,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;;AAGpC,MAAa,sBAAsB;CAAE,aAAa;CAAI,cAAc;AAAG;AAEvE,MAAM,gBAAgB;CACpB,aAAa,EAAE,OAAO,oBAAoB,YAAY;CACtD,cAAc,EAAE,OAAO,oBAAoB,aAAa;AAC1D;AAEA,MAAa,oBACX,GAAG,UAC2C,CAC9C,GAAG,OACH;CAAE,MAAM;CAAU,QAA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AAI,IAAI,SAAS,CAAC,GACvC,OAAO,KAAK,UACV,gBAAgB,KAAK;CACnB,UAAU,MAAM;CAChB,KAAK,mBAAmB,MAAM;CAC9B,OAAO,KAAK;CACZ,gBAAgB,KAAK,SAAS;CAC9B,cAAc;CACd,aAAa,SAAS,WACpB,oBAAoB,OAAO,MAAM,MAAM,CAAC,CAAC,SAAS,GAAG,GAAG,EAAE,EAC5D;AACF,CAAC,CACH,CACF,EACJ,CAAC,CACH;;AAGF,MAAa,sBACX,aACA,UAGI,CAAC,MAEL,aAAa,GAAG;CACd,mBAAmB,OAAO,QAAQ,WAAW;CAC7C,aAAa,OAAO,QAAQ,QAAQ,SAAS,OAAO,KAAK,CAAC;CAC1D,oBACE,QAAQ,eAAe,KAAA,IACnB,OAAO,KAAK,yBAAyB,KAAK,EAAE,QAAQ,wBAAwB,CAAC,CAAC,IAC9E,OAAO,QAAQ,QAAQ,UAAU;AACzC,CAAC;;AAGH,MAAa,2BACX,aACA,UAGI,CAAC,MAEL,MAAM,QAAQ,YAAY,CAAC,CAAC,mBAAmB,aAAa,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,6 @@
1
1
  {
2
2
  "name": "@effect-agent/pr-review",
3
- "version": "0.1.0-beta.6",
4
- "description": "Bounded, fail-closed GitHub pull-request reviewer built on the effect-agent public surface: schema-first review contracts, read-only tools, GitHub adapters, a configuration factory, and CLI + GitHub Actions entrypoints.",
5
- "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/danieljvdm/effect-agent.git",
9
- "directory": "packages/pr-review"
10
- },
11
- "files": [
12
- "dist",
13
- "src"
14
- ],
15
- "type": "module",
3
+ "version": "0.1.0-beta.9",
16
4
  "exports": {
17
5
  ".": {
18
6
  "types": "./dist/index.d.mts",
@@ -31,6 +19,25 @@
31
19
  "default": "./dist/cli.mjs"
32
20
  }
33
21
  },
22
+ "dependencies": {
23
+ "@effect/ai-anthropic": "4.0.0-beta.107",
24
+ "@effect/ai-openai": "4.0.0-beta.107",
25
+ "@effect/platform-node": "4.0.0-beta.107",
26
+ "effect": "4.0.0-beta.107",
27
+ "effect-agent": "0.1.0-beta.9"
28
+ },
29
+ "description": "Bounded, fail-closed GitHub pull-request reviewer built on the effect-agent public surface: schema-first review contracts, read-only tools, GitHub adapters, a configuration factory, and CLI + GitHub Actions entrypoints.",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/danieljvdm/effect-agent.git",
34
+ "directory": "packages/pr-review"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src"
39
+ ],
40
+ "type": "module",
34
41
  "publishConfig": {
35
42
  "access": "public"
36
43
  },
@@ -39,13 +46,6 @@
39
46
  "check": "tsc --noEmit -p tsconfig.json",
40
47
  "test": "vp test --passWithNoTests"
41
48
  },
42
- "dependencies": {
43
- "@effect/ai-anthropic": "4.0.0-beta.107",
44
- "@effect/ai-openai": "4.0.0-beta.107",
45
- "@effect/platform-node": "4.0.0-beta.107",
46
- "effect": "4.0.0-beta.107",
47
- "effect-agent": "0.1.0-beta.6"
48
- },
49
49
  "devDependencies": {
50
50
  "@effect/vitest": "4.0.0-beta.107",
51
51
  "typescript": "7.0.2",
package/src/action.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { NodeRuntime, NodeServices } from "@effect/platform-node";
2
2
  import { Config, Console, Effect, FileSystem, Layer, Option, Redacted, Schema } from "effect";
3
3
  import { BudgetExceeded, UsageBudgetLimits } from "effect-agent";
4
+ import { FetchHttpClient } from "effect/unstable/http";
4
5
 
5
6
  import { InvalidEffortInput, parseEffortPosition, type EffortPosition } from "./internal/effort.ts";
6
7
  import { PrReview, type RunReviewOptions } from "./internal/factory.ts";
@@ -15,6 +16,7 @@ import {
15
16
  openAiClientLayer,
16
17
  type ReviewProvider,
17
18
  } from "./internal/providers.ts";
19
+ import { retireStaleReviews } from "./internal/retirement.ts";
18
20
  import {
19
21
  ReviewExecutionContext,
20
22
  ReviewHeadComparison,
@@ -89,6 +91,7 @@ export interface ResolvedActionInputs {
89
91
  /** Deprecated compatibility input; conclusions are always conservative. */
90
92
  readonly failOn: FailOnPolicy;
91
93
  readonly skipUnchanged: boolean;
94
+ readonly retireStaleReviews: boolean;
92
95
  }
93
96
 
94
97
  /** Read the PR_REVIEW_* input surface (all optional, all defaulted). */
@@ -129,6 +132,9 @@ export const resolveActionInputs = Effect.fn("resolveActionInputs")(function* ()
129
132
  const skipUnchanged = yield* Config.boolean("PR_REVIEW_SKIP_UNCHANGED").pipe(
130
133
  Config.withDefault(true),
131
134
  );
135
+ const retireStaleReviews = yield* Config.boolean("PR_REVIEW_RETIRE_STALE_REVIEWS").pipe(
136
+ Config.withDefault(true),
137
+ );
132
138
  return {
133
139
  provider,
134
140
  model: Option.getOrUndefined(model),
@@ -147,6 +153,7 @@ export const resolveActionInputs = Effect.fn("resolveActionInputs")(function* ()
147
153
  reviewMode,
148
154
  failOn,
149
155
  skipUnchanged,
156
+ retireStaleReviews,
150
157
  } satisfies ResolvedActionInputs;
151
158
  });
152
159
 
@@ -399,6 +406,8 @@ export const runReviewAction = <E, R, FingerprintE = never, FingerprintR = never
399
406
  readonly modelLabel?: string | undefined;
400
407
  /** Explicit test/custom-host history override; GitHub owns the default adapter. */
401
408
  readonly priorReviews?: PriorReviews["Service"] | undefined;
409
+ /** Retire marker-bearing prior reviews after a successful post (default true). */
410
+ readonly retireStaleReviews?: boolean | undefined;
402
411
  } = {},
403
412
  ) =>
404
413
  Effect.gen(function* () {
@@ -565,6 +574,27 @@ export const runReviewAction = <E, R, FingerprintE = never, FingerprintR = never
565
574
  );
566
575
  if (outcome.published !== undefined) {
567
576
  yield* Console.log(`Posted ${outcome.published.event} review: ${outcome.published.url}`);
577
+ if (options.retireStaleReviews !== false && outcome.state !== undefined) {
578
+ if (outcome.published.authorNodeId === null || outcome.published.submittedAt === null) {
579
+ yield* Console.warn(
580
+ "Skipping stale-review retirement because GitHub did not return the posted review's actor and submission time.",
581
+ );
582
+ } else {
583
+ const report = yield* retireStaleReviews({
584
+ currentReviewId: outcome.published.reviewId,
585
+ currentReviewUrl: outcome.published.url,
586
+ currentAuthorNodeId: outcome.published.authorNodeId,
587
+ currentSubmittedAt: outcome.published.submittedAt,
588
+ currentState: outcome.state,
589
+ });
590
+ yield* Console.log(
591
+ `Review retirement: ${report.reviewsRetired} prior review(s), ` +
592
+ `${report.findingsResolved} resolved finding(s), ` +
593
+ `${report.commentsMinimized} minimized inline comment(s), ` +
594
+ `${report.failures} failure(s).`,
595
+ );
596
+ }
597
+ }
568
598
  }
569
599
  const check = concludeReviewOutcome(outcome);
570
600
  yield* writeActionOutputs(outcomeOutputs(outcome, check.conclusion));
@@ -620,6 +650,7 @@ export const reviewActionProgram = Effect.gen(function* () {
620
650
  failOn: inputs.failOn,
621
651
  skipUnchanged: inputs.skipUnchanged,
622
652
  reviewMode: inputs.reviewMode,
653
+ retireStaleReviews: inputs.retireStaleReviews,
623
654
  modelLabel,
624
655
  };
625
656
  if (inputs.provider === "anthropic") {
@@ -652,7 +683,7 @@ export const main = (): void =>
652
683
  ),
653
684
  ),
654
685
  Effect.scoped,
655
- Effect.provide(NodeServices.layer),
686
+ Effect.provide(Layer.merge(NodeServices.layer, FetchHttpClient.layer)),
656
687
  ),
657
688
  { disableErrorReporting: true },
658
689
  );
package/src/cli.ts CHANGED
@@ -2,6 +2,7 @@ import { NodeRuntime, NodeServices } from "@effect/platform-node";
2
2
  import { Console, Effect, Layer, Option, Schema } from "effect";
3
3
  import { BudgetExceeded } from "effect-agent";
4
4
  import { Command as CliCommand, Flag } from "effect/unstable/cli";
5
+ import { FetchHttpClient } from "effect/unstable/http";
5
6
 
6
7
  import { InvalidEffortInput, parseEffortPosition, type EffortPosition } from "./internal/effort.ts";
7
8
  import { PrReview, type RunReviewOptions } from "./internal/factory.ts";
@@ -207,7 +208,7 @@ const program = CliCommand.run(command, { version: "0.0.0" }).pipe(
207
208
  ),
208
209
  ),
209
210
  Effect.scoped,
210
- Effect.provide(NodeServices.layer),
211
+ Effect.provide(Layer.merge(NodeServices.layer, FetchHttpClient.layer)),
211
212
  );
212
213
 
213
214
  NodeRuntime.runMain(program, { disableErrorReporting: true });
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./internal/ignore.ts";
13
13
  export * from "./internal/profiles.ts";
14
14
  export * from "./internal/providers.ts";
15
15
  export * from "./internal/render.ts";
16
+ export * from "./internal/retirement.ts";
16
17
  export * from "./internal/review-agent.ts";
17
18
  export * from "./internal/review-state.ts";
18
19
  export * from "./internal/review-units.ts";
@@ -25,6 +25,7 @@ const INPUT_TO_ENV: ReadonlyArray<readonly [input: string, env: string]> = [
25
25
  ["INPUT_REVIEW-MODE", "PR_REVIEW_MODE"],
26
26
  ["INPUT_FAIL-ON", "PR_REVIEW_FAIL_ON"],
27
27
  ["INPUT_SKIP-UNCHANGED", "PR_REVIEW_SKIP_UNCHANGED"],
28
+ ["INPUT_RETIRE-STALE-REVIEWS", "PR_REVIEW_RETIRE_STALE_REVIEWS"],
28
29
  ["INPUT_STATE-SECRET", "PR_REVIEW_STATE_SECRET"],
29
30
  ["INPUT_OPENAI-API-KEY", "OPENAI_API_KEY"],
30
31
  ["INPUT_ANTHROPIC-API-KEY", "ANTHROPIC_API_KEY"],
@@ -73,7 +73,8 @@ export type OfflineUnitOutcome =
73
73
  | { readonly _tag: "malformed-output" }
74
74
  /**
75
75
  * Declare more Tool Calls than the child's AgentPolicy allows in one turn —
76
- * the child fails typed (AgentPolicyError "tool-calls") before any executes.
76
+ * none executes and the child fails typed (AgentPolicyError "tool-calls",
77
+ * the reviewer's deliberate `onExhaustion: "fail"` pin).
77
78
  */
78
79
  | { readonly _tag: "budget-runaway"; readonly declaredCalls: number };
79
80
 
@@ -2,19 +2,9 @@ import { Effect, Schema } from "effect";
2
2
  import {
3
3
  Agent,
4
4
  AgentPolicy,
5
- AgentSpawner,
6
- IdGenerator,
7
- RunEventSink,
8
5
  Subagent,
9
- SubagentBudgetExhausted,
10
- SubagentDurability,
11
- SubagentDurabilityError,
12
- SubagentExecutionFailure,
13
6
  SubagentPolicy,
14
- SubagentPrestartDenied,
15
- SubagentProjectionFailure,
16
7
  SubagentRuntime,
17
- ToolCallWaiting,
18
8
  ToolExecutionClass,
19
9
  type RuntimeBinding,
20
10
  } from "effect-agent";
@@ -148,9 +138,16 @@ export const defaultFileReviewerPolicy = AgentPolicy.make({
148
138
  maxDuration: "4 minutes",
149
139
  toolConcurrency: 2,
150
140
  tokenBudget: 200_000,
151
- // S1 soft landing is not yet adopted here: the fan-out contract pins the
152
- // typed "unit unreviewed" failure flow until the containment slice reworks
153
- // it (planned S2/S3 of the budget arc).
141
+ // Bound one live prompt independently from cumulative usage. The engine
142
+ // prunes old diff/file results before paying for a summary.
143
+ contextTokenLimit: 150_000,
144
+ // Typed exhaustion, deliberately NOT the final-answer soft landing: a
145
+ // review is a coverage claim, and a child whose reads were rejected could
146
+ // still emit schema-valid findings — laundering budget exhaustion into
147
+ // "reviewed". Until host-owned evidence proves every mandatory
148
+ // read_file_diff completed, an exhausted child fails typed and its unit
149
+ // stays honestly unreviewed (containment turns that into result data
150
+ // without failing the run).
154
151
  onExhaustion: "fail",
155
152
  });
156
153
 
@@ -223,45 +220,6 @@ export const mapFileReviewChildFailure = (failure: {
223
220
  message: (failure.message ?? "").slice(0, 400),
224
221
  });
225
222
 
226
- // ---------------------------------------------------------------------------
227
- // The parent-facing view of the delegation Tool.
228
- //
229
- // `Subagent.define` fixes `failureMode: "error"`, so a failed child would
230
- // fail the WHOLE parent Run typed — one unreviewable unit would abort the
231
- // entire fan-out review. This coordinator wants partial results with honest
232
- // reporting instead, so its Toolkit carries a same-name Tool value with the
233
- // identical parameter/success/failure Schemas but `failureMode: "return"`:
234
- // Effect AI resolves handlers by Tool NAME, so the real S1 delegation handler
235
- // from `SubagentRuntime.layer` still executes, and a typed unit failure
236
- // reaches the model as a failed tool result (bounded, encoded through the
237
- // declared failure union) instead of aborting the Run.
238
- // ---------------------------------------------------------------------------
239
-
240
- /** Exactly the failure union `Subagent.define` declares for this delegation. */
241
- export const FileReviewDelegationFailure = Schema.Union([
242
- FileReviewUnitFailed,
243
- SubagentPrestartDenied,
244
- SubagentBudgetExhausted,
245
- SubagentProjectionFailure,
246
- SubagentExecutionFailure,
247
- ToolCallWaiting,
248
- SubagentDurabilityError,
249
- ]);
250
-
251
- export const DelegateFileReview = Tool.make("delegate_file_review", {
252
- description: delegationDescription,
253
- parameters: FileReviewRequest,
254
- success: FileReviewUnitResult,
255
- failure: FileReviewDelegationFailure,
256
- failureMode: "return",
257
- })
258
- .addDependency(AgentSpawner)
259
- .addDependency(RunEventSink)
260
- .addDependency(SubagentDurability)
261
- .addDependency(IdGenerator)
262
- // The delegated child's whole tool surface is read-only.
263
- .annotate(ToolExecutionClass, "readonly");
264
-
265
223
  // ---------------------------------------------------------------------------
266
224
  // The coordinator's own tool: the deterministic unit plan over the changeset.
267
225
  // Grouping is host code (review-units.ts), not model prose, so fan-out shape
@@ -303,8 +261,6 @@ export const FanOutCoordinatorToolkitLayer = FanOutCoordinatorToolkit.toLayer({
303
261
  // apply unchanged.
304
262
  // ---------------------------------------------------------------------------
305
263
 
306
- export const FanOutReviewToolkit = Toolkit.make(ListReviewUnits, DelegateFileReview);
307
-
308
264
  /**
309
265
  * Build the coordinator's instructions. The same consumer guidance the
310
266
  * children receive is injected between the mission framing and the procedure
@@ -341,13 +297,17 @@ export const defaultFanOutPolicy = AgentPolicy.make({
341
297
  maxToolCalls: 1 + MAX_REVIEW_UNITS,
342
298
  maxDuration: "15 minutes",
343
299
  toolConcurrency: 3,
344
- // One declared batch may legitimately contain a failed result for every
345
- // review unit. Leave the coordinator one turn to report all of them, while
346
- // still stopping a model that declares another failed delegation.
347
- repeatedFailureLimit: MAX_REVIEW_UNITS + 1,
300
+ // Contained unit failures (SUB-033) are ordinary successful Tool results,
301
+ // so they no longer fold into the repeated-failure counter; the default
302
+ // bound suffices.
303
+ repeatedFailureLimit: 3,
348
304
  tokenBudget: 300_000,
349
- // See defaultFileReviewerPolicy: soft-landing adoption is the S2/S3 rework.
350
- onExhaustion: "fail",
305
+ // Child reports can amplify the merge prompt; compact before the provider's
306
+ // 200k-class window becomes the failure boundary.
307
+ contextTokenLimit: 150_000,
308
+ // Budget soft landing (RUN-018): an exhausted coordinator merges what it
309
+ // has into one best-effort review instead of discarding every child report.
310
+ onExhaustion: "final-answer",
351
311
  });
352
312
 
353
313
  /** Everything one fan-out configuration is made of, built as one unit so the
@@ -375,18 +335,6 @@ export interface FanOutSuiteOptions extends FanOutInstructionOptions {
375
335
  readonly maxFindings?: number | undefined;
376
336
  }
377
337
 
378
- const makeFanOutReviewerDefinition = (options: FanOutSuiteOptions = {}) =>
379
- Agent.define("pr-fanout-reviewer", {
380
- input: ReviewMission,
381
- output: CodeReview,
382
- instructions: makeFanOutReviewInstructions(options),
383
- toolkit: FanOutReviewToolkit,
384
- policy: defaultFanOutPolicy,
385
- description:
386
- "Coordinate one pull-request review by fanning bounded per-unit file reviews out to delegated children and merging their findings into one structured review.",
387
- metadata: { deploymentClass: "E", surface: "read-only", delegation: "S1-attached" },
388
- });
389
-
390
338
  const makeFileReviewDelegation = (child: ReturnType<typeof makeFileReviewerDefinition>) =>
391
339
  Subagent.define("delegate_file_review", {
392
340
  description: delegationDescription,
@@ -394,6 +342,11 @@ const makeFileReviewDelegation = (child: ReturnType<typeof makeFileReviewerDefin
394
342
  parameters: FileReviewRequest,
395
343
  success: FileReviewUnitResult,
396
344
  failure: FileReviewUnitFailed,
345
+ // First-party containment (SUB-033): a failed unit is model-visible
346
+ // result data instead of a parent-Run-fatal error, so the coordinator
347
+ // reports it honestly and keeps reviewing the other units. This retires
348
+ // the former same-name shadow-Tool workaround (FRICTION #7).
349
+ failureMode: "return",
397
350
  prepareInput: (request) =>
398
351
  Effect.succeed(
399
352
  FileReviewBrief.make({
@@ -416,13 +369,38 @@ const makeFileReviewDelegation = (child: ReturnType<typeof makeFileReviewerDefin
416
369
  policy: fileReviewPolicy,
417
370
  });
418
371
 
372
+ /**
373
+ * The coordinator-facing delegation Tool: the delegation's own first-party
374
+ * contained Tool plus the read-only execution class (the delegated child's
375
+ * whole tool surface is read-only). Effect AI resolves handlers by Tool name,
376
+ * so `SubagentRuntime.layer`'s handler serves this annotated copy unchanged.
377
+ */
378
+ const delegationToolFor = (delegation: ReturnType<typeof makeFileReviewDelegation>) =>
379
+ delegation.tool.annotate(ToolExecutionClass, "readonly");
380
+
381
+ const makeFanOutReviewerDefinition = (
382
+ options: FanOutSuiteOptions,
383
+ delegation: ReturnType<typeof makeFileReviewDelegation>,
384
+ ) =>
385
+ Agent.define("pr-fanout-reviewer", {
386
+ input: ReviewMission,
387
+ output: CodeReview,
388
+ instructions: makeFanOutReviewInstructions(options),
389
+ toolkit: Toolkit.make(ListReviewUnits, delegationToolFor(delegation)),
390
+ policy: defaultFanOutPolicy,
391
+ description:
392
+ "Coordinate one pull-request review by fanning bounded per-unit file reviews out to delegated children and merging their findings into one structured review.",
393
+ metadata: { deploymentClass: "E", surface: "read-only", delegation: "S1-attached" },
394
+ });
395
+
419
396
  /** Build one coherent fan-out suite: child, coordinator, and delegation. */
420
397
  export const makeFanOutReviewSuite = (options: FanOutSuiteOptions = {}): FanOutReviewSuite => {
421
398
  const child = makeFileReviewerDefinition({ guidance: options.guidance });
399
+ const delegation = makeFileReviewDelegation(child);
422
400
  return {
423
401
  child,
424
- parent: makeFanOutReviewerDefinition(options),
425
- delegation: makeFileReviewDelegation(child),
402
+ parent: makeFanOutReviewerDefinition(options, delegation),
403
+ delegation,
426
404
  };
427
405
  };
428
406
 
@@ -437,6 +415,19 @@ export const FanOutReviewer = defaultSuite.parent;
437
415
  /** The default delegation over the default child. */
438
416
  export const fileReviewDelegation = defaultSuite.delegation;
439
417
 
418
+ /** The default coordinator-facing delegation Tool (first-party contained mode). */
419
+ export const DelegateFileReview = delegationToolFor(fileReviewDelegation);
420
+
421
+ /** The default coordinator Toolkit. */
422
+ export const FanOutReviewToolkit = FanOutReviewer.toolkit;
423
+
424
+ /**
425
+ * The contained failure family the delegation can surface as result data
426
+ * (SUB-033), derived from the delegation itself so the coverage decoder can
427
+ * never diverge from what the runtime actually contains.
428
+ */
429
+ export const FileReviewDelegationFailure = fileReviewDelegation.containedFailure;
430
+
440
431
  /** Runtime wiring: one delegation plus one explicit child Binding. */
441
432
  export const fanOutHandlersLayerFor =
442
433
  (delegation: ReturnType<typeof makeFileReviewDelegation>) =>
@@ -1,4 +1,4 @@
1
- import { Effect, Layer, Option, Ref, Schema } from "effect";
1
+ import { DateTime, Effect, Layer, Option, Ref, Schema } from "effect";
2
2
 
3
3
  import { ChangedFile } from "./diff.ts";
4
4
  import {
@@ -93,6 +93,10 @@ export const collectingReviewPublisherLayer = (
93
93
  url: `memory://review/${plans.length}`,
94
94
  event: plan.event,
95
95
  inlineComments: plan.comments.length,
96
+ authorNodeId: "BOT_memory-reviewer",
97
+ submittedAt: DateTime.makeUnsafe(
98
+ `2026-01-01T00:00:${String(plans.length).padStart(2, "0")}Z`,
99
+ ),
96
100
  }),
97
101
  ),
98
102
  ),
@@ -1,5 +1,5 @@
1
1
  import { Config, Effect, FileSystem, Layer, Option, Schema } from "effect";
2
- import { FetchHttpClient } from "effect/unstable/http";
2
+ import type { HttpClient } from "effect/unstable/http";
3
3
 
4
4
  import type { PriorReviews, ReviewPublisher } from "./github.ts";
5
5
  import {
@@ -7,7 +7,9 @@ import {
7
7
  gitHubPriorReviewsLayer,
8
8
  gitHubPullRequestSourceLayer,
9
9
  gitHubReviewPublisherLayer,
10
+ gitHubReviewRetirementHostLayer,
10
11
  } from "./github.ts";
12
+ import type { ReviewRetirementHost } from "./retirement.ts";
11
13
  import type { PullRequestSource } from "./source.ts";
12
14
 
13
15
  // ---------------------------------------------------------------------------
@@ -105,24 +107,36 @@ export const resolveReviewTarget = Effect.fn("resolveReviewTarget")(function* (o
105
107
  */
106
108
  export const gitHubReviewLayers = (
107
109
  target: ResolvedReviewTarget,
108
- ): Layer.Layer<PullRequestSource | ReviewPublisher | PriorReviews, Config.ConfigError> =>
110
+ ): Layer.Layer<
111
+ PullRequestSource | ReviewPublisher | PriorReviews | ReviewRetirementHost,
112
+ Config.ConfigError,
113
+ HttpClient.HttpClient
114
+ > =>
109
115
  Layer.unwrap(
110
116
  Effect.gen(function* () {
111
117
  const apiUrl = yield* Config.string("GITHUB_API_URL").pipe(
112
118
  Config.withDefault("https://api.github.com"),
113
119
  );
120
+ const graphqlUrl = yield* Config.string("GITHUB_GRAPHQL_URL").pipe(
121
+ Config.withDefault(
122
+ apiUrl === "https://api.github.com"
123
+ ? "https://api.github.com/graphql"
124
+ : apiUrl.replace(/\/api\/v3$/, "/api/graphql"),
125
+ ),
126
+ );
114
127
  const token = yield* Config.option(Config.redacted("GITHUB_TOKEN"));
115
128
  const targetLayer = GitHubReviewTarget.layer({
116
129
  apiUrl,
130
+ graphqlUrl,
117
131
  repository: target.repository,
118
132
  number: target.number,
119
133
  token,
120
134
  });
121
- const deps = Layer.merge(targetLayer, FetchHttpClient.layer);
122
135
  return Layer.mergeAll(
123
- gitHubPullRequestSourceLayer.pipe(Layer.provide(deps)),
124
- gitHubReviewPublisherLayer.pipe(Layer.provide(deps)),
125
- gitHubPriorReviewsLayer.pipe(Layer.provide(deps)),
136
+ gitHubPullRequestSourceLayer.pipe(Layer.provide(targetLayer)),
137
+ gitHubReviewPublisherLayer.pipe(Layer.provide(targetLayer)),
138
+ gitHubPriorReviewsLayer.pipe(Layer.provide(targetLayer)),
139
+ gitHubReviewRetirementHostLayer.pipe(Layer.provide(targetLayer)),
126
140
  );
127
141
  }),
128
142
  );