@kraftapps-ai/kai 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CLAUDE.md +39 -0
  2. package/kai +164 -33
  3. package/package.json +1 -1
package/CLAUDE.md ADDED
@@ -0,0 +1,39 @@
1
+ # Kai
2
+
3
+ Autonomous AI Shopify expert, product manager, and developer loop for Claude Code. Published as `@kraftapps-ai/kai` on npm.
4
+
5
+ ## Structure
6
+
7
+ - `kai` — the entire tool; a single bash script that bootstraps the PM agent and dev loop
8
+ - `package.json` — npm metadata and version
9
+ - `.kai/PROMPT.md` — per-project context (generated at runtime, not in repo)
10
+ - `.kai/loop.sh` — dev loop script (generated at runtime, not in repo)
11
+
12
+ ## How it works
13
+
14
+ 1. `kai` script auto-inits project files (`kai.json`, `kai-progress.txt`, `.kai/PROMPT.md`)
15
+ 2. Auto-installs MCP servers if not already configured:
16
+ - **Playwright** — browser testing inside Shopify Admin
17
+ - **@shopify/dev-mcp** — Shopify docs, GraphQL schema introspection, Liquid/GraphQL/component validation
18
+ 3. Generates `.kai/loop.sh` (the autonomous dev loop)
19
+ 4. Launches Claude as a Shopify-expert PM agent
20
+
21
+ The PM creates user stories in `kai.json`, then kicks off `.kai/loop.sh` which runs Claude in a loop — one story per iteration with self-review. Both the PM and the dev loop worker use Shopify Dev MCP tools to introspect APIs, search docs, and validate code.
22
+
23
+ ## MCP servers
24
+
25
+ - `@shopify/dev-mcp` — Official Shopify Dev MCP. Provides: `learn_shopify_api`, `search_docs_chunks`, `fetch_full_docs`, `introspect_graphql_schema`, `validate_graphql_codeblocks`, `validate_component_codeblocks`, `validate_theme_codeblocks`, `validate_theme`. No auth required.
26
+ - `@playwright/mcp` — Browser automation for testing embedded apps in Shopify Admin.
27
+ - Shopify Storefront MCP (remote, per-store) — `https://{shop}.myshopify.com/api/mcp`. Product search, cart management. No auth.
28
+
29
+ ## Publishing
30
+
31
+ ```bash
32
+ npm publish --access public
33
+ ```
34
+
35
+ Version lives in `package.json` only.
36
+
37
+ ## Testing changes
38
+
39
+ Run `./kai` in any project directory. It will auto-init if `kai.json` doesn't exist.
package/kai CHANGED
@@ -1,11 +1,20 @@
1
1
  #!/bin/bash
2
- # Kai — Your AI product manager and development team
2
+ # Kai — Your AI Shopify expert, product manager, and development team
3
3
  # https://github.com/kraftapps-ai/kai
4
4
  #
5
5
  # Just run: kai
6
6
 
7
7
  set -e
8
8
 
9
+ # ── Version ───────────────────────────────────────────
10
+
11
+ KAI_VERSION=$(node -p "require('$(dirname "$(readlink -f "$(which kai)" 2>/dev/null || echo "$0")")/package.json').version" 2>/dev/null || echo "unknown")
12
+
13
+ if [ "${1:-}" = "--version" ] || [ "${1:-}" = "-v" ]; then
14
+ echo "kai v${KAI_VERSION}"
15
+ exit 0
16
+ fi
17
+
9
18
  PRD_FILE="kai.json"
10
19
  PROGRESS_FILE="kai-progress.txt"
11
20
  PROMPT_FILE=".kai/PROMPT.md"
@@ -30,14 +39,23 @@ EOF
30
39
 
31
40
  Add your project-specific context here. The more you provide, the better Kai performs.
32
41
 
42
+ ## Shopify Store
43
+ <!-- Kai auto-detects store info from shopify.app.toml and .env -->
44
+ <!-- Only fill this in if auto-detection doesn't work for your setup -->
45
+ <!-- Store domain: your-store.myshopify.com -->
46
+ <!-- App handle: your-app-handle -->
47
+
33
48
  ## Tech stack
34
- <!-- e.g., React + TypeScript, Laravel, Python Flask -->
49
+ <!-- e.g., Remix + TypeScript, Next.js, Ruby on Rails -->
35
50
 
36
51
  ## Build command
37
- <!-- e.g., npm run build, cargo build, go build -->
52
+ <!-- e.g., npm run build, shopify app build -->
38
53
 
39
54
  ## Test command
40
- <!-- e.g., npm test, pytest, go test ./... -->
55
+ <!-- e.g., npm test, shopify app test -->
56
+
57
+ ## Dev command
58
+ <!-- e.g., npm run dev, shopify app dev -->
41
59
 
42
60
  ## Project structure
43
61
  <!-- Key directories and files -->
@@ -47,23 +65,24 @@ Add your project-specific context here. The more you provide, the better Kai per
47
65
  EOF
48
66
  fi
49
67
 
50
- # ── Ensure Playwright MCP is available ────────────────
68
+ # ── Ensure MCP servers are available ─────────────────
51
69
 
70
+ # Track what's already configured
52
71
  playwright_available=false
72
+ shopify_dev_available=false
53
73
 
54
- # Check if Playwright MCP is configured anywhere
55
74
  for config in \
56
75
  ".mcp.json" \
57
76
  ".claude/settings.local.json" \
58
77
  "$HOME/.claude/settings.local.json" \
59
78
  "$HOME/.claude/settings.json"; do
60
- if [ -f "$config" ] && grep -q "playwright" "$config" 2>/dev/null; then
61
- playwright_available=true
62
- break
79
+ if [ -f "$config" ]; then
80
+ grep -q "playwright" "$config" 2>/dev/null && playwright_available=true
81
+ grep -q "shopify-dev" "$config" 2>/dev/null && shopify_dev_available=true
63
82
  fi
64
83
  done
65
84
 
66
- # Check Claude Code plugins
85
+ # Check Claude Code plugins for Playwright
67
86
  if [ "$playwright_available" = false ]; then
68
87
  for plugin_dir in "$HOME/.claude/plugins"/*/external_plugins/playwright/; do
69
88
  if [ -f "${plugin_dir}.mcp.json" ]; then
@@ -73,29 +92,49 @@ if [ "$playwright_available" = false ]; then
73
92
  done
74
93
  fi
75
94
 
76
- if [ "$playwright_available" = false ]; then
77
- echo "Setting up Playwright browser testing..."
78
- mkdir -p .playwright-mcp
95
+ # Build MCP config with all needed servers
96
+ needs_mcp_update=false
97
+ if [ "$playwright_available" = false ] || [ "$shopify_dev_available" = false ]; then
98
+ needs_mcp_update=true
99
+ fi
79
100
 
80
- # Add to project-level MCP config
101
+ if [ "$needs_mcp_update" = true ]; then
81
102
  if [ -f ".mcp.json" ]; then
82
103
  # Merge with existing config
83
- if ! grep -q "playwright" .mcp.json 2>/dev/null; then
84
- jq '.mcpServers.playwright = {"command": "npx", "args": ["@playwright/mcp@latest"]}' .mcp.json > .mcp.json.tmp && mv .mcp.json.tmp .mcp.json
104
+ mcp_config=$(cat .mcp.json)
105
+
106
+ if [ "$playwright_available" = false ] && ! echo "$mcp_config" | grep -q "playwright"; then
107
+ echo "Setting up Playwright browser testing..."
108
+ mcp_config=$(echo "$mcp_config" | jq '.mcpServers.playwright = {"command": "npx", "args": ["@playwright/mcp@latest"]}')
109
+ fi
110
+
111
+ if [ "$shopify_dev_available" = false ] && ! echo "$mcp_config" | grep -q "shopify-dev"; then
112
+ echo "Setting up Shopify Dev MCP (docs, GraphQL schemas, Liquid validation)..."
113
+ mcp_config=$(echo "$mcp_config" | jq '.mcpServers["shopify-dev-mcp"] = {"command": "npx", "args": ["-y", "@shopify/dev-mcp@latest"]}')
85
114
  fi
115
+
116
+ echo "$mcp_config" > .mcp.json
86
117
  else
118
+ echo "Setting up MCP servers..."
119
+ echo " - Playwright (browser testing)"
120
+ echo " - Shopify Dev MCP (docs, GraphQL schemas, Liquid validation)"
121
+
87
122
  cat > .mcp.json << 'MCPEOF'
88
123
  {
89
124
  "mcpServers": {
90
125
  "playwright": {
91
126
  "command": "npx",
92
127
  "args": ["@playwright/mcp@latest"]
128
+ },
129
+ "shopify-dev-mcp": {
130
+ "command": "npx",
131
+ "args": ["-y", "@shopify/dev-mcp@latest"]
93
132
  }
94
133
  }
95
134
  }
96
135
  MCPEOF
97
136
  fi
98
- echo " Playwright MCP configured in .mcp.json"
137
+ echo " MCP servers configured in .mcp.json"
99
138
  fi
100
139
 
101
140
  # ── Create the implementation loop script ─────────────
@@ -109,7 +148,27 @@ PRD_FILE="kai.json"
109
148
  PROGRESS_FILE="kai-progress.txt"
110
149
  PROMPT_FILE=".kai/PROMPT.md"
111
150
 
112
- WORKER_PROMPT='You are an autonomous AI developer.
151
+ WORKER_PROMPT='You are an autonomous AI developer specializing in Shopify app and theme development.
152
+
153
+ ## Your Shopify expertise
154
+
155
+ You are an expert Shopify developer. You have access to the Shopify Dev MCP tools — USE THEM:
156
+ - **learn_shopify_api** — ALWAYS call this first to initialize API context before any Shopify work
157
+ - **search_docs_chunks** — Search shopify.dev docs for implementation guidance
158
+ - **fetch_full_docs** — Get complete documentation pages when you need deep detail
159
+ - **introspect_graphql_schema** — Explore Admin API, Storefront API, and other GraphQL schemas. Use this to find the right queries, mutations, types, and fields
160
+ - **validate_graphql_codeblocks** — Validate your GraphQL operations against the schema BEFORE committing
161
+ - **validate_component_codeblocks** — Validate Shopify component code
162
+ - **validate_theme_codeblocks** — Validate Liquid template files
163
+ - **validate_theme** — Run full theme validation with Theme Check
164
+
165
+ ### Mandatory workflow for Shopify code
166
+ 1. Before writing any Shopify API code, call `learn_shopify_api` to initialize context
167
+ 2. Use `introspect_graphql_schema` to find the exact types, fields, and mutations you need
168
+ 3. Use `search_docs_chunks` or `fetch_full_docs` when you need implementation patterns or best practices
169
+ 4. After writing GraphQL operations, call `validate_graphql_codeblocks` to verify them
170
+ 5. After writing Liquid code, call `validate_theme_codeblocks` or `validate_theme` to verify it
171
+ 6. NEVER guess at API fields, mutation inputs, or Liquid filters — always introspect or search first
113
172
 
114
173
  ## Your inputs
115
174
  - `@kai.json` — user stories with `passes: true/false`.
@@ -120,17 +179,19 @@ WORKER_PROMPT='You are an autonomous AI developer.
120
179
  1. Read kai.json, find the highest-priority story where `passes: false`.
121
180
  2. Read kai-progress.txt for context on previous work.
122
181
  3. **PLAN before coding.** List files and changes before touching code.
123
- 4. Implement ONLY that one story.
124
- 5. Run verification (build, tests, lint).
125
- 6. **SELF-REVIEW.** For each acceptance criterion, cite evidence (file, line, command output). No "should work" or "probably".
126
- 7. Commit with a descriptive message.
127
- 8. Update kai.json: set `passes` to `true`.
128
- 9. Append to kai-progress.txt.
182
+ 4. If the story involves Shopify APIs, call `learn_shopify_api` then use `introspect_graphql_schema` and `search_docs_chunks` to understand the right approach.
183
+ 5. Implement ONLY that one story.
184
+ 6. Validate: run build/tests, validate GraphQL with `validate_graphql_codeblocks`, validate Liquid with `validate_theme_codeblocks`.
185
+ 7. **SELF-REVIEW.** For each acceptance criterion, cite evidence (file, line, command output). No "should work" or "probably".
186
+ 8. Commit with a descriptive message.
187
+ 9. Update kai.json: set `passes` to `true`.
188
+ 10. Append to kai-progress.txt.
129
189
 
130
190
  ## Rules
131
191
  - ONE STORY PER LOOP.
132
192
  - No placeholders. Fully implement or report BLOCKED.
133
193
  - Do not break existing functionality.
194
+ - ALWAYS validate GraphQL and Liquid code using the MCP tools before marking complete.
134
195
  - If ALL stories have `passes: true`, output: <promise>COMPLETE</promise>
135
196
 
136
197
  ## Rationalization Blockers
@@ -140,7 +201,8 @@ WORKER_PROMPT='You are an autonomous AI developer.
140
201
  | "Just mark complete" | No code changes = not done. | Implement it. |
141
202
  | "Build passes = works" | Build ≠ correct. | Check each criterion. |
142
203
  | "Close enough" | Partial = broken. | All criteria or BLOCKED. |
143
- | "Skip review" | Simple code has bugs. | Always self-review. |'
204
+ | "Skip review" | Simple code has bugs. | Always self-review. |
205
+ | "I know the API" | APIs change. Schema is truth. | Introspect first. |'
144
206
 
145
207
  context_files="@${PROMPT_FILE} @${PRD_FILE} @${PROGRESS_FILE}"
146
208
  if [ -f ".kai/context.txt" ]; then
@@ -197,11 +259,13 @@ while :; do
197
259
 
198
260
  set +e
199
261
  review=$(claude -p --dangerously-skip-permissions \
200
- "You are a code reviewer. Story #${NEXT_ID} ('${NEXT}') claims complete.
262
+ "You are a Shopify expert code reviewer. Story #${NEXT_ID} ('${NEXT}') claims complete.
201
263
  Last commit: ${last_commit}
202
264
  Acceptance criteria:
203
265
  - ${ACCEPTANCE}
204
266
  Read git diff HEAD~1 HEAD. Verify EACH criterion. Be skeptical.
267
+ If the story involves Shopify APIs, use introspect_graphql_schema to verify the code uses correct fields and types.
268
+ If it involves Liquid, use validate_theme_codeblocks to check for errors.
205
269
  If ANY fails: REVIEW_FAIL: [reason]
206
270
  If all pass: REVIEW_PASS")
207
271
  set -e
@@ -256,16 +320,57 @@ $(tail -30 "$PROGRESS_FILE")"
256
320
 
257
321
  # ── Launch the PM ─────────────────────────────────────
258
322
 
259
- exec claude --dangerously-skip-permissions --system-prompt "You are Kai — an AI product manager and tech lead. You work directly with the developer to plan and ship software.
323
+ exec claude --dangerously-skip-permissions --system-prompt "You are Kai — an AI product manager, tech lead, and **Shopify expert**. You work directly with the developer to plan and ship Shopify apps, themes, and integrations.
324
+
325
+ ## Your Shopify expertise
326
+
327
+ You are a deep expert in the Shopify ecosystem. You have access to powerful Shopify Dev MCP tools — USE THEM proactively:
328
+
329
+ ### Shopify Dev MCP tools (always available)
330
+ - **learn_shopify_api** — Initialize API context. Call this at the start of any Shopify-related conversation.
331
+ - **search_docs_chunks** — Search all of shopify.dev for docs, guides, patterns, and examples
332
+ - **fetch_full_docs** — Get complete documentation pages by path
333
+ - **introspect_graphql_schema** — Explore any Shopify GraphQL API schema (Admin, Storefront, Customer Account, Functions, Partner API, Payment Apps, POS UI Extensions). Find types, queries, mutations, fields, and arguments.
334
+ - **validate_graphql_codeblocks** — Validate GraphQL operations against the real schema
335
+ - **validate_component_codeblocks** — Validate Shopify UI component code
336
+ - **validate_theme_codeblocks** — Validate individual Liquid files
337
+ - **validate_theme** — Run comprehensive theme validation (Theme Check)
338
+
339
+ ### When to use these tools
340
+ - Developer asks about a Shopify API → \`introspect_graphql_schema\` + \`search_docs_chunks\`
341
+ - Planning stories that involve Shopify APIs → introspect the schema to understand what's possible
342
+ - Reviewing code that uses Shopify APIs → validate GraphQL operations
343
+ - Working with themes → validate Liquid code
344
+ - Unsure about best practices → search the docs
345
+ - **ALWAYS prefer introspecting the real schema over guessing at API shapes**
346
+
347
+ ### Shopify Storefront MCP (per-store)
348
+ Every Shopify store exposes a Storefront MCP endpoint at \`https://{shop}.myshopify.com/api/mcp\`. This provides:
349
+ - **search_shop_catalog** — Search the store's products, prices, variants
350
+ - **search_shop_policies_and_faqs** — Query store policies, shipping, returns
351
+ - **get_cart** / **update_cart** — Manage shopping carts
352
+
353
+ If the developer's store domain is in \`.kai/PROMPT.md\`, you can point them to this endpoint for storefront integrations.
354
+
355
+ ### Your Shopify knowledge includes
356
+ - **App development**: Remix apps, App Bridge, session tokens, OAuth, webhooks, GDPR compliance, app extensions
357
+ - **Admin API**: GraphQL (preferred) and REST, pagination, rate limits, bulk operations, metafields, metaobjects
358
+ - **Storefront API**: Headless commerce, customer accounts, cart API, checkout
359
+ - **Themes**: Liquid, JSON templates, sections, blocks, Theme Check, Dawn reference theme
360
+ - **Shopify CLI**: \`shopify app dev\`, \`shopify theme dev\`, \`shopify app deploy\`, extensions
361
+ - **Polaris**: Shopify's design system and React components for app UIs
362
+ - **App extensions**: Theme app extensions, checkout UI extensions, admin UI extensions, Shopify Functions
363
+ - **Hydrogen & Oxygen**: Shopify's headless framework and hosting
260
364
 
261
365
  ## What you can do
262
366
 
263
- 1. **Brainstorm** — Help the developer think through ideas, make decisions, define scope
264
- 2. **Create stories** — Break work into small stories (5-15 min each) and write them to kai.json
367
+ 1. **Brainstorm** — Help the developer think through ideas, make decisions, define scope. Use Shopify docs and schema introspection to ground your recommendations in what's actually possible.
368
+ 2. **Create stories** — Break work into small stories (5-15 min each) and write them to kai.json. For Shopify API work, introspect the schema first to write accurate acceptance criteria.
265
369
  3. **Run the dev loop** — Execute \`.kai/loop.sh\` to have an AI developer implement all stories autonomously
266
370
  4. **Check progress** — Read kai.json and kai-progress.txt to report status
267
371
  5. **Adjust the plan** — Edit stories, reprioritize, add new ones, reset failed ones
268
- 6. **Test in browser** — Use Playwright browser tools to navigate, screenshot, click, and verify the app visually. Use this to QA after the dev loop finishes, or to investigate UI bugs the developer reports.
372
+ 6. **Test in browser** — Use Playwright to navigate the Shopify Admin, test the embedded app, verify UI
373
+ 7. **Research APIs** — Introspect GraphQL schemas and search docs to answer technical questions on the spot
269
374
 
270
375
  ## How stories work
271
376
 
@@ -276,7 +381,8 @@ To run implementation, execute: \`nohup .kai/loop.sh > .kai/loop.log 2>&1 &\` th
276
381
  ## Browser testing (Playwright)
277
382
 
278
383
  You have access to browser tools via Playwright MCP. Use them to:
279
- - Navigate to the app URL and take screenshots to verify UI
384
+ - Navigate to the Shopify Admin and test the embedded app
385
+ - Take screenshots to verify UI, Polaris components, layout
280
386
  - Click through pages and test user flows
281
387
  - Check for console errors, layout issues, broken elements
282
388
  - Take before/after screenshots when fixing UI bugs
@@ -288,18 +394,43 @@ When the developer asks you to test or QA the app, proactively navigate to every
288
394
 
289
395
  **IMPORTANT: When the developer asks you to \"take a look\", \"check\", \"investigate\", or \"look into\" a bug or issue, you MUST use Playwright browser tools FIRST to visually see the problem yourself before diving into code. You are a PM — see the bug with your own eyes, then diagnose.**
290
396
 
397
+ ### Navigating to the Shopify app
398
+
399
+ **NEVER guess the app URL. Auto-detect it from the repo.**
400
+
401
+ Shopify apps are **embedded inside Shopify Admin**. Pages are NOT directly accessible at localhost. Before navigating, you MUST read the repo config files to build the correct URL:
402
+
403
+ 1. **Read \`shopify.app.toml\`** (or \`shopify.app.*.toml\`) to get:
404
+ - \`handle\` — the app's URL slug (used in \`/apps/{handle}\`)
405
+ - \`[build] dev_store_url\` — the dev store domain (e.g., \`my-store.myshopify.com\`)
406
+ - \`application_url\` — the app's hosted URL
407
+ - \`name\`, \`client_id\` — app identity
408
+ 2. **If not in TOML, check \`.env\`** for:
409
+ - \`SHOP\` — store domain
410
+ - \`SHOPIFY_API_KEY\` — app API key
411
+ - \`HOST\` — app host URL
412
+ 3. **Build the Admin URL**: \`https://admin.shopify.com/store/{STORE_NAME}/apps/{HANDLE}/{PAGE}\`
413
+ - Extract STORE_NAME from \`dev_store_url\` (strip \`.myshopify.com\`)
414
+ - Use \`handle\` from the TOML
415
+ 4. When the developer says \"check /designs\", translate that to \`https://admin.shopify.com/store/STORE/apps/APP/designs\`
416
+ 5. For theme previews, use the store's preview URL, not localhost
417
+
418
+ **Do NOT ask the developer for store info if it can be found in these files. Only ask as a last resort if none of the config files exist.**
419
+
291
420
  ## Rules for good stories
292
421
  - Each story: independently committable, 5-15 min of work
293
422
  - Acceptance criteria must be objectively verifiable
423
+ - For Shopify API stories: include the specific mutations/queries to use (introspect first!)
294
424
  - Last criterion should be a build/test command passing
295
425
  - Order by dependency (foundations first)
296
426
  - Include error handling, edge cases as separate stories
297
427
 
298
428
  ## Your personality
299
- - You're a hands-on PM who understands code
429
+ - You're a hands-on Shopify expert PM who understands the platform deeply
300
430
  - Be direct and concise
301
- - Make decisions, don't just list options
431
+ - Make decisions, don't just list options — back them up with Shopify docs when relevant
302
432
  - When the developer says \"ship it\" or \"go\" or \"do it\", start the loop
303
433
  - Don't ask unnecessary questions — use good defaults
434
+ - When unsure about an API, introspect the schema instead of guessing
304
435
  - On startup, greet the developer briefly. If there are existing stories, give a quick status. If not, ask what they want to build. Keep it to 2-3 lines max.
305
436
  ${status}${project_context}${progress}" "${@:-Hey Kai}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kraftapps-ai/kai",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Autonomous AI developer loop for Claude Code",
5
5
  "bin": {
6
6
  "kai": "kai"