Skip to content

Commit 56f3857

Browse files
committed
chore: initial commit
1 parent b1e0415 commit 56f3857

21 files changed

+8077
-2
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 10
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
16+
- name: Setup Node
17+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
18+
with:
19+
cache: 'npm'
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Build
25+
run: npm run build

.github/workflows/deploy-npm.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
strategy:
13+
matrix:
14+
node-version: ['24', '22', '20']
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run unit tests
29+
run: npm test
30+
31+
publish:
32+
needs: test
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read
36+
id-token: write
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
40+
41+
- name: Setup Node
42+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
43+
with:
44+
node-version: 24
45+
registry-url: 'https://registry.npmjs.org'
46+
cache: 'npm'
47+
48+
- name: Install dependencies
49+
run: npm ci
50+
51+
- name: Build
52+
run: npm run build
53+
54+
- name: Publish to npm
55+
run: npm publish --provenance --access public
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
strategy:
14+
matrix:
15+
node-version: ['24', '22', '20']
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Run unit tests
30+
run: npm test

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# system related
2+
.DS_Store
3+
.vscode
4+
.idea
5+
local
6+
7+
#test related
8+
coverage
9+
10+
# App related
11+
.env
12+
node_modules/*
13+
dist
14+
docs

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/dist/*
2+
package-lock.json

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"tabWidth": 4,
7+
"bracketSpacing": true,
8+
"arrowParens": "avoid",
9+
"useTabs": false
10+
}

AGENTS.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Make CLI - AI Agents Guide
2+
3+
## Overview
4+
5+
This document provides instructions for AI agents on how to work with and extend the Make CLI repository. The CLI is a standalone command-line tool that interacts with the Make automation platform. It depends on `@makehq/sdk` for all API access, types, and MCP tool definitions.
6+
7+
## Repository Structure
8+
9+
```
10+
make-cli/
11+
├── src/
12+
│ ├── cli.ts # Executable entry point: sets up Commander, registers all commands
13+
│ ├── commands.ts # Builds CLI commands from @makehq/sdk MCP tool definitions
14+
│ ├── auth.ts # Resolves API key and zone from flags or env vars
15+
│ ├── output.ts # Output formatting: json, compact, table
16+
│ ├── categories.ts # Display titles and groupings for command categories
17+
│ └── version.ts # Auto-generated version constant (from scripts/build-version.mjs)
18+
├── test/
19+
│ └── commands.spec.ts # Unit tests for CLI utilities and command building
20+
├── scripts/
21+
│ └── build-version.mjs # Writes src/version.ts from package.json version
22+
└── dist/ # Compiled output (auto-generated)
23+
└── cli.js # The executable CLI (ESM with shebang)
24+
```
25+
26+
## Dependency on `@makehq/sdk`
27+
28+
All API functionality comes from the `@makehq/sdk` package. The CLI imports:
29+
30+
| Import | Source | Purpose |
31+
| -------------- | ----------------- | ------------------------------------------------ |
32+
| `Make` | `@makehq/sdk` | API client — instantiated per command invocation |
33+
| `MakeError` | `@makehq/sdk` | Typed API error with `statusCode` and `message` |
34+
| `JSONValue` | `@makehq/sdk` | Generic JSON value type |
35+
| `MakeMCPTools` | `@makehq/sdk/mcp` | Array of all MCP tool definitions |
36+
| `MakeMCPTool` | `@makehq/sdk/mcp` | Type describing a single MCP tool |
37+
| `JSONSchema` | `@makehq/sdk/mcp` | JSON Schema type for tool input parameters |
38+
39+
## How the CLI Works
40+
41+
The CLI uses an **auto-discovery pattern**: it reads the `MakeMCPTools` array from `@makehq/sdk/mcp` and dynamically registers each tool as a CLI subcommand. No command wiring is done by hand.
42+
43+
### Command registration flow
44+
45+
1. `src/index.ts` creates a Commander program with global flags (`--api-key`, `--zone`, `--output`)
46+
2. It calls `buildCommands(program, MakeMCPTools)` from `src/commands.ts`
47+
3. `buildCommands` groups tools by `tool.category` and creates nested subcommands:
48+
- Category → top-level command (e.g. `scenarios`, `data-stores`, `sdk-apps`)
49+
- Tool action → subcommand (e.g. `list`, `get`, `create`)
50+
4. Each subcommand's options are derived from `tool.inputSchema.properties`
51+
5. On execution, the tool's `execute(make, args)` function is called
52+
53+
### Tool name → CLI command mapping
54+
55+
Tool names follow `{category}_{action}` where category dots become hyphens:
56+
57+
```
58+
scenarios_list → make scenarios list
59+
data-stores_get → make data-stores get
60+
sdk-apps_get-section → make sdk-apps get-section
61+
```
62+
63+
### Auth resolution
64+
65+
Every command resolves credentials via `resolveAuth()` in `src/auth.ts`:
66+
67+
- Checks `--api-key` / `--zone` flags first
68+
- Falls back to `MAKE_API_KEY` / `MAKE_ZONE` environment variables
69+
- Throws if either is missing
70+
71+
### Output formatting
72+
73+
Controlled by the global `--output` flag (default: `json`):
74+
75+
- `json` — pretty-printed JSON
76+
- `compact` — single-line JSON
77+
- `table` — ASCII table (for arrays of objects)
78+
79+
## Adding New Commands
80+
81+
New CLI commands come automatically from new MCP tools added in `@makehq/sdk`. To add a command:
82+
83+
1. Add or update a `.mcp.ts` file in the `@makehq/sdk` repository following its conventions
84+
2. Bump and publish a new version of `@makehq/sdk`
85+
3. Update `@makehq/sdk` version in this repo's `package.json` and run `npm install`
86+
4. No code changes needed in this repo — the new tool is auto-discovered
87+
88+
To customize how a **category** is displayed (title, help group), update `src/categories.ts`.
89+
90+
## Testing Patterns
91+
92+
### Unit Tests (`test/commands.spec.ts`)
93+
94+
Tests cover the helper functions and command-building logic using mock tool definitions:
95+
96+
```typescript
97+
import { describe, expect, it } from '@jest/globals';
98+
import { Command } from 'commander';
99+
import { deriveActionName, camelToKebab, coerceValue, buildCommands } from '../src/commands.js';
100+
import { resolveAuth } from '../src/auth.js';
101+
import { formatOutput } from '../src/output.js';
102+
import type { MakeMCPTool } from '@makehq/sdk/mcp';
103+
104+
const makeTool = (overrides: Partial<MakeMCPTool> = {}): MakeMCPTool => ({
105+
name: 'scenarios_list',
106+
title: 'List scenarios',
107+
description: 'List all scenarios',
108+
category: 'scenarios',
109+
inputSchema: { type: 'object', properties: {}, required: [] },
110+
execute: async () => [],
111+
...overrides,
112+
});
113+
```
114+
115+
Tests do **not** mock HTTP requests — they only test pure CLI logic (argument parsing, type coercion, output formatting, command structure).
116+
117+
## Build and Development
118+
119+
### Scripts
120+
121+
- `npm run build` — compile `src/index.ts` to `dist/index.js` (ESM with shebang)
122+
- `npm run build:version` — write current package.json version to `src/version.ts`
123+
- `npm test` — run unit tests in `test/`
124+
- `npm run lint` — TypeScript type-check + ESLint
125+
- `npm run format` — format with Prettier
126+
127+
### Output
128+
129+
The build produces a single file: `dist/index.js` — an ESM executable with `#!/usr/bin/env node`.
130+
131+
## TypeScript Guidelines
132+
133+
- Use `type` imports for type-only imports
134+
- All imports from `@makehq/sdk` and `@makehq/sdk/mcp` use the package name (never relative paths into node_modules)
135+
- Use `.js` extensions in relative imports (e.g. `import { run } from './index.js'`)
136+
137+
## Quality Checklist
138+
139+
Before completing any change:
140+
141+
- [ ] `npm run lint` passes (TypeScript + ESLint)
142+
- [ ] `npm test` passes
143+
- [ ] `npm run build` succeeds and produces `dist/index.js`
144+
- [ ] `node dist/index.js --help` shows expected commands

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Read and follow @AGENTS.md

0 commit comments

Comments
 (0)