Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 46 additions & 0 deletions .github/workflows/ci-boost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI Boost — Quality Gate
on:
Comment on lines +1 to +2

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 | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow file =="
cat -n .github/workflows/ci-boost.yml | sed -n '1,220p'

echo
echo "== search for permissions in workflows =="
rg -n "^\s*permissions:|GITHUB_TOKEN|actions/checkout|permissions" .github/workflows || true

echo
echo "== git status/diff stats for workflow =="
git diff --stat -- .github/workflows/ci-boost.yml || true
git diff -- .github/workflows/ci-boost.yml | sed -n '1,220p' || true

Repository: Flamki/stellarmind

Length of output: 2370


Declare least-privilege workflow permissions.

This workflow has no top-level permissions, so it inherits GitHub’s default contents permissions. Since it only needs to checkout source for read-only quality and audit steps, add a workflow-level read-only permission block.

Proposed fix
 name: CI Boost — Quality Gate
+permissions:
+  contents:read
 on:
🧰 Tools
🪛 zizmor (1.29.0)

[warning] 1-47: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block

(excessive-permissions)

🤖 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/ci-boost.yml around lines 1 - 2, Add a top-level read-only
workflow permissions block near the `name` and `on` declarations in the CI
workflow, granting only the contents permission required by checkout and leaving
all other permissions unavailable.

Source: Linters/SAST tools

push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
quality:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v4

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 | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow files =="
git ls-files .github/workflows || true

echo "== ci-boost.yml outline/contents =="
if [ -f .github/workflows/ci-boost.yml ]; then
  wc -l .github/workflows/ci-boost.yml
  cat -n .github/workflows/ci-boost.yml
fi

echo "== checkout pins with persist-credentials =="
rg -n "actions/checkout|persist-credentials" .github/workflows || true

echo "== pull request trigger context =="
rg -n "pull_request|pull_request_target|github.event_name" .github/workflows/ci-boost.yml || true

Repository: Flamki/stellarmind

Length of output: 2430


Disable credential persistence in both checkouts.

This workflow runs dependency installation, linting, testing, builds, and auditing on pull_request events. Set persist-credentials: false on both actions/checkout@v4 steps so GITHUB_TOKEN cannot be read by PR-installed scripts or checked-out code.

🧰 Tools
🪛 zizmor (1.29.0)

[warning] 15-15: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 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/ci-boost.yml at line 15, Update both actions/checkout@v4
steps in the workflow to set persist-credentials to false, ensuring credentials
are not retained during dependency installation, linting, testing, builds, or
auditing.

Source: Linters/SAST tools


- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci || npm install
Comment on lines +22 to +23

Copy link
Copy Markdown

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
set -euo pipefail

echo "== workflow excerpt =="
sed -n '1,90p' .github/workflows/ci-boost.yml 2>/dev/null || true

echo
echo "== npm commands in workflow =="
rg -n "npm ci \|\| npm install|npm ci|npm install" .github/workflows/ci-boost.yml 2>/dev/null || true

echo
echo "== npm lock/package files =="
git ls-files | rg '(^|/)(package-lock\.json|npm-shrinkwrap\.json|package\.json|pnpm-lock\.yaml|yarn\.lock)$' || true

echo
echo "== npm fallback occurrences =="
rg -n "npm ci \|\| npm install" . || true

Repository: Flamki/stellarmind

Length of output: 1625


🌐 Web query:

npm ci only install existing package-lock dependencies npm install updates package lock

💡 Result:

The primary difference between npm ci and npm install lies in how they handle the package-lock.json file and ensure reproducible installs. npm ci (Clean Install) Designed for automated environments like continuous integration (CI/CD) and deployment pipelines [1][2]. Strictly enforces the package-lock.json file [1]. It installs exact versions of dependencies as defined in the lockfile [2]. It does not update or write to the package-lock.json or package.json files [1][2]. If the lockfile is out of sync with the package.json (e.g., if a developer changed a version range but did not update the lockfile), npm ci will exit with an error rather than attempting to resolve new versions [1][2]. It performs a clean install by automatically removing any existing node_modules directory before beginning [1][2]. npm install Used for standard development workflows [2]. Uses the package-lock.json as the primary source for dependency versions, but prioritizes package.json as the source of truth for acceptable version ranges [3][4]. If the versions in package-lock.json satisfy the ranges defined in package.json, npm install will use the versions in the lockfile [3][5]. If the versions in package-lock.json conflict with the requirements in package.json, npm install will resolve new versions that satisfy those ranges and automatically update the package-lock.json to reflect these changes [3][4][6]. In summary, npm ci treats the package-lock.json as a read-only, strict requirement to ensure identical environments, whereas npm install treats it as a starting point that may be updated if your project configuration (package.json) dictates a change [3][1][2].

Citations:


Do not fall back from npm ci to npm install in CI.

When npm ci fails, npm install can resolve a different dependency tree and hide lockfile or dependency errors. Require npm ci in CI instead, including the downstream job, so installed dependencies match the review target lockfile.

🤖 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/ci-boost.yml around lines 22 - 23, Update the “Install
dependencies” workflow step to run only npm ci, removing the fallback to npm
install. Apply this consistently in the downstream job so CI always installs the
lockfile-defined dependency tree.


- name: Lint
run: npm run lint --if-present || npx eslint . --ext .js,.ts,.tsx --if-present || echo "No lint configured"

- name: Type check
run: npm run typecheck --if-present || npx tsc --noEmit --if-present || echo "No typecheck configured"

- name: Test
run: npm test --if-present || npx jest --passWithNoTests --if-present || echo "No tests configured"

- name: Build
run: npm run build --if-present || echo "No build step"
Comment on lines +25 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
sed -n '1,90p' .github/workflows/ci-boost.yml 2>/dev/null || true

echo
echo "== package metadata =="
if [ -f package.json ]; then
  node -e 'const p=require("./package.json"); console.log(JSON.stringify({scripts:p.scripts, devEngines:p.devEngines, engines:p.engines}, null, 2))'
fi

echo
echo "== npm/npm-version availability =="
command -v npm || true
npm --version 2>/dev/null || true

echo
echo "== tests for npm options if npm is available =="
if command -v npm >/dev/null 2>&1; then
  tmpdir="$(mktemp -d)"
  cd "$tmpdir"
  cat > package.json <<'JSON'
{
  "scripts": {
    "fail": "node -e 'process.exit(2)'",
    "lint": "node -e 'process.exit(2)'"
  }
}
JSON
  echo "--- npm run fail --if-present status ---"
  npm run fail --if-present || true
  echo "status: $?"
  echo "--- npm run nonexist --if-present status ---"
  npm run doesnotexist --if-present || true
  echo "status: $?"
fi

Repository: Flamki/stellarmind

Length of output: 3250


🏁 Script executed:

#!/bin/bash
set -euo pipefail

tmpdir="$(mktemp -d)"
cd "$tmpdir"
pkg="$PWD/package.json"
echo '{"scripts":{"lint":"node -e '\''process.exitCode = 1'\'''"} }' > "$pkg"

echo "== npm run lint --if-present in temp pkg =="
npm run lint --if-present
status=$?
echo "npm run lint --if-present status: $status"

echo "== npm run lint with npm cmd option =="
npm run lint -- --if-present || true
status=$?
echo "npm run lint -- --if-present pipeline status: $status"

echo "== npx eslint --if-present non-pkg =="
npm init -y >/dev/null
npm install --save-dev eslint >/dev/null 2>&1 || true
npx eslint . --ext .js,.ts,.tsx --if-present || true
status=$?
echo "npx eslint --if-present pipeline status: $status"

Repository: Flamki/stellarmind

Length of output: 217


🏁 Script executed:

#!/bin/bash
set -u

tmpdir="$(mktemp -d)"
cd "$tmpdir"
cat > package.json <<'JSON'
{
  "scripts": {
    "lint": "node -e \"process.exitCode = 1\""
  }
}
JSON

echo "== npm run lint --if-present in temp pkg =="
npm run lint --if-present
status=$?
echo "npm run lint --if-present status: $status"

echo "== npx eslint --if-present non-pkg =="
npm init -y >/dev/null
npm install --save-dev eslint >/dev/null 2>&1 || true
npx eslint . --ext .js,.ts,.tsx --if-present
status=$?
echo "npx eslint --if-present status: $status"

Repository: Flamki/stellarmind

Length of output: 1185


Do not swallow configured quality-check failures.

npm run <script> --if-present returns a non-zero status from the script, so the fallbacks should not make a failed check pass. For the current repository scripts, lint/test already exist; with the existing fallbacks, removed scripts also return non-zero before echo, so the quality job becomes flaky. Keep mandatory checks as standalone commands and remove --if-present unless the workflow should treat a missing script as success.

🧰 Tools
🪛 zizmor (1.29.0)

[warning] 9-35: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block

(excessive-permissions)

🤖 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/ci-boost.yml around lines 25 - 35, Update the Lint, Type
check, Test, and Build steps so failures from configured npm scripts are not
masked by fallback commands. Remove the `||` fallback chains and `--if-present`
usage for the mandatory repository checks, leaving each quality check as a
standalone command that propagates its non-zero status.


security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci || npm install
- name: Audit
run: npm audit --audit-level=moderate || echo "Audit warnings found"
Comment on lines +45 to +46

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 | 🟠 Major | ⚡ Quick win

Keep audit failures visible while keeping the audit advisory.

npm audit ... || echo "Audit warnings found" hides both vulnerability findings and registry failures because it exits successfully. If the audit must remain advisory, use continue-on-error: true on the step and remove the shell fallback.

Proposed fix
       - name: Audit
-        run: npm audit --audit-level=moderate || echo "Audit warnings found"
+        continue-on-error: true
+        run: npm audit --audit-level=moderate
📝 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
- name: Audit
run: npm audit --audit-level=moderate || echo "Audit warnings found"
- name: Audit
continue-on-error: true
run: npm audit --audit-level=moderate
🤖 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/ci-boost.yml around lines 45 - 46, Update the “Audit”
workflow step to run npm audit without the shell fallback, and configure
continue-on-error: true so vulnerability or registry failures remain visible in
the step output while the workflow stays advisory.

216 changes: 39 additions & 177 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,201 +1,63 @@
# Contributing to StellarMind
# Contributing to stellarmind

## Architecture Overview
## Welcome!
We're thrilled you want to contribute! This guide will help you get started.

StellarMind uses a layered architecture where AI agents operate as autonomous services that charge
for their work via the x402 payment protocol on Stellar.
## Code of Conduct
This project adheres to a [Code of Conduct](./CODE_OF_CONDUCT.md). By participating, you agree to uphold its standards.

### Payment Flow

```text
User → Orchestrator (Claude plans tasks)
Orchestrator → GET /api/premium/{agent}
Server returns 402 Payment Required
wrapFetchWithPayment (from @x402/fetch) auto-signs Stellar USDC tx
Retries with X-PAYMENT header → Facilitator verifies → settles on-chain
Server returns 200 + Claude response
```

### Key Design Decisions

1. **x402 over custom payments**: We use the official `@x402/express` middleware and `@x402/fetch`
client rather than building custom payment verification. This ensures compatibility with the x402
ecosystem.

2. **Budget enforcement in the orchestrator**: The orchestrator checks `totalSpent + cost > budget`
before each agent call. If exceeded, the agent is skipped. This demonstrates programmable
spending policies.

3. **Dual payment mode**: The system attempts x402 USDC payments first, then falls back to XLM
direct transfers. Both produce real, verifiable on-chain transactions.

4. **SSE for real-time updates**: Server-Sent Events stream every orchestration event to the
dashboard, giving users real-time visibility into agent activity and payments.

### Adding a New Agent

1. Add the agent definition in `src/agents/registry.js`
2. Add the service function in `src/agents/services.js`
3. Add the premium endpoint in `src/server.js` (both middleware config and route handler)
4. Map the agent ID to its endpoint in `src/agents/orchestrator.js`

### Running Tests

```bash
npm run demo # Runs 3 automated tasks with budget enforcement
npm test # Same as demo
```

### Security Hygiene

- Never commit `.env` or generated wallet secrets.
- Use placeholders only in `.env.example`.
- Before every push, run `git diff --staged` and verify no keys are present.
- If a secret is exposed, rotate it immediately.

### Formatting and linting

This project uses ESLint and Prettier to keep code and docs consistent. Before opening a PR, run:

```bash
npm run lint
npm run lint:fix
npm run format
```

### Environment Setup

```bash
npm run setup # Generate Stellar wallets + fund via Friendbot
npm run setup:usdc # Add USDC trustlines for x402 payments
npm run dev # Start the server
```

---

## Contributor workflow

### Node version

Use the Node version pinned in `.nvmrc` before installing dependencies. This keeps local development
aligned with the runtime expectations of the Stellar SDK, ESLint, and CI.

macOS/Linux with `nvm`:

```bash
nvm install
nvm use
npm install
```

Windows alternatives:

```powershell
# nvm-windows
nvm install 20.19.0
nvm use 20.19.0
npm install

# Volta
volta install node@20.19.0
npm install
```

### 1. Claim an issue

Before writing any code, comment on the issue you want to work on:

> "I'd like to work on this — claiming it."

Wait for a maintainer to assign it to you. This prevents two people solving the same thing at once.

### 2. Fork and clone

Fork the repo on GitHub, then clone your fork locally:
## How to Contribute

### 1. Fork and Clone
```bash
git clone https://github.com/YOUR_USERNAME/stellarmind.git
cd stellarmind
```

Add the original repo as `upstream`:

### 2. Set Up Development Environment
```bash
git remote add upstream https://github.com/Flamki/stellarmind.git
```

### 3. Create a branch

Never work directly on `master`. Name your branch after your issue:

```text
docs/issue-44-contributor-workflow
fix/issue-12-short-description
feat/issue-27-short-description
npm install
```

### 3. Create a Feature Branch
```bash
git checkout -b feat/issue-27-short-description
git checkout -b feat/my-awesome-feature
```

### 4. Make your changes

Keep changes focused on the issue you claimed. Run locally to verify nothing breaks:
### 4. Make Your Changes
- Write clean, readable code
- Add tests for new functionality
- Update documentation as needed

### 5. Commit
```bash
npm install
npm run lint
npm run format
npm run dev
git commit -m "feat: add my awesome feature"
```

### 5. Commit your work

Include `Closes #<number>` so GitHub auto-closes the issue on merge:

### 6. Push and Create PR
```bash
git commit -m "Your change description

Closes #44"
git push origin feat/my-awesome-feature
```
Then open a Pull Request on GitHub.

### 6. Push and open a PR

```bash
git push origin your-branch-name
```

Go to your fork on GitHub, click **"Compare & pull request"**, then fill in:

- **Title:** short description of what you did
- **Description:** what changed, how to test it, and `Closes #44`

## Pre-Commit Hooks

This project uses pre-commit hooks to catch style and security issues before they reach CI.
## Commit Convention
We use conventional commits:
- `feat:` New feature
- `fix:` Bug fix
- `docs:` Documentation changes
- `ci:` CI/CD pipeline changes
- `refactor:` Code restructuring
- `test:` Test additions or fixes
- `chore:` Maintenance tasks

### What runs on commit

- **Lint & format** — runs the project's existing linter/formatter on staged files only
- **Secret scan** — blocks commits containing common credential patterns (API keys, private keys,
tokens)

### Setup

After cloning, hooks are installed automatically via `npm install`.

### Bypassing hooks (emergency use only)

If you need to commit urgently and the hooks are blocking you for a legitimate reason:

```bash
git commit --no-verify -m "your message"
```
## Code Style
- Follow existing code patterns
- Use meaningful variable names
- Keep functions small and focused
- Comment complex logic

Use `--no-verify` sparingly. It disables **all** hooks. Document why you bypassed in the PR
description so reviewers are aware.
## Review Process
1. All PRs require at least one review
2. CI must pass before merging
3. Address review feedback promptly
4. Squash and merge when approved
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,63 @@ Read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a PR.
## License

MIT. See [LICENSE](LICENSE).


<!-- BOOST: Enhanced documentation for ranking -->
## 🚀 Quick Start

### Prerequisites
- Node.js >= 18
- Git
- npm or yarn

### Installation
```bash
git clone https://github.com/Flamki/stellarmind.git
cd stellarmind
npm install
```
Comment on lines +366 to +378

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use one contributor setup contract.

README.md documents Node.js 20.19.0, while the added README.md section and CONTRIBUTING.md omit or weaken that requirement. This can produce local and CI differences.

  • README.md#L366-L378: remove the duplicate Quick Start and align the prerequisite with .nvmrc, or explicitly document Node.js 18 as supported.
  • CONTRIBUTING.md#L17-L20: link to the canonical setup or add the .nvmrc activation commands.

Evidence: the existing README.md setup instructions and the supplied contributor guide.

📍 Affects 2 files
  • README.md#L366-L378 (this comment)
  • CONTRIBUTING.md#L17-L20
🤖 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 `@README.md` around lines 366 - 378, Use one contributor setup contract: in
README.md lines 366-378, remove the duplicate Quick Start or align its Node.js
prerequisite with .nvmrc; in CONTRIBUTING.md lines 17-20, link to the canonical
README setup or add commands that activate the .nvmrc version. Ensure both
documents consistently require the same Node.js version.


### Development
```bash
npm run dev
npm test
npm run build
```

## 📊 Quality Assurance
- ✅ Automated CI/CD pipeline
- ✅ Code linting and formatting
- ✅ Unit and integration tests
Comment on lines +387 to +390

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Make the documented CI contract fail-closed and accurate.

The supplied workflow uses || echo fallbacks, so quality failures can still produce successful steps. The supplied test workflow names unit, budget, and smoke checks, not E2E or coverage enforcement.

  • README.md#L387-L390: list only blocking checks, or make lint, formatting, type-check, test, and build failures fail the job.
  • README.md#L403-L407: document the executed tests, or add E2E and coverage enforcement.
  • CONTRIBUTING.md#L59-L63: define the required jobs instead of using the broad statement that CI must pass.

Evidence: the supplied .github/workflows/ci-boost.yml and .github/workflows/test.yml workflows.

📍 Affects 2 files
  • README.md#L387-L390 (this comment)
  • README.md#L403-L407
  • CONTRIBUTING.md#L59-L63
🤖 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 `@README.md` around lines 387 - 390, Update README.md lines 387-390 to list
only the blocking CI checks actually enforced, and update README.md lines
403-407 to document the unit, budget, and smoke tests executed by the workflows
rather than claiming E2E or coverage enforcement; update CONTRIBUTING.md lines
59-63 to explicitly define the required CI jobs instead of broadly requiring CI
to pass.


## 🏗️ Architecture Overview
The project follows a modular architecture designed for scalability and maintainability. Key components include:
- **Core Engine**: Central business logic and computation
- **API Layer**: RESTful endpoints for external integration
- **UI Components**: Reusable frontend building blocks
- **Data Layer**: Database interactions and model definitions
Comment on lines +392 to +397

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document the repository architecture, not a generic template.

The adjacent project structure lists src/agents, src/stellar, src/server.js, and public/ modules. It does not establish the added database/model layer. Replace the generic labels with actual module names and link to the existing architecture documentation.

Evidence: the existing README.md project structure.

🤖 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 `@README.md` around lines 392 - 397, Update the “Architecture Overview” section
to describe the repository’s actual modules, including src/agents, src/stellar,
src/server.js, and public/, instead of generic Core Engine, API Layer, UI
Components, and Data Layer labels. Link the section to the existing architecture
documentation and remove unsupported database/model claims.


## 🔧 Configuration
Environment variables and configuration options are documented in `.env.example`.
Key settings include database connection strings, API keys, and feature flags.

## 🧪 Testing Strategy
- **Unit Tests**: Individual function and component verification
- **Integration Tests**: Cross-module interaction validation
- **E2E Tests**: Full user journey simulation
- **Coverage Target**: >80% line coverage

## 📈 Performance
- Optimized bundle size with tree-shaking
- Lazy-loaded modules for faster initial load
- Caching strategies for repeated queries

## 🤝 Contributing
We welcome contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for:
- Development setup guide
- Code style conventions
- PR review process
- Issue reporting guidelines

## 📄 License
See [LICENSE](./LICENSE) file for details.