Skip to content
Merged
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
19 changes: 18 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ updates:

- package-ecosystem: npm
directories:
- /client
- /server
- /indexer
schedule:
Expand All @@ -34,3 +33,21 @@ updates:
npm-minor-patch:
patterns: ["*"]
update-types: ["minor", "patch"]

# The published client releases on fix commits, so runtime dependency updates
# use fix(deps) and ship; dev dependency updates stay chore(deps-dev).
- package-ecosystem: npm
directory: /client
schedule:
interval: monthly
open-pull-requests-limit: 5
cooldown:
default-days: 7
commit-message:
prefix: fix
prefix-development: chore
include: scope
groups:
npm-minor-patch:
patterns: ["*"]
update-types: ["minor", "patch"]
19 changes: 19 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "node",
"bootstrap-sha": "aa5895cde3b0b68482921aa8df111d4420b022f1",
"packages": {
"client": {
"component": "foc-observer",
"include-v-in-tag": true,
"pull-request-header": "📦 Release Preparation",
"pull-request-footer": "\n\n## 🚀 How to Release\n\n1. **Review** the changelog and version bump in this PR\n2. **Merge this PR** to trigger the release\n3. After merging, the workflow will:\n - Create a GitHub release with tag ${version}\n - Publish to npm automatically\n4. Wait until the workflow is complete before merging another release PR\n\n⚠️ **Note**: The release has NOT been created yet. It will only be created after you merge this PR.",
"changelog-sections": [
{ "type": "feat", "section": "Features", "hidden": false },
{ "type": "fix", "section": "Bug Fixes", "hidden": false },
{ "type": "chore", "section": "Chores", "hidden": false },
{ "type": "docs", "section": "Documentation", "hidden": false }
]
}
}
}
3 changes: 3 additions & 0 deletions .github/release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"client": "1.0.0"
}
216 changes: 216 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
name: release-please

# Releases the @filoz/foc-observer client (client/). release-please counts only
# commits that touch client/ and maintains a release PR; merging it tags
# foc-observer-vX.Y.Z and publishes the tarball to npm through trusted publishing.
# A manual dispatch on an existing release tag republishes a release whose
# publish job failed.

on:
push:
branches:
- master
workflow_dispatch:
inputs:
dry_run:
description: Run npm publish with --dry-run (manual dispatch only)
type: boolean
default: false

concurrency:
group: release-please
cancel-in-progress: false

permissions:
contents: read

jobs:
release-please:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs['client--release_created'] }}
steps:
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
id: release
with:
# PAT so release PRs trigger other workflows (test.yml, add-issues-and-prs-to-fs-project-board).
# This PAT has the permissions outlined in https://github.com/googleapis/release-please-action?tab=readme-ov-file#workflow-permissions.
# Using GITHUB_TOKEN suppresses follow-on workflow runs, so release PRs wouldn't be tested or added to the project board.
token: ${{ secrets.FILOZZY_RELEASE_PLEASE_PAT }}
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json

validate-dispatch:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Validate dispatch ref and release state
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF: ${{ github.ref }}
SHA: ${{ github.sha }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail

case "$REF" in
refs/tags/foc-observer-v[0-9]*.[0-9]*.[0-9]*) ;;
*)
echo "::error::Dispatch ref must be a foc-observer-vX.Y.Z tag, got: $REF"
exit 1
;;
esac
TAG="${REF#refs/tags/}"
VERSION="${TAG#foc-observer-v}"

PKG_NAME="$(node -p "require('./client/package.json').name")"
PKG_VERSION="$(node -p "require('./client/package.json').version")"
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag $TAG does not match client/package.json version $PKG_VERSION"
exit 1
fi

# Confirm the tag commit is on the default branch via GitHub's
# compare API (works regardless of local clone depth).
STATUS="$(gh api "repos/$GITHUB_REPOSITORY/compare/$DEFAULT_BRANCH...$SHA" --jq .status)"
case "$STATUS" in
identical|behind) ;;
*)
echo "::error::Tag commit $SHA is not an ancestor of $DEFAULT_BRANCH (compare status: $STATUS)"
exit 1
;;
esac

if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "::error::GitHub release $TAG not found"
exit 1
fi

PUBLISHED="$(npm view "$PKG_NAME@$VERSION" version 2>/dev/null || true)"
if [ -n "$PUBLISHED" ]; then
echo "::error::npm already has $PKG_NAME@$PUBLISHED"
exit 1
fi

build:
needs: [release-please, validate-dispatch]
if: |
always() && (
needs.release-please.outputs.release_created == 'true' ||
needs.validate-dispatch.result == 'success'
)
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 20
defaults:
run:
working-directory: client
outputs:
tarball: ${{ steps.pack.outputs.tarball }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 'lts/*'
check-latest: true
registry-url: 'https://registry.npmjs.org'

# Pin npm to a known-good major to avoid @latest drift on a publish-path runner.
- name: Pin npm
run: npm install -g npm@11

- name: Install dependencies
run: npm ci --no-audit --no-fund

- name: Build
run: npm run build

- name: Test
run: npm test

- name: Pack tarball
id: pack
run: |
set -euo pipefail
TARBALL="$(npm pack --silent)"
test -n "$TARBALL"
test -f "$TARBALL"
echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: npm-tarball
path: client/${{ steps.pack.outputs.tarball }}
retention-days: 7
if-no-files-found: error

publish:
needs: build
# build needs both release-please and validate-dispatch, and exactly one of
# those is skipped on every trigger (release-please on dispatch, validate-dispatch
# on push). That skip propagates down the needs chain, so publish must override
# with always() the same way build does, then gate on build actually succeeding.
if: ${{ always() && needs.build.result == 'success' }}
runs-on: ubuntu-latest
permissions:
id-token: write # OIDC for npm trusted publishing
contents: read
timeout-minutes: 20
steps:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 'lts/*'
check-latest: true
registry-url: 'https://registry.npmjs.org'

- name: Pin npm
run: npm install -g npm@11

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: npm-tarball
path: artifact

- name: Publish tarball to npm
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
TARBALL_NAME: ${{ needs.build.outputs.tarball }}
run: |
set -euo pipefail

# Assert exactly one tarball was delivered and it matches the
# filename emitted by the build job.
COUNT="$(find artifact -maxdepth 1 -name '*.tgz' | wc -l | tr -d ' ')"
if [ "$COUNT" != "1" ]; then
echo "::error::Expected exactly one tarball in artifact/, found $COUNT"
exit 1
fi
# Absolute path: npm treats a bare "dir/file.tgz" arg as a GitHub
# owner/repo shorthand and tries to git-clone it. A leading "/" forces
# it to resolve as a local tarball file.
TARBALL="$PWD/artifact/$TARBALL_NAME"
if [ ! -f "$TARBALL" ]; then
echo "::error::Tarball $TARBALL not found"
exit 1
fi

if [ "$DRY_RUN" = "true" ]; then
npm publish --access public --dry-run "$TARBALL"
else
npm publish --access public "$TARBALL"
fi
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Iterate with the smallest relevant test, and report the checks you didn't run.

Follow the [single-network reindex runbook](REINDEX.md) for preflight, checkpoints, cutover, API verification and rollback. The [example override](compose.reindex.example.yaml) runs the candidate image without the live checkout's bind mounts.

### Client releases

`@filoz/foc-observer` releases through release-please (`.github/release-please-config.json`, `.github/workflows/release-please.yml`). Only commits that touch `client/` count: `feat` bumps the minor version, `fix` the patch, and other types appear in the changelog without releasing, so give client changes an accurate type. Merging the release PR tags `foc-observer-vX.Y.Z` and publishes through npm trusted publishing. Release-please owns the version in `client/package.json` and `client/CHANGELOG.md`; don't edit them by hand. Dispatching the workflow on a release tag republishes a release whose publish job failed.

## Logging

`logger.ts` writes JSON lines to stdout. Compose rotates the server logs. `mcp` records tool, duration and result size. Successful `sql` entries include up to 2,000 query characters and UTF-8 sizes for the compact SQL result (`resultBytes`) and its largest row (`maxRowBytes`). Limit failures record `limitHit`; failed queries omit SQL text. `rest` records method, route pattern and status. `backend` records sanitized diagnostics. Under backpressure the logger drops entries rather than buffering them.
Expand Down
8 changes: 6 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/FilOzone/foc-observer.git"
"url": "git+https://github.com/FilOzone/foc-observer.git",
"directory": "client"
},
"bugs": {
"url": "https://github.com/FilOzone/foc-observer/issues"
Expand All @@ -39,5 +40,8 @@
"@types/node": "^26.0.1",
"typescript": "^7.0.2",
"vitest": "^5.0.5"
}
},
"files": [
"dist"
]
}
3 changes: 2 additions & 1 deletion client/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { callTool, callToolAndClose, configureMcpUrl, createMcpClient } from "./
import { serveProxy } from "./mcp-proxy.js"
import { escapeTerminalText, formatTerminalValue, stringifyTerminalSafeJson } from "./terminal.js"
import { listProviderPages, type ProviderPageResult } from "./provider-pages.js"
import { VERSION } from "./version.js"

type NetworkName = "calibnet" | "mainnet"

Expand All @@ -45,7 +46,7 @@ const AFFIRM = { i_have_read_the_system_context: true }
program
.name("foc-observer")
.description("FOC observability - MCP server and CLI for querying Filecoin Onchain Cloud data")
.version("0.0.1")
.version(VERSION)
.option("--api-url <url>", "foc-observer server URL (overrides FOC_API_URL env var)")

// Configure MCP URL from global --api-url option before any command runs
Expand Down
3 changes: 2 additions & 1 deletion client/src/mcp-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { VERSION } from "./version.js"

let configuredMcpUrl: string | undefined

Expand All @@ -26,7 +27,7 @@ export async function createMcpClient(mcpUrl?: string): Promise<Client> {
if (!url) throw new Error("FOC_API_URL environment variable is required")

const transport = new StreamableHTTPClientTransport(new URL(url))
const client = new Client({ name: "foc-observer-cli", version: "0.0.1" })
const client = new Client({ name: "foc-observer-cli", version: VERSION })
await client.connect(transport)
return client
}
Expand Down
5 changes: 3 additions & 2 deletions client/src/mcp-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js"
import { VERSION } from "./version.js"

export async function serveProxy(mcpUrl: string): Promise<void> {
const remoteTransport = new StreamableHTTPClientTransport(new URL(mcpUrl))
const remoteClient = new Client({ name: "foc-observer-proxy", version: "0.0.1" })
const remoteClient = new Client({ name: "foc-observer-proxy", version: VERSION })
await remoteClient.connect(remoteTransport)

// Forward the remote JSON schemas verbatim, including optional parameters and enums.
const localServer = new Server({ name: "foc-observer", version: "0.0.1" }, {
const localServer = new Server({ name: "foc-observer", version: VERSION }, {
capabilities: { tools: {} },
instructions: remoteClient.getInstructions(),
})
Expand Down
4 changes: 4 additions & 0 deletions client/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createRequire } from "node:module"

/** The published package version, read from package.json so a release changes no source. */
export const VERSION: string = createRequire(import.meta.url)("../package.json").version