Skip to content

feat: Add docsense-agent kit#228

Open
mehwishafsa wants to merge 4 commits into
Lamatic:mainfrom
mehwishafsa:docsense-agent
Open

feat: Add docsense-agent kit#228
mehwishafsa wants to merge 4 commits into
Lamatic:mainfrom
mehwishafsa:docsense-agent

Conversation

@mehwishafsa

@mehwishafsa mehwishafsa commented Jul 12, 2026

Copy link
Copy Markdown

DocSense — Adaptive Document-Intake Agent

An agentic document-intake kit for accountants. It reads each client document as it arrives and infers what's still missing — instead of relying on a static checklist.

The problem: you never know the full list of documents you need until you start reading what the client sends. A foreign payment means an extra tax form; a large cash deposit means a source-of-funds note. Today that depends on one person's memory.

What it does: reads each document, extracts the facts, and proposes new requirements the document triggers — each with cited evidence. For returning clients it stays quiet on routine items and surfaces only what's different this year.

Architecture: the Lamatic flow (docsense-intake: extraction → reasoning) does the fuzzy LLM work; a deterministic state model (apps/lib/requirement-state.ts) tracks the living requirement list and diffs returning clients against their baseline — so every requirement is explainable, never hallucinated.

Built with a two-node Lamatic flow + a Next.js app. Tested end-to-end.

  • Added the DocSense adaptive document-intake agent kit for accountants.
  • Added documentation covering the agent’s purpose, behavior, setup, structure, and deterministic requirement-tracking design.
  • Added Lamatic kit configuration, environment templates, ignore rules, model configurations, prompts, and constitution guidelines.
  • Added the docsense-intake flow:
    • GraphQL API trigger node receives document text and client context.
    • Dynamic LLM extraction node identifies document type and relevant facts.
    • Dynamic LLM reasoning node determines satisfied requirements and proposes new evidence-cited requirements.
    • API response node returns the reasoning result.
    • The flow runs extraction first, passes its facts into reasoning, and returns structured JSON without prose or markdown.
  • Added deterministic requirement-state logic for:
    • Creating new client profiles with baseline requirements.
    • Marking requirements as satisfied from incoming documents.
    • Adding newly triggered requirements with evidence and explanations.
    • Detecting anomalies for returning clients against historical baselines.
    • Listing outstanding requirements.
  • Added a Next.js DocSense application with:
    • Server-side Lamatic orchestration and defensive JSON parsing.
    • Document text input, sample data, loading/error states, and analysis results.
    • “Newly required” and “Still outstanding” requirement views.
    • Lamatic client configuration and environment validation.
  • Added reusable UI infrastructure and components based on Radix UI, Tailwind CSS, shadcn-style primitives, Lucide icons, charts, forms, navigation, dialogs, menus, tables, toasts, and responsive layouts.
  • Added mobile detection, toast state management, theme support, global styling, and Next.js configuration.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6184c9f7-a8a7-474d-8add-176f8a1d69f5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Changes

DocSense Agent Kit

Layer / File(s) Summary
Intake contracts and flow configuration
kits/docsense-agent/README.md, kits/docsense-agent/flows/..., kits/docsense-agent/apps/lib/..., kits/docsense-agent/prompts/...
Defines the intake flow, prompts, model configuration, deterministic requirement state, environment setup, constitution, and kit metadata.
Intake orchestration and application flow
kits/docsense-agent/apps/actions/..., kits/docsense-agent/apps/app/..., kits/docsense-agent/apps/lib/...
Connects document submission to Lamatic processing, updates requirement state, and renders the Next.js analysis interface.
Reusable UI component system
kits/docsense-agent/apps/components/..., kits/docsense-agent/apps/hooks/..., kits/docsense-agent/apps/app/globals.css
Adds the shared Tailwind foundation and reusable Radix, form, navigation, chart, feedback, layout, and interaction components used by the app.

Suggested reviewers: amanintech, d-pamneja

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the kit, but it does not follow the required PR checklist template or include the required sections. Rewrite it using the template sections: contribution type, general requirements, file structure, and validation checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly states the main change: adding the docsense-agent kit.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

:robot_face: AgentKit Structural Validation

New Contributions Detected

  • Kit: kits/docsense-agent

Check Results

Check Status
No edits to existing kits ✅ Pass
Required root files present ✅ Pass
Flow .ts files present ✅ Pass
lamatic.config.ts valid ✅ Pass
No changes outside kits/ ✅ Pass

🎉 All checks passed! This contribution follows the AgentKit structure.

@mehwishafsa

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 23

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@kits/docsense-agent/.env.example`:
- Line 1: Remove the leading BOM character from the .env.example file so line 1
begins directly with the DOCSENSE_INTAKE variable declaration, preserving the
existing key and value unchanged.

In `@kits/docsense-agent/apps/.env.example`:
- Line 1: Rewrite the .env.example file so line 1 starts directly with the
DOCSENSE_INTAKE key, removing the leading UTF-8 BOM character while preserving
the existing variable name and value.

In `@kits/docsense-agent/apps/actions/orchestrate.ts`:
- Around line 91-92: Update the docId generation in the ReceivedDoc construction
to use a collision-resistant unique identifier rather than Date.now() alone,
ensuring concurrent submissions receive distinct IDs and their evidence trails
cannot overwrite each other.
- Around line 82-84: Validate the parsed LLM output in the reasoning flow before
assigning `satisfies` and `triggers`. Define and apply a zod schema that
enforces each satisfy entry and `InferredTrigger` field shape, including
required `requirementId`, and use only the validated values when calling
`applyDocument` and `detectAnomalies`; handle invalid output according to the
existing error path.
- Around line 91-96: Update the ReceivedDoc construction in the orchestration
flow to populate docType and extractedFacts from the flow’s actual structured
extraction output instead of the hardcoded "unknown" and empty object. Preserve
the existing docId and receivedAt behavior, and pass the payload fields expected
by requirement-state.ts into each stored receivedDocs entry.

In `@kits/docsense-agent/apps/app/layout.tsx`:
- Around line 10-12: Update the metadata title and description in the layout
configuration to use DocSense branding instead of the leftover “v0 App” and
“Created with v0” scaffold values, while leaving the generator setting
unchanged.

In `@kits/docsense-agent/apps/app/page.tsx`:
- Around line 31-47: Update handleAnalyze to wrap the intakeDocument call and
response handling in try/catch/finally. In the catch block, set an appropriate
error message from the thrown error, and move setLoading(false) into finally so
loading always ends for success, returned failures, and thrown server or network
errors.

In `@kits/docsense-agent/apps/components/header.tsx`:
- Around line 7-42: Update the header component’s hardcoded Tailwind color
classes, including border-slate-200, bg-white, text-slate-800, text-rose-500,
and the Docs/GitHub color classes, to use the app’s theme-aware CSS-variable
utility classes consistent with page.tsx, card.tsx, and drawer.tsx. Preserve the
existing layout, spacing, hover behavior, and link styling while ensuring all
header colors adapt to dark mode and custom themes.

In `@kits/docsense-agent/apps/components/ui/button-group.tsx`:
- Around line 1-5: Add the namespace React import used by the
React.ComponentProps references in the button-group component, matching the
import style of sibling components; leave the existing Slot, cva, cn, and
Separator imports unchanged.

In `@kits/docsense-agent/apps/components/ui/carousel.tsx`:
- Around line 96-105: Update the cleanup function in the React.useEffect
subscription around api, onSelect, and the reInit/select listeners to detach the
reInit listener as well as the select listener. Preserve the existing
subscription behavior and ensure both handlers are removed when the effect
reruns or unmounts.

In `@kits/docsense-agent/apps/components/ui/empty.tsx`:
- Around line 71-82: Update EmptyDescription so its props use the React
component props type for a div, matching the element it renders. Preserve the
existing className handling, data-slot attribute, and rendered styling.

In `@kits/docsense-agent/apps/components/ui/form.tsx`:
- Around line 28-30: Update FormFieldContext to use a null default, then change
useFormField to validate the context before reading fieldContext.name or calling
useFormState/getFieldState. Throw the existing missing-FormField error when no
context is present, while preserving normal field state behavior for valid
FormField usage.

In `@kits/docsense-agent/apps/components/ui/input-group.tsx`:
- Around line 64-79: Remove the role="group" attribute from the InputGroupAddon
component’s returned div, leaving the parent InputGroup as the sole group
landmark while preserving the addon’s other attributes and behavior.
- Around line 70-76: Update InputGroupAddon’s click handling so consumer props
do not overwrite the internal focus behavior: place prop spreading before the
internal onClick or explicitly compose both handlers. Change the queried control
selector to focus either the group’s input or textarea, while preserving the
existing button-click exclusion.

In `@kits/docsense-agent/apps/components/ui/label.tsx`:
- Around line 8-22: No functional change is required: keep the Label component’s
current prop spreading and ref behavior under React 19.2.0. Only convert Label
to React.forwardRef if consistency with other exposed UI primitives is
explicitly desired; otherwise leave the implementation unchanged.

In `@kits/docsense-agent/apps/components/ui/spinner.tsx`:
- Around line 1-5: Add the missing React import required by the
React.ComponentProps type annotation in Spinner, following the explicit import
pattern used by the surrounding UI components. Keep the existing Loader2Icon,
cn, and Spinner implementation unchanged.

In `@kits/docsense-agent/apps/lib/requirement-state.ts`:
- Around line 114-152: Update applyDocument so requirement status changes do not
mutate objects from the input profile: when marking a satisfied requirement as
received, create and store a replacement Requirement object in reqById while
preserving all existing fields. Keep the returned updated profile and
newlySurfaced behavior unchanged, and ensure the original profile.requirements
entries remain untouched.

In `@kits/docsense-agent/apps/next.config.mjs`:
- Around line 6-8: Document the rationale for setting images.unoptimized to true
in the Next.js configuration by adding a brief inline comment explaining why
built-in image optimization is intentionally disabled. Keep the existing
configuration value unchanged.
- Around line 3-5: Remove the ignoreBuildErrors setting from the Next.js
typescript configuration so production builds fail on TypeScript errors. Do not
replace it with a production-wide suppression; if development-only behavior is
required, gate it explicitly to development while keeping production validation
enabled.

In `@kits/docsense-agent/apps/README.md`:
- Around line 1-12: Update the README content for the DocSense Agent rather than
the copied Generation kit: change the title and descriptive references, use the
DocSense Vercel deployment settings with root directory kits/docsense-agent and
DOCSENSE_INTAKE, update setup instructions to reference DocSense, replace
AGENTIC_GENERATE_CONTENT with DOCSENSE_INTAKE, and revise the repository
structure to match the actual DocSense kit layout.

In `@kits/docsense-agent/flows/docsense-intake.ts`:
- Around line 143-154: Update the API Response node configuration identified by
nodeId "graphqlResponseNode" so its outputMapping maps the DocSense reasoning
node's payload into result. Replace the empty mapping while preserving the
existing response settings, ensuring executeFlow returns the reasoning output
for apps/actions/orchestrate.ts to parse.
- Around line 56-71: Update the triggerNode_1 configuration so its values
declaration uses the input name document instead of sampleInput, preserving the
existing string type/schema and trigger metadata to match the payload consumed
by the extraction flow.

In
`@kits/docsense-agent/model-configs/docsense-intake_llmnode-599_generative-model-name.ts`:
- Around line 4-13: The generativeModelName configuration has a
credential/provider mismatch. Update credential_name in the configuration entry
with provider_name "gemini" and model_name "gemini/gemini-2.5-flash" to the
correct Gemini credential name, preserving the existing credentialId mapping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: eba7c51f-9690-47c5-9898-da926c389f1d

📥 Commits

Reviewing files that changed from the base of the PR and between dafde4c and 3991fe5.

⛔ Files ignored due to path filters (1)
  • kits/docsense-agent/apps/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (88)
  • kits/docsense-agent/.env.example
  • kits/docsense-agent/.gitignore
  • kits/docsense-agent/README.md
  • kits/docsense-agent/agent.md
  • kits/docsense-agent/apps/.env.example
  • kits/docsense-agent/apps/.gitignore
  • kits/docsense-agent/apps/README.md
  • kits/docsense-agent/apps/actions/orchestrate.ts
  • kits/docsense-agent/apps/app/globals.css
  • kits/docsense-agent/apps/app/layout.tsx
  • kits/docsense-agent/apps/app/page.tsx
  • kits/docsense-agent/apps/components.json
  • kits/docsense-agent/apps/components/header.tsx
  • kits/docsense-agent/apps/components/theme-provider.tsx
  • kits/docsense-agent/apps/components/ui/accordion.tsx
  • kits/docsense-agent/apps/components/ui/alert-dialog.tsx
  • kits/docsense-agent/apps/components/ui/alert.tsx
  • kits/docsense-agent/apps/components/ui/aspect-ratio.tsx
  • kits/docsense-agent/apps/components/ui/avatar.tsx
  • kits/docsense-agent/apps/components/ui/badge.tsx
  • kits/docsense-agent/apps/components/ui/breadcrumb.tsx
  • kits/docsense-agent/apps/components/ui/button-group.tsx
  • kits/docsense-agent/apps/components/ui/button.tsx
  • kits/docsense-agent/apps/components/ui/calendar.tsx
  • kits/docsense-agent/apps/components/ui/card.tsx
  • kits/docsense-agent/apps/components/ui/carousel.tsx
  • kits/docsense-agent/apps/components/ui/chart.tsx
  • kits/docsense-agent/apps/components/ui/checkbox.tsx
  • kits/docsense-agent/apps/components/ui/collapsible.tsx
  • kits/docsense-agent/apps/components/ui/command.tsx
  • kits/docsense-agent/apps/components/ui/context-menu.tsx
  • kits/docsense-agent/apps/components/ui/dialog.tsx
  • kits/docsense-agent/apps/components/ui/drawer.tsx
  • kits/docsense-agent/apps/components/ui/dropdown-menu.tsx
  • kits/docsense-agent/apps/components/ui/empty.tsx
  • kits/docsense-agent/apps/components/ui/field.tsx
  • kits/docsense-agent/apps/components/ui/form.tsx
  • kits/docsense-agent/apps/components/ui/hover-card.tsx
  • kits/docsense-agent/apps/components/ui/input-group.tsx
  • kits/docsense-agent/apps/components/ui/input-otp.tsx
  • kits/docsense-agent/apps/components/ui/input.tsx
  • kits/docsense-agent/apps/components/ui/item.tsx
  • kits/docsense-agent/apps/components/ui/kbd.tsx
  • kits/docsense-agent/apps/components/ui/label.tsx
  • kits/docsense-agent/apps/components/ui/menubar.tsx
  • kits/docsense-agent/apps/components/ui/navigation-menu.tsx
  • kits/docsense-agent/apps/components/ui/pagination.tsx
  • kits/docsense-agent/apps/components/ui/popover.tsx
  • kits/docsense-agent/apps/components/ui/progress.tsx
  • kits/docsense-agent/apps/components/ui/radio-group.tsx
  • kits/docsense-agent/apps/components/ui/resizable.tsx
  • kits/docsense-agent/apps/components/ui/scroll-area.tsx
  • kits/docsense-agent/apps/components/ui/select.tsx
  • kits/docsense-agent/apps/components/ui/separator.tsx
  • kits/docsense-agent/apps/components/ui/sheet.tsx
  • kits/docsense-agent/apps/components/ui/sidebar.tsx
  • kits/docsense-agent/apps/components/ui/skeleton.tsx
  • kits/docsense-agent/apps/components/ui/slider.tsx
  • kits/docsense-agent/apps/components/ui/sonner.tsx
  • kits/docsense-agent/apps/components/ui/spinner.tsx
  • kits/docsense-agent/apps/components/ui/switch.tsx
  • kits/docsense-agent/apps/components/ui/table.tsx
  • kits/docsense-agent/apps/components/ui/tabs.tsx
  • kits/docsense-agent/apps/components/ui/textarea.tsx
  • kits/docsense-agent/apps/components/ui/toast.tsx
  • kits/docsense-agent/apps/components/ui/toaster.tsx
  • kits/docsense-agent/apps/components/ui/toggle-group.tsx
  • kits/docsense-agent/apps/components/ui/toggle.tsx
  • kits/docsense-agent/apps/components/ui/tooltip.tsx
  • kits/docsense-agent/apps/components/ui/use-mobile.tsx
  • kits/docsense-agent/apps/components/ui/use-toast.ts
  • kits/docsense-agent/apps/hooks/use-mobile.ts
  • kits/docsense-agent/apps/hooks/use-toast.ts
  • kits/docsense-agent/apps/lib/lamatic-client.ts
  • kits/docsense-agent/apps/lib/requirement-state.ts
  • kits/docsense-agent/apps/lib/utils.ts
  • kits/docsense-agent/apps/next.config.mjs
  • kits/docsense-agent/apps/package.json
  • kits/docsense-agent/apps/tsconfig.json
  • kits/docsense-agent/constitutions/default.md
  • kits/docsense-agent/flows/docsense-intake.ts
  • kits/docsense-agent/lamatic.config.ts
  • kits/docsense-agent/model-configs/docsense-intake_llmnode-421_generative-model-name.ts
  • kits/docsense-agent/model-configs/docsense-intake_llmnode-599_generative-model-name.ts
  • kits/docsense-agent/prompts/docsense-intake_llmnode-421_system_0.md
  • kits/docsense-agent/prompts/docsense-intake_llmnode-421_user_1.md
  • kits/docsense-agent/prompts/docsense-intake_llmnode-599_system_0.md
  • kits/docsense-agent/prompts/docsense-intake_llmnode-599_user_1.md

@@ -0,0 +1,4 @@
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Remove the BOM character at the start of line 1.

A byte order mark (U+FEFF) precedes DOCSENSE_INTAKE. Some env parsers fail to handle BOM and will silently miss the first variable, causing DOCSENSE_INTAKE to be undefined at runtime.

🔧 Proposed fix
-DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
+DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
🧰 Tools
🪛 dotenv-linter (4.0.0)

[warning] 1-1: [LeadingCharacter] Invalid leading character detected

(LeadingCharacter)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/.env.example` at line 1, Remove the leading BOM character
from the .env.example file so line 1 begins directly with the DOCSENSE_INTAKE
variable declaration, preserving the existing key and value unchanged.

Source: Linters/SAST tools

@@ -0,0 +1,4 @@
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Remove the BOM character from line 1.

Line 1 begins with a UTF-8 BOM (U+FEFF, rendered as ). Some .env parsers will read the key as \uFEFFDOCSENSE_INTAKE rather than DOCSENSE_INTAKE, silently causing the variable to never load. Rewrite the file without the BOM prefix.

🔧 Proposed fix
-DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
+DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
DOCSENSE_INTAKE="DOCSENSE_INTAKE Flow ID"
🧰 Tools
🪛 dotenv-linter (4.0.0)

[warning] 1-1: [LeadingCharacter] Invalid leading character detected

(LeadingCharacter)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/.env.example` at line 1, Rewrite the .env.example
file so line 1 starts directly with the DOCSENSE_INTAKE key, removing the
leading UTF-8 BOM character while preserving the existing variable name and
value.

Source: Linters/SAST tools

Comment on lines +82 to +84
const reasoning = parseReasoning(resData?.result);
const satisfies: string[] = reasoning.satisfies ?? [];
let triggers: InferredTrigger[] = reasoning.triggers ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Trust, but verify — the LLM's JSON is consumed unchecked.

reasoning.satisfies/reasoning.triggers are cast straight from parsed LLM output with no shape validation, so a malformed or hallucinated field (e.g. missing requirementId) flows directly into applyDocument/detectAnomalies. zod is already a project dependency — a small schema would catch drift cheaply.

♻️ Proposed validation
+import { z } from "zod";
+
+const ReasoningSchema = z.object({
+  satisfies: z.array(z.string()).optional(),
+  triggers: z
+    .array(
+      z.object({
+        requirementId: z.string(),
+        label: z.string(),
+        reason: z.string(),
+      })
+    )
+    .optional(),
+});
+
 function parseReasoning(raw: unknown): ReasoningResult {
   if (raw == null) return {};
-  if (typeof raw === "object") return raw as ReasoningResult;
+  if (typeof raw === "object") {
+    const parsed = ReasoningSchema.safeParse(raw);
+    return parsed.success ? parsed.data : {};
+  }
   if (typeof raw !== "string") return {};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const reasoning = parseReasoning(resData?.result);
const satisfies: string[] = reasoning.satisfies ?? [];
let triggers: InferredTrigger[] = reasoning.triggers ?? [];
import { z } from "zod";
const ReasoningSchema = z.object({
satisfies: z.array(z.string()).optional(),
triggers: z
.array(
z.object({
requirementId: z.string(),
label: z.string(),
reason: z.string(),
})
)
.optional(),
});
function parseReasoning(raw: unknown): ReasoningResult {
if (raw == null) return {};
if (typeof raw === "object") {
const parsed = ReasoningSchema.safeParse(raw);
return parsed.success ? parsed.data : {};
}
if (typeof raw !== "string") return {};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/actions/orchestrate.ts` around lines 82 - 84,
Validate the parsed LLM output in the reasoning flow before assigning
`satisfies` and `triggers`. Define and apply a zod schema that enforces each
satisfy entry and `InferredTrigger` field shape, including required
`requirementId`, and use only the validated values when calling `applyDocument`
and `detectAnomalies`; handle invalid output according to the existing error
path.

Comment on lines +91 to +92
const doc: ReceivedDoc = {
docId: `doc-${Date.now()}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Date.now() isn't a safe cover identity for concurrent docs.

If two documents are submitted in the same millisecond (e.g. a batch upload via Promise.all), docId collisions overwrite each other's evidence trail.

🪪 Proposed fix
     const doc: ReceivedDoc = {
-      docId: `doc-${Date.now()}`,
+      docId: `doc-${crypto.randomUUID()}`,
       docType: "unknown",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const doc: ReceivedDoc = {
docId: `doc-${Date.now()}`,
const doc: ReceivedDoc = {
docId: `doc-${crypto.randomUUID()}`,
docType: "unknown",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/actions/orchestrate.ts` around lines 91 - 92, Update
the docId generation in the ReceivedDoc construction to use a
collision-resistant unique identifier rather than Date.now() alone, ensuring
concurrent submissions receive distinct IDs and their evidence trails cannot
overwrite each other.

Comment on lines +91 to +96
const doc: ReceivedDoc = {
docId: `doc-${Date.now()}`,
docType: "unknown",
extractedFacts: {},
receivedAt: new Date().toISOString(),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

set -euo pipefail

printf 'Repo root: '; pwd

# Map relevant files and their sizes first
git ls-files 'kits/docsense-agent/apps/actions/orchestrate.ts' 'kits/docsense-agent/apps/**/requirement-state.ts' 'kits/docsense-agent/apps/**/flow*.ts' 'kits/docsense-agent/apps/**/flow*.tsx' 'kits/docsense-agent/apps/**/workflow*.ts'

echo
echo '--- outline orchestrate.ts ---'
ast-grep outline kits/docsense-agent/apps/actions/orchestrate.ts --view expanded || true

echo
echo '--- outline requirement-state.ts candidates ---'
for f in $(git ls-files 'kits/docsense-agent/apps/**/requirement-state.ts'); do
  echo "FILE: $f"
  ast-grep outline "$f" --view expanded || true
done

echo
echo '--- search for outputMapping / ReceivedDoc / docType / extractedFacts ---'
rg -n "outputMapping|ReceivedDoc|extractedFacts|docType|reasoning\.satisfies|reasoning\.triggers" kits/docsense-agent/apps -S

Repository: Lamatic/AgentKit

Length of output: 3158


🏁 Script executed:

set -euo pipefail

# If the first query didn't find the exact files, discover nearby relevant ones.
echo '--- candidate files under kits/docsense-agent/apps ---'
fd -t f -a 'requirement-state.ts|orchestrate.ts|flow.*\.ts$|workflow.*\.ts$' kits/docsense-agent/apps || true

Repository: Lamatic/AgentKit

Length of output: 345


🏁 Script executed:

set -euo pipefail

# Read the relevant sections once the file locations are known.
# This script is intentionally read-only.
for f in kits/docsense-agent/apps/actions/orchestrate.ts $(git ls-files 'kits/docsense-agent/apps/**/requirement-state.ts' | head -n 5); do
  [ -f "$f" ] || continue
  echo "===== $f ====="
  nl -ba "$f" | sed -n '1,220p'
  echo
done

Repository: Lamatic/AgentKit

Length of output: 254


🏁 Script executed:

set -euo pipefail

echo '--- locate relevant files ---'
git ls-files 'kits/docsense-agent/apps/**/orchestrate.ts' 'kits/docsense-agent/apps/**/requirement-state.ts' 'kits/docsense-agent/apps/**/flow*.ts' 'kits/docsense-agent/apps/**/workflow*.ts'

echo
echo '--- search for key symbols ---'
rg -n "outputMapping|ReceivedDoc|extractedFacts|docType|reasoning\.satisfies|reasoning\.triggers|docId" kits/docsense-agent/apps -S

Repository: Lamatic/AgentKit

Length of output: 1627


🏁 Script executed:

set -euo pipefail

echo '--- orchestrate.ts relevant slice ---'
sed -n '1,180p' kits/docsense-agent/apps/actions/orchestrate.ts

echo
echo '--- requirement-state.ts relevant slice ---'
sed -n '1,220p' kits/docsense-agent/apps/lib/requirement-state.ts

Repository: Lamatic/AgentKit

Length of output: 9549


Wire the real extraction payload into ReceivedDoc kits/docsense-agent/apps/actions/orchestrate.ts: docType and extractedFacts are still hardcoded to "unknown" / {}, so every stored receivedDocs entry drops the evidence trail that requirement-state.ts expects. Pass through the flow’s actual structured output here instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/actions/orchestrate.ts` around lines 91 - 96, Update
the ReceivedDoc construction in the orchestration flow to populate docType and
extractedFacts from the flow’s actual structured extraction output instead of
the hardcoded "unknown" and empty object. Preserve the existing docId and
receivedAt behavior, and pass the payload fields expected by
requirement-state.ts into each stored receivedDocs entry.

Comment on lines +6 to +8
images: {
unoptimized: true,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider documenting why image optimization is disabled.

images.unoptimized: true disables Next.js's built-in image optimization (lazy loading, responsive sizes, format conversion). If this is intentional for the kit (e.g., no image-heavy content), consider adding a brief comment explaining the rationale so future contributors don't remove it without understanding the context.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/next.config.mjs` around lines 6 - 8, Document the
rationale for setting images.unoptimized to true in the Next.js configuration by
adding a brief inline comment explaining why built-in image optimization is
intentionally disabled. Keep the existing configuration value unchanged.

Comment on lines +1 to +12
# Agent Kit Generation by Lamatic.ai

<p align="center">
<a href="https://agent-kit-generation.vercel.app" target="_blank">
<img src="https://img.shields.io/badge/Live%20Demo-black?style=for-the-badge" alt="Live Demo" />
</a>
</p>


**Agent Kit Generation** is an AI-powered content generation system built with [Lamatic.ai](https://lamatic.ai). It uses intelligent workflows to generate text, images, and JSON content through a modern Next.js interface with markdown rendering support.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/Lamatic/AgentKit&root-directory=kits/agentic/generation&env=AGENTIC_GENERATE_CONTENT,LAMATIC_API_URL,LAMATIC_PROJECT_ID,LAMATIC_API_KEY&envDescription=Your%20Lamatic%20Generation%20keys%20are%20required.&envLink=https://lamatic.ai/templates/agentkits/agentic/agent-kit-generation)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

This README is copy-pasted from the Generation kit — update it for DocSense.

Every key reference points to the wrong kit. Users following these instructions will be unable to deploy or configure DocSense:

  • Line 1: Title says "Agent Kit Generation" — should be "DocSense Agent"
  • Line 12: Deploy URL uses root-directory=kits/agentic/generation and env=AGENTIC_GENERATE_CONTENT — should be kits/docsense-agent and DOCSENSE_INTAKE
  • Line 24: Template reference says "Select the 'Generation' agent kit" — should reference DocSense
  • Lines 62-65: Env var AGENTIC_GENERATE_CONTENT should be DOCSENSE_INTAKE (matches kits/docsense-agent/.env.example)
  • Lines 79-94: Repo structure doesn't match the actual kit layout

Would you like me to generate a corrected README tailored to the DocSense kit?

Also applies to: 20-27, 56-66

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/apps/README.md` around lines 1 - 12, Update the README
content for the DocSense Agent rather than the copied Generation kit: change the
title and descriptive references, use the DocSense Vercel deployment settings
with root directory kits/docsense-agent and DOCSENSE_INTAKE, update setup
instructions to reference DocSense, replace AGENTIC_GENERATE_CONTENT with
DOCSENSE_INTAKE, and revise the repository structure to match the actual
DocSense kit layout.

Comment on lines +56 to +71
"id": "triggerNode_1",
"type": "triggerNode",
"position": {
"x": 0,
"y": 0
},
"data": {
"nodeId": "graphqlNode",
"trigger": true,
"values": {
"nodeName": "API Request",
"responeType": "realtime",
"advance_schema": "{\"sampleInput\":\"string\"}"
}
}
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check what variable name the extraction prompts actually interpolate.
rg -n "sampleInput|triggerNode_1.output" kits/docsense-agent/prompts

Repository: Lamatic/AgentKit

Length of output: 154


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the relevant files first.
git ls-files 'kits/docsense-agent/flows/docsense-intake.ts' \
             'kits/docsense-agent/flows/orchestrate.ts' \
             'kits/docsense-agent/prompts/*'

echo '--- outline: docsense-intake.ts ---'
ast-grep outline kits/docsense-agent/flows/docsense-intake.ts --view expanded || true

echo '--- outline: orchestrate.ts ---'
ast-grep outline kits/docsense-agent/flows/orchestrate.ts --view expanded || true

echo '--- rg for triggerNode_1, sampleInput, document ---'
rg -n "triggerNode_1|sampleInput|documentText|resData\\?\\.result|outputMapping|advance_schema|responseNode" kits/docsense-agent/flows kits/docsense-agent/prompts

Repository: Lamatic/AgentKit

Length of output: 1932


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the relevant slices with line numbers once the files are identified.
sed -n '1,240p' kits/docsense-agent/flows/docsense-intake.ts | cat -n
echo '---'
sed -n '1,240p' kits/docsense-agent/flows/orchestrate.ts | cat -n

Repository: Lamatic/AgentKit

Length of output: 6409


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- files under kits/docsense-agent ---'
git ls-files 'kits/docsense-agent/**'

echo '--- search for documentText / sampleInput / triggerNode_1.output / advance_schema ---'
rg -n "documentText|sampleInput|triggerNode_1\\.output|advance_schema|outputMapping|docsense-intake" kits/docsense-agent .

echo '--- prompt contents (small slices) ---'
for f in kits/docsense-agent/prompts/docsense-intake_llmnode-599_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-599_user_1.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_user_1.md; do
  echo "### $f"
  sed -n '1,220p' "$f" | cat -n
  echo
done

Repository: Lamatic/AgentKit

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- docsense-intake prompts ---'
for f in kits/docsense-agent/prompts/docsense-intake_llmnode-599_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-599_user_1.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_user_1.md; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,200p'
  echo
done

echo '--- direct pattern search in docsense prompts ---'
rg -n "sampleInput|document|triggerNode_1\\.output" kits/docsense-agent/prompts/docsense-intake_*.md

Repository: Lamatic/AgentKit

Length of output: 299


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- apps/actions/orchestrate.ts ---'
nl -ba kits/docsense-agent/apps/actions/orchestrate.ts | sed -n '1,180p'

echo '--- apps/app/page.tsx ---'
nl -ba kits/docsense-agent/apps/app/page.tsx | sed -n '1,120p'

Repository: Lamatic/AgentKit

Length of output: 230


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- prompt files with line numbers via awk ---'
for f in kits/docsense-agent/prompts/docsense-intake_llmnode-599_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-599_user_1.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_system_0.md \
         kits/docsense-agent/prompts/docsense-intake_llmnode-421_user_1.md; do
  echo "### $f"
  awk '{printf "%4d  %s\n", NR, $0}' "$f" | sed -n '1,220p'
  echo
done

echo '--- quick search for common placeholder syntax ---'
rg -n "\{\{.*\}\}|sampleInput|documentText|triggerNode_1\.output|document" kits/docsense-agent/prompts/docsense-intake_*.md

Repository: Lamatic/AgentKit

Length of output: 5558


Rename the trigger input to document.
apps/actions/orchestrate.ts sends { document: documentText }, and the extraction prompt reads {{trigger.output.document}}, but triggerNode_1 still declares sampleInput. That leaves the document payload outside the flow contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@kits/docsense-agent/flows/docsense-intake.ts` around lines 56 - 71, Update
the triggerNode_1 configuration so its values declaration uses the input name
document instead of sampleInput, preserving the existing string type/schema and
trigger metadata to match the payload consumed by the extraction flow.

Comment thread kits/docsense-agent/flows/docsense-intake.ts
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@akshatvirmani

Copy link
Copy Markdown
Contributor

/validate

@github-actions

Copy link
Copy Markdown
Contributor

📡 Running Studio validation — results will appear here shortly.

@github-actions

Copy link
Copy Markdown
Contributor

Studio Runtime Validation (Phase 2)

Studio validation passed. The kit loaded successfully in Lamatic Studio.

This PR is ready for final review and merge.

@akshatvirmani

Copy link
Copy Markdown
Contributor

@mehwishafsa please resolve the comments above

@mehwishafsa

mehwishafsa commented Jul 13, 2026 via email

Copy link
Copy Markdown
Author

@akshatvirmani

Copy link
Copy Markdown
Contributor

/validate

@github-actions

Copy link
Copy Markdown
Contributor

📡 Running Studio validation — results will appear here shortly.

@akshatvirmani

Copy link
Copy Markdown
Contributor

Hello

@mehwishafsa great! One thing: please resolve the remaining coderabbit comments

@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants