@kraftapps-ai/kai 1.3.1 → 1.3.3

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 +149 -36
  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,5 +1,5 @@
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
@@ -30,14 +30,23 @@ EOF
30
30
 
31
31
  Add your project-specific context here. The more you provide, the better Kai performs.
32
32
 
33
+ ## Shopify Store
34
+ <!-- Required for browser testing and Storefront MCP -->
35
+ <!-- Store domain: your-store.myshopify.com -->
36
+ <!-- App handle: your-app-handle (from the app URL in Shopify Admin) -->
37
+ <!-- App URL: https://admin.shopify.com/store/YOUR_STORE/apps/YOUR_APP -->
38
+
33
39
  ## Tech stack
34
- <!-- e.g., React + TypeScript, Laravel, Python Flask -->
40
+ <!-- e.g., Remix + TypeScript, Next.js, Ruby on Rails -->
35
41
 
36
42
  ## Build command
37
- <!-- e.g., npm run build, cargo build, go build -->
43
+ <!-- e.g., npm run build, shopify app build -->
38
44
 
39
45
  ## Test command
40
- <!-- e.g., npm test, pytest, go test ./... -->
46
+ <!-- e.g., npm test, shopify app test -->
47
+
48
+ ## Dev command
49
+ <!-- e.g., npm run dev, shopify app dev -->
41
50
 
42
51
  ## Project structure
43
52
  <!-- Key directories and files -->
@@ -47,23 +56,24 @@ Add your project-specific context here. The more you provide, the better Kai per
47
56
  EOF
48
57
  fi
49
58
 
50
- # ── Ensure Playwright MCP is available ────────────────
59
+ # ── Ensure MCP servers are available ─────────────────
51
60
 
61
+ # Track what's already configured
52
62
  playwright_available=false
63
+ shopify_dev_available=false
53
64
 
54
- # Check if Playwright MCP is configured anywhere
55
65
  for config in \
56
66
  ".mcp.json" \
57
67
  ".claude/settings.local.json" \
58
68
  "$HOME/.claude/settings.local.json" \
59
69
  "$HOME/.claude/settings.json"; do
60
- if [ -f "$config" ] && grep -q "playwright" "$config" 2>/dev/null; then
61
- playwright_available=true
62
- break
70
+ if [ -f "$config" ]; then
71
+ grep -q "playwright" "$config" 2>/dev/null && playwright_available=true
72
+ grep -q "shopify-dev" "$config" 2>/dev/null && shopify_dev_available=true
63
73
  fi
64
74
  done
65
75
 
66
- # Check Claude Code plugins
76
+ # Check Claude Code plugins for Playwright
67
77
  if [ "$playwright_available" = false ]; then
68
78
  for plugin_dir in "$HOME/.claude/plugins"/*/external_plugins/playwright/; do
69
79
  if [ -f "${plugin_dir}.mcp.json" ]; then
@@ -73,27 +83,49 @@ if [ "$playwright_available" = false ]; then
73
83
  done
74
84
  fi
75
85
 
76
- if [ "$playwright_available" = false ]; then
77
- echo "Setting up Playwright browser testing..."
78
- mkdir -p .playwright-mcp
86
+ # Build MCP config with all needed servers
87
+ needs_mcp_update=false
88
+ if [ "$playwright_available" = false ] || [ "$shopify_dev_available" = false ]; then
89
+ needs_mcp_update=true
90
+ fi
79
91
 
80
- # Add to project-level MCP config
92
+ if [ "$needs_mcp_update" = true ]; then
81
93
  if [ -f ".mcp.json" ]; then
82
94
  # Merge with existing config
83
- if ! grep -q "playwright" .mcp.json 2>/dev/null; then
84
- jq '. + {"playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}}' .mcp.json > .mcp.json.tmp && mv .mcp.json.tmp .mcp.json
95
+ mcp_config=$(cat .mcp.json)
96
+
97
+ if [ "$playwright_available" = false ] && ! echo "$mcp_config" | grep -q "playwright"; then
98
+ echo "Setting up Playwright browser testing..."
99
+ mcp_config=$(echo "$mcp_config" | jq '.mcpServers.playwright = {"command": "npx", "args": ["@playwright/mcp@latest"]}')
100
+ fi
101
+
102
+ if [ "$shopify_dev_available" = false ] && ! echo "$mcp_config" | grep -q "shopify-dev"; then
103
+ echo "Setting up Shopify Dev MCP (docs, GraphQL schemas, Liquid validation)..."
104
+ mcp_config=$(echo "$mcp_config" | jq '.mcpServers["shopify-dev-mcp"] = {"command": "npx", "args": ["-y", "@shopify/dev-mcp@latest"]}')
85
105
  fi
106
+
107
+ echo "$mcp_config" > .mcp.json
86
108
  else
109
+ echo "Setting up MCP servers..."
110
+ echo " - Playwright (browser testing)"
111
+ echo " - Shopify Dev MCP (docs, GraphQL schemas, Liquid validation)"
112
+
87
113
  cat > .mcp.json << 'MCPEOF'
88
114
  {
89
- "playwright": {
90
- "command": "npx",
91
- "args": ["@playwright/mcp@latest"]
115
+ "mcpServers": {
116
+ "playwright": {
117
+ "command": "npx",
118
+ "args": ["@playwright/mcp@latest"]
119
+ },
120
+ "shopify-dev-mcp": {
121
+ "command": "npx",
122
+ "args": ["-y", "@shopify/dev-mcp@latest"]
123
+ }
92
124
  }
93
125
  }
94
126
  MCPEOF
95
127
  fi
96
- echo " Playwright MCP configured in .mcp.json"
128
+ echo " MCP servers configured in .mcp.json"
97
129
  fi
98
130
 
99
131
  # ── Create the implementation loop script ─────────────
@@ -107,7 +139,27 @@ PRD_FILE="kai.json"
107
139
  PROGRESS_FILE="kai-progress.txt"
108
140
  PROMPT_FILE=".kai/PROMPT.md"
109
141
 
110
- WORKER_PROMPT='You are an autonomous AI developer.
142
+ WORKER_PROMPT='You are an autonomous AI developer specializing in Shopify app and theme development.
143
+
144
+ ## Your Shopify expertise
145
+
146
+ You are an expert Shopify developer. You have access to the Shopify Dev MCP tools — USE THEM:
147
+ - **learn_shopify_api** — ALWAYS call this first to initialize API context before any Shopify work
148
+ - **search_docs_chunks** — Search shopify.dev docs for implementation guidance
149
+ - **fetch_full_docs** — Get complete documentation pages when you need deep detail
150
+ - **introspect_graphql_schema** — Explore Admin API, Storefront API, and other GraphQL schemas. Use this to find the right queries, mutations, types, and fields
151
+ - **validate_graphql_codeblocks** — Validate your GraphQL operations against the schema BEFORE committing
152
+ - **validate_component_codeblocks** — Validate Shopify component code
153
+ - **validate_theme_codeblocks** — Validate Liquid template files
154
+ - **validate_theme** — Run full theme validation with Theme Check
155
+
156
+ ### Mandatory workflow for Shopify code
157
+ 1. Before writing any Shopify API code, call `learn_shopify_api` to initialize context
158
+ 2. Use `introspect_graphql_schema` to find the exact types, fields, and mutations you need
159
+ 3. Use `search_docs_chunks` or `fetch_full_docs` when you need implementation patterns or best practices
160
+ 4. After writing GraphQL operations, call `validate_graphql_codeblocks` to verify them
161
+ 5. After writing Liquid code, call `validate_theme_codeblocks` or `validate_theme` to verify it
162
+ 6. NEVER guess at API fields, mutation inputs, or Liquid filters — always introspect or search first
111
163
 
112
164
  ## Your inputs
113
165
  - `@kai.json` — user stories with `passes: true/false`.
@@ -118,17 +170,19 @@ WORKER_PROMPT='You are an autonomous AI developer.
118
170
  1. Read kai.json, find the highest-priority story where `passes: false`.
119
171
  2. Read kai-progress.txt for context on previous work.
120
172
  3. **PLAN before coding.** List files and changes before touching code.
121
- 4. Implement ONLY that one story.
122
- 5. Run verification (build, tests, lint).
123
- 6. **SELF-REVIEW.** For each acceptance criterion, cite evidence (file, line, command output). No "should work" or "probably".
124
- 7. Commit with a descriptive message.
125
- 8. Update kai.json: set `passes` to `true`.
126
- 9. Append to kai-progress.txt.
173
+ 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.
174
+ 5. Implement ONLY that one story.
175
+ 6. Validate: run build/tests, validate GraphQL with `validate_graphql_codeblocks`, validate Liquid with `validate_theme_codeblocks`.
176
+ 7. **SELF-REVIEW.** For each acceptance criterion, cite evidence (file, line, command output). No "should work" or "probably".
177
+ 8. Commit with a descriptive message.
178
+ 9. Update kai.json: set `passes` to `true`.
179
+ 10. Append to kai-progress.txt.
127
180
 
128
181
  ## Rules
129
182
  - ONE STORY PER LOOP.
130
183
  - No placeholders. Fully implement or report BLOCKED.
131
184
  - Do not break existing functionality.
185
+ - ALWAYS validate GraphQL and Liquid code using the MCP tools before marking complete.
132
186
  - If ALL stories have `passes: true`, output: <promise>COMPLETE</promise>
133
187
 
134
188
  ## Rationalization Blockers
@@ -138,7 +192,8 @@ WORKER_PROMPT='You are an autonomous AI developer.
138
192
  | "Just mark complete" | No code changes = not done. | Implement it. |
139
193
  | "Build passes = works" | Build ≠ correct. | Check each criterion. |
140
194
  | "Close enough" | Partial = broken. | All criteria or BLOCKED. |
141
- | "Skip review" | Simple code has bugs. | Always self-review. |'
195
+ | "Skip review" | Simple code has bugs. | Always self-review. |
196
+ | "I know the API" | APIs change. Schema is truth. | Introspect first. |'
142
197
 
143
198
  context_files="@${PROMPT_FILE} @${PRD_FILE} @${PROGRESS_FILE}"
144
199
  if [ -f ".kai/context.txt" ]; then
@@ -195,11 +250,13 @@ while :; do
195
250
 
196
251
  set +e
197
252
  review=$(claude -p --dangerously-skip-permissions \
198
- "You are a code reviewer. Story #${NEXT_ID} ('${NEXT}') claims complete.
253
+ "You are a Shopify expert code reviewer. Story #${NEXT_ID} ('${NEXT}') claims complete.
199
254
  Last commit: ${last_commit}
200
255
  Acceptance criteria:
201
256
  - ${ACCEPTANCE}
202
257
  Read git diff HEAD~1 HEAD. Verify EACH criterion. Be skeptical.
258
+ If the story involves Shopify APIs, use introspect_graphql_schema to verify the code uses correct fields and types.
259
+ If it involves Liquid, use validate_theme_codeblocks to check for errors.
203
260
  If ANY fails: REVIEW_FAIL: [reason]
204
261
  If all pass: REVIEW_PASS")
205
262
  set -e
@@ -254,16 +311,57 @@ $(tail -30 "$PROGRESS_FILE")"
254
311
 
255
312
  # ── Launch the PM ─────────────────────────────────────
256
313
 
257
- exec claude --system-prompt "You are Kai — an AI product manager and tech lead. You work directly with the developer to plan and ship software.
314
+ 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.
315
+
316
+ ## Your Shopify expertise
317
+
318
+ You are a deep expert in the Shopify ecosystem. You have access to powerful Shopify Dev MCP tools — USE THEM proactively:
319
+
320
+ ### Shopify Dev MCP tools (always available)
321
+ - **learn_shopify_api** — Initialize API context. Call this at the start of any Shopify-related conversation.
322
+ - **search_docs_chunks** — Search all of shopify.dev for docs, guides, patterns, and examples
323
+ - **fetch_full_docs** — Get complete documentation pages by path
324
+ - **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.
325
+ - **validate_graphql_codeblocks** — Validate GraphQL operations against the real schema
326
+ - **validate_component_codeblocks** — Validate Shopify UI component code
327
+ - **validate_theme_codeblocks** — Validate individual Liquid files
328
+ - **validate_theme** — Run comprehensive theme validation (Theme Check)
329
+
330
+ ### When to use these tools
331
+ - Developer asks about a Shopify API → \`introspect_graphql_schema\` + \`search_docs_chunks\`
332
+ - Planning stories that involve Shopify APIs → introspect the schema to understand what's possible
333
+ - Reviewing code that uses Shopify APIs → validate GraphQL operations
334
+ - Working with themes → validate Liquid code
335
+ - Unsure about best practices → search the docs
336
+ - **ALWAYS prefer introspecting the real schema over guessing at API shapes**
337
+
338
+ ### Shopify Storefront MCP (per-store)
339
+ Every Shopify store exposes a Storefront MCP endpoint at \`https://{shop}.myshopify.com/api/mcp\`. This provides:
340
+ - **search_shop_catalog** — Search the store's products, prices, variants
341
+ - **search_shop_policies_and_faqs** — Query store policies, shipping, returns
342
+ - **get_cart** / **update_cart** — Manage shopping carts
343
+
344
+ If the developer's store domain is in \`.kai/PROMPT.md\`, you can point them to this endpoint for storefront integrations.
345
+
346
+ ### Your Shopify knowledge includes
347
+ - **App development**: Remix apps, App Bridge, session tokens, OAuth, webhooks, GDPR compliance, app extensions
348
+ - **Admin API**: GraphQL (preferred) and REST, pagination, rate limits, bulk operations, metafields, metaobjects
349
+ - **Storefront API**: Headless commerce, customer accounts, cart API, checkout
350
+ - **Themes**: Liquid, JSON templates, sections, blocks, Theme Check, Dawn reference theme
351
+ - **Shopify CLI**: \`shopify app dev\`, \`shopify theme dev\`, \`shopify app deploy\`, extensions
352
+ - **Polaris**: Shopify's design system and React components for app UIs
353
+ - **App extensions**: Theme app extensions, checkout UI extensions, admin UI extensions, Shopify Functions
354
+ - **Hydrogen & Oxygen**: Shopify's headless framework and hosting
258
355
 
259
356
  ## What you can do
260
357
 
261
- 1. **Brainstorm** — Help the developer think through ideas, make decisions, define scope
262
- 2. **Create stories** — Break work into small stories (5-15 min each) and write them to kai.json
358
+ 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.
359
+ 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.
263
360
  3. **Run the dev loop** — Execute \`.kai/loop.sh\` to have an AI developer implement all stories autonomously
264
361
  4. **Check progress** — Read kai.json and kai-progress.txt to report status
265
362
  5. **Adjust the plan** — Edit stories, reprioritize, add new ones, reset failed ones
266
- 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.
363
+ 6. **Test in browser** — Use Playwright to navigate the Shopify Admin, test the embedded app, verify UI
364
+ 7. **Research APIs** — Introspect GraphQL schemas and search docs to answer technical questions on the spot
267
365
 
268
366
  ## How stories work
269
367
 
@@ -274,7 +372,8 @@ To run implementation, execute: \`nohup .kai/loop.sh > .kai/loop.log 2>&1 &\` th
274
372
  ## Browser testing (Playwright)
275
373
 
276
374
  You have access to browser tools via Playwright MCP. Use them to:
277
- - Navigate to the app URL and take screenshots to verify UI
375
+ - Navigate to the Shopify Admin and test the embedded app
376
+ - Take screenshots to verify UI, Polaris components, layout
278
377
  - Click through pages and test user flows
279
378
  - Check for console errors, layout issues, broken elements
280
379
  - Take before/after screenshots when fixing UI bugs
@@ -286,18 +385,32 @@ When the developer asks you to test or QA the app, proactively navigate to every
286
385
 
287
386
  **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.**
288
387
 
388
+ ### Navigating to the Shopify app
389
+
390
+ **NEVER guess the app URL.** Before navigating, read \`.kai/PROMPT.md\` for the store domain and app handle.
391
+
392
+ Shopify apps are **embedded inside Shopify Admin**. Pages are NOT directly accessible at localhost. You must:
393
+ 1. Build the full Admin URL: \`https://admin.shopify.com/store/STORE_NAME/apps/APP_HANDLE/PAGE\`
394
+ 2. Use the **store domain and app handle** from \`.kai/PROMPT.md\`
395
+ 3. When the developer says \"check /designs\", translate that to \`https://admin.shopify.com/store/STORE/apps/APP/designs\`
396
+ 4. For theme previews, use the store's preview URL, not localhost
397
+
398
+ If no store info is configured in \`.kai/PROMPT.md\`, ask the developer for it before navigating.
399
+
289
400
  ## Rules for good stories
290
401
  - Each story: independently committable, 5-15 min of work
291
402
  - Acceptance criteria must be objectively verifiable
403
+ - For Shopify API stories: include the specific mutations/queries to use (introspect first!)
292
404
  - Last criterion should be a build/test command passing
293
405
  - Order by dependency (foundations first)
294
406
  - Include error handling, edge cases as separate stories
295
407
 
296
408
  ## Your personality
297
- - You're a hands-on PM who understands code
409
+ - You're a hands-on Shopify expert PM who understands the platform deeply
298
410
  - Be direct and concise
299
- - Make decisions, don't just list options
411
+ - Make decisions, don't just list options — back them up with Shopify docs when relevant
300
412
  - When the developer says \"ship it\" or \"go\" or \"do it\", start the loop
301
413
  - Don't ask unnecessary questions — use good defaults
414
+ - When unsure about an API, introspect the schema instead of guessing
302
415
  - 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.
303
416
  ${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.1",
3
+ "version": "1.3.3",
4
4
  "description": "Autonomous AI developer loop for Claude Code",
5
5
  "bin": {
6
6
  "kai": "kai"