Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ai-issue-triager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: AI Issue Triager

on:
issues:
types: [opened]

jobs:
triage:
runs-on: ubuntu-latest
permissions:
issues: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run AI Triage
run: |
npm run ai:triage
env:
ISSUE_BODY: ${{ github.event.issue.body }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
40 changes: 40 additions & 0 deletions .github/workflows/ai-pr-reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: AI PR Reviewer

on:
pull_request:
types: [opened, synchronize]

jobs:
review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run AI PR Review
run: |
npm run ai:pr-review
env:
BASE_REF: ${{ github.base_ref }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v3

Check failure on line 37 in .github/workflows/ai-pr-reviewer.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=NITISH-R-G_Intelli-Credit-V2&issues=AZ9huRO-UL-_drkNFe4x&open=AZ9huRO-UL-_drkNFe4x&pullRequest=115
with:
file-path: 'pr_review.md'
comment-tag: 'ai-pr-review'
46 changes: 46 additions & 0 deletions .github/workflows/autonomous-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Autonomous Documentation

on:
push:
branches:
- main
paths-ignore:
- 'docs/**'

jobs:
generate-docs:
runs-on: ubuntu-latest
Comment on lines +10 to +12

Copy link
Copy Markdown

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

Add concurrency limits to prevent git push conflicts.

Since this workflow commits and pushes to main, concurrent runs triggered by rapid pushes can result in git push failures due to diverging branches. Adding a concurrency group will queue the runs and prevent these conflicts.

🛡️ Proposed fix
 jobs:
   generate-docs:
     runs-on: ubuntu-latest
+    concurrency:
+      group: ${{ github.workflow }}-${{ github.ref }}
+      cancel-in-progress: false
     permissions:
📝 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
jobs:
generate-docs:
runs-on: ubuntu-latest
jobs:
generate-docs:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
🧰 Tools
🪛 zizmor (1.26.1)

[info] 11-11: workflow or action definition without a name (anonymous-definition): this job

(anonymous-definition)

🤖 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 @.github/workflows/autonomous-docs.yml around lines 10 - 12, Add a
workflow-level or job-level concurrency configuration for generate-docs, using a
stable group keyed to this workflow or the target branch and enabling queued
execution rather than canceling in-progress runs. Keep the existing runs-on and
documentation generation behavior unchanged.

permissions:
contents: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Repo Analysis
run: npm run analyze:repo

- name: Generate Diagrams
run: npm run generate:diagrams

- name: Generate Knowledge Graph
run: npm run generate:knowledge-graph

- name: Commit and Push Changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add docs/
git commit -m "docs: auto-update repository documentation and architecture diagrams" || exit 0
git push
31 changes: 31 additions & 0 deletions .github/workflows/continuous-improvement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Continuous Improvement

on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
workflow_dispatch:

jobs:
improve:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Continuous Improvement Script
run: npm run ai:improve
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
Comment on lines +30 to +31

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Remove the unnecessary secret exposure.

The GEMINI_API_KEY secret is being injected into the environment, but the underlying target script (scripts/automation/ai-improve.ts) currently uses a mocked implementation that does not consume the API key (as seen in the provided context). Exposing secrets to an environment where they are not used violates the principle of least privilege.

Consider removing these lines, or wait to include them until the script is fully implemented to call the Gemini API.

🛡️ Proposed fix
-        env:
-          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
📝 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
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
🤖 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 @.github/workflows/continuous-improvement.yml around lines 30 - 31, Remove
the GEMINI_API_KEY environment mapping from the workflow job; the current
scripts/automation/ai-improve.ts implementation does not consume it, so the
secret should not be exposed until Gemini API integration is implemented.

53 changes: 53 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Intelli-Credit Terminal AI Guidelines

This repository is designed to be an automated corporate credit appraisal application and a highly automated open-source repository. All AI assistants MUST adhere to the following directives:

## 1. Automation First

Every repetitive task that can be automated must be automated.

- If you find yourself doing something manually that could be scripted, create a script in `scripts/automation/`.
- Ensure all automated tasks are self-contained and idempotent.

## 2. Self-Healing

- Use `npm run fix` (which runs `lint:fix` and `format`) to automatically resolve linting and formatting issues.
- Attempt to continuously repair CI failures when safe to do so.
- When generating fixes or patches, use AI to automate simple conflicts and suggest solutions.

## 3. Pre-Commit Validation

Before submitting any changes, you must validate your work by running:

1. `npm test`
2. `npm run typecheck`
3. `npm run format`
4. `npm run lint`

## 4. Security Rules

- Prevent command injection: Do not use `execSync` or `exec` with concatenated strings in automation scripts. Use `execFileSync` with separated executable and argument arrays instead.
- Native APIs: Rewrite piped shell commands (`|`) using native Node.js logic since `execFileSync` does not support pipes.
- Audits: Run `npm audit --audit-level=high` regularly. Ensure dependencies are secure.

## 5. Coding Standards

- Do NOT use `console.log`. The ESLint configuration prohibits it.
- Use `console.info`, `console.warn`, or `console.error` in automation scripts and application code.
- Ensure type safety by maintaining strict TypeScript typing.

## 6. Continuous Knowledge

- The repository autonomously generates and maintains its knowledge graph and architecture diagrams in the `docs/` folder via the `npm run analyze:repo`, `npm run generate:diagrams`, and `npm run generate:knowledge-graph` scripts. Do not manually edit files in `docs/` that are auto-generated.
- Documentation must regenerate whenever the repository changes.

## 7. GitHub Actions

- When writing or updating GitHub Actions, especially when using `thollander/actions-comment-pull-request@v3`, ensure inputs use kebab-case (e.g., `file-path`, `comment-tag`).
- Variables like `github.base_ref` and `github.head_ref` must be assigned to environment variables and referenced (e.g., `$BASE_REF`) in run scripts to prevent command injection vulnerabilities, rather than injected directly using `${{ }}`.
- When generating git diffs in PR triggers, use `git diff origin/$BASE_REF...HEAD`.

## 8. AI Reviewer

- The repository automates pull request reviews using a dedicated AI PR Reviewer GitHub Action.
- The workflow generates feedback via artifacts or comments, utilizing the `GEMINI_API_KEY` secret.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed

- Repository transformed for open-source readiness: MIT License added, README
rewritten, CONTRIBUTING/SECURITY expanded, structured issue templates and PR
template, deterministic CI/release automation.

### Removed

- All AI-dependent and autonomous-commit automation (AI doc agent, self-healing
auto-fix, self-updating README, autonomous repo analysis, dashboard
generator) and their generated artifacts (`metadata.json`,
Expand All @@ -22,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.0.0] — 2026-06-23

### Security

- Moved the Google Gemini API key fully server-side into Vercel serverless
functions (`/api/analyze`). The key is never bundled, never logged, and never
returned to the client. The `@google/genai` SDK is absent from the client
Expand All @@ -37,12 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Restricted dev-server CORS from `*` to a localhost + optional origin allowlist.

### Added

- `api/analyze.ts`, `api/_lib/analyze-core.ts`, `api/_lib/mcp-tools.ts`,
`api/_lib/limits.ts` — the serverless analysis layer and shared limits.
- Tests for upload limits and analysis-core resilience (timeout, retry,
guard paths).

### Changed

- `performAnalysis` now POSTs to `/api/analyze` and runs the pure client-side
`calculateRiskAndFraud` on the result; structured server error codes map to
precise UI messages.
Expand All @@ -51,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CI runs `typecheck`, `lint`, `test`, and `build` (was `tsc` + `test` + `build`).

### Removed

- Dead dependencies: `pdf-parse`, `@types/pdf-parse`,
`@types/express-rate-limit`, duplicate `vite` entry.
- Dead files: `test-pdf.ts`, `test-pdf2.ts`, duplicate `src/lib/file-utils.test.ts`.
26 changes: 13 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ and consistency — please treat feedback as collaborative.
New issues get `needs-triage` automatically. A maintainer will then apply the
appropriate label(s). Canonical set:

| Label | Meaning |
| --- | --- |
| `bug` | Something isn't working as documented |
| `enhancement` | A feature request or improvement |
| `documentation` | Docs gaps or inaccuracies |
| `good first issue` | Small, scoped, beginner-friendly — great first contribution |
| `help wanted` | Welcome community help; design is agreed |
| `needs-triage` | Awaiting maintainer review |
| `needs-design` | Needs discussion before work can start |
| `security` | Security-relevant (use [SECURITY.md](SECURITY.md) to report!) |
| `frontend` / `backend` | Affected area (auto-applied from changed paths) |
| `dependencies` / `github-actions` | Dependency or CI updates |
| `duplicate` / `wontfix` / `question` | Resolution states |
| Label | Meaning |
| ------------------------------------ | ------------------------------------------------------------- |
| `bug` | Something isn't working as documented |
| `enhancement` | A feature request or improvement |
| `documentation` | Docs gaps or inaccuracies |
| `good first issue` | Small, scoped, beginner-friendly — great first contribution |
| `help wanted` | Welcome community help; design is agreed |
| `needs-triage` | Awaiting maintainer review |
| `needs-design` | Needs discussion before work can start |
| `security` | Security-relevant (use [SECURITY.md](SECURITY.md) to report!) |
| `frontend` / `backend` | Affected area (auto-applied from changed paths) |
| `dependencies` / `github-actions` | Dependency or CI updates |
| `duplicate` / `wontfix` / `question` | Resolution states |

The path-based labels (`frontend`, `backend`, `documentation`, `dependencies`,
`github-actions`) are applied automatically by the **Pull Request Labeler**.
Expand Down
4 changes: 3 additions & 1 deletion api/_lib/__tests__/analyze-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ describe('runAnalysis resilience (per-call timeout + retry)', () => {
});

it('retries a transient (429) error, then succeeds', async () => {
gc.mockImplementationOnce(() => Promise.reject(new Error('429 rate limit'))).mockResolvedValueOnce({
gc.mockImplementationOnce(() =>
Promise.reject(new Error('429 rate limit')),
).mockResolvedValueOnce({
text: JSON.stringify({ ok: true }),
functionCalls: [],
});
Expand Down
3 changes: 1 addition & 2 deletions api/_lib/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ const ALLOWED_MIME_EXACT = new Set([
]);

export const isAllowedMimeType = (mimeType: string): boolean =>
ALLOWED_MIME_EXACT.has(mimeType) ||
ALLOWED_MIME_PREFIXES.some((p) => mimeType.startsWith(p));
ALLOWED_MIME_EXACT.has(mimeType) || ALLOWED_MIME_PREFIXES.some((p) => mimeType.startsWith(p));
16 changes: 9 additions & 7 deletions api/_lib/mcp-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
export const callMcpTool = async (
toolName: string,
args: any,

Check warning on line 14 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

Unexpected any. Specify a different type

Check warning on line 14 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

Unexpected any. Specify a different type
apiMode: boolean,
bureauApiKey: string,
) => {
Expand All @@ -24,8 +24,7 @@
if (toolName === 'search_cases') {
if (!apiKey) {
return {
error:
'eCourts API key not configured. Please set ECOURTS_API_KEY in your environment.',
error: 'eCourts API key not configured. Please set ECOURTS_API_KEY in your environment.',
};
}
return {
Expand Down Expand Up @@ -63,7 +62,7 @@
};
}
return await response.json();
} catch (error) {

Check warning on line 65 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

'error' is defined but never used

Check warning on line 65 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

'error' is defined but never used
return {
error: 'Network error: Failed to reach the Bureau API endpoint. Check your connection.',
};
Expand Down Expand Up @@ -100,7 +99,7 @@
};
}
return await response.json();
} catch (error) {

Check warning on line 102 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (22.x)

'error' is defined but never used

Check warning on line 102 in api/_lib/mcp-tools.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x)

'error' is defined but never used
return {
error: 'Network error: Failed to reach the LTV Calculation API. Check your connection.',
};
Expand All @@ -124,11 +123,14 @@
if (toolName === 'get_mca_info') {
if (apiMode && bureauApiKey) {
try {
const res = await fetch('https://api.mca.gov.in/resource/4dbe5667-7b6b-41d7-82af-211562424d9a', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ companyName: args.companyName }),
});
const res = await fetch(
'https://api.mca.gov.in/resource/4dbe5667-7b6b-41d7-82af-211562424d9a',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ companyName: args.companyName }),
},
);
if (res.ok) return await res.json();

const getRes = await fetch(
Expand Down
3 changes: 1 addition & 2 deletions api/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ export default async function handler(req: Request): Promise<Response> {
console.error(`[/api/analyze:${requestId}]`, e?.stack ?? e);

if (e instanceof AnalysisError) {
const status =
e.code === 'MISSING_API_KEY' || e.code === 'NO_FILES' ? 400 : 500;
const status = e.code === 'MISSING_API_KEY' || e.code === 'NO_FILES' ? 400 : 500;
// `rawLogs` may carry reflected document content / env var names —
// only forward it for client-side-fixable issues; otherwise omit.
const safeRawLogs =
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "vitest run",
"test:watch": "vitest"
"test:watch": "vitest",
"fix": "tsx scripts/automation/self-heal.ts",
"ai:triage": "tsx scripts/automation/ai-triage.ts",
"ai:improve": "tsx scripts/automation/ai-improve.ts",
"ai:pr-review": "tsx scripts/automation/ai-pr-review.ts",
"analyze:repo": "tsx scripts/automation/analyze-repo.ts",
"generate:diagrams": "tsx scripts/automation/generate-diagrams.ts",
"generate:knowledge-graph": "tsx scripts/automation/generate-knowledge-graph.ts"
},
"dependencies": {
"@google/genai": "^1.29.0",
Expand Down Expand Up @@ -77,4 +84,3 @@
"vitest": "^4.1.7"
}
}

17 changes: 17 additions & 0 deletions plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1. **Create `AGENTS.md`**: Add guidelines for AI assistants, enforcing the automation of repetitive tasks, use of `npm run fix` for self-healing, and pre-commit validation using `npm test`, `npm run format`, and `npm run lint`.
2. **Update `package.json`**: Add the required automation scripts (`fix`, `ai:triage`, `ai:improve`, `ai:pr-review`, `analyze:repo`, `generate:diagrams`, `generate:knowledge-graph`) pointing to `tsx scripts/automation/...`.
3. **Implement Automation Scripts in `scripts/automation/`**:
- `self-heal.ts`: Executes `lint:fix`, `format`, etc., using `execFileSync` to prevent command injection and without `console.log`.
- `ai-triage.ts`: Mocks/Implements issue triaging using `@google/genai`.
- `ai-improve.ts`: Mocks/Implements continuous improvement loop.
- `ai-pr-review.ts`: Reads git diff safely (`origin/$BASE_REF...HEAD`), generates a PR review, and saves it to a file.
- `analyze-repo.ts`: Analyzes repo and outputs to `docs/`.
- `generate-diagrams.ts`: Generates architecture diagrams to `docs/`.
- `generate-knowledge-graph.ts`: Generates knowledge graph to `docs/`.
4. **Create GitHub Actions Workflows**:
- `ai-pr-reviewer.yml`: Runs on PRs, assigns `github.base_ref` to `$BASE_REF`, runs `npm run ai:pr-review`, and posts the output using `thollander/actions-comment-pull-request@v3` with kebab-case inputs.
- `ai-issue-triager.yml`: Runs `npm run ai:triage` on issue creation.
- `continuous-improvement.yml`: Runs `npm run ai:improve` on a schedule.
- `autonomous-docs.yml`: Runs doc generation scripts on push to main and opens a PR or commits directly.
5. **Pre-commit and Verify**: Run all verification steps and pre-commit instructions.
6. **Submit**: Submit the changes.
Loading
Loading