@ak--47/dungeon-master 1.7.0 → 1.8.1

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 (43) hide show
  1. package/.claude/skills/analyze-soup/SKILL.md +30 -11
  2. package/.claude/skills/create-dungeon/SKILL.md +84 -44
  3. package/.claude/skills/create-project/SKILL.md +28 -3
  4. package/.claude/skills/create-project/context.mjs +89 -0
  5. package/.claude/skills/create-project/provision.mjs +1 -60
  6. package/.claude/skills/headless-build/SKILL.md +39 -12
  7. package/.claude/skills/powertools/SKILL.md +26 -3
  8. package/.claude/skills/release-check/SKILL.md +124 -0
  9. package/.claude/skills/verify-dungeon/SKILL.md +103 -29
  10. package/.claude/skills/verify-dungeon/references/alignment-contract.md +84 -0
  11. package/.claude/skills/verify-dungeon/references/counting-semantics.md +41 -16
  12. package/.claude/skills/verify-dungeon/references/report-format.md +41 -10
  13. package/.claude/skills/verify-dungeon/references/sql-recipes.md +171 -226
  14. package/.claude/skills/warehouse-metrics/GAPS-template.md +34 -0
  15. package/.claude/skills/warehouse-metrics/SKILL.md +111 -0
  16. package/.claude/skills/warehouse-metrics/deploy.mjs +651 -0
  17. package/.claude/skills/write-hooks/SKILL.md +94 -51
  18. package/CHANGELOG.md +183 -0
  19. package/HOOKS.md +165 -18
  20. package/README.md +265 -1
  21. package/docs/guides/1.8.0-upgrade-guide.md +151 -0
  22. package/docs/guides/1.8.1-upgrade-guide.md +153 -0
  23. package/dungeons/technical/warehouse.js +187 -0
  24. package/index.js +116 -2
  25. package/lib/core/config-validator.js +21 -0
  26. package/lib/core/dungeon-loader.js +1 -1
  27. package/lib/core/storage.js +51 -3
  28. package/lib/generators/events.js +6 -0
  29. package/lib/generators/funnels.js +15 -0
  30. package/lib/generators/standalone.js +248 -0
  31. package/lib/generators/warehouse.js +828 -0
  32. package/lib/hook-helpers/shape.js +73 -17
  33. package/lib/orchestrators/mixpanel-sender.js +27 -2
  34. package/lib/orchestrators/user-loop.js +83 -15
  35. package/lib/templates/story-spec.schema.json +41 -16
  36. package/lib/utils/utils.js +37 -12
  37. package/lib/verify/funnel-engine.js +66 -26
  38. package/lib/verify/index.js +1 -0
  39. package/lib/verify/story-runner.js +71 -8
  40. package/lib/verify/warehouse.js +683 -0
  41. package/package.json +4 -2
  42. package/scripts/verify-stories.mjs +150 -44
  43. package/types.d.ts +312 -9
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: warehouse-metrics
3
+ description: 'Use when a completed warehouse dungeon needs its warehouse tables loaded into BigQuery and saved as Mixpanel warehouse metrics. Triggers: "deploy warehouse metrics", "load warehouse tables", "connect warehouse metric source", "save warehouse metrics", after a dungeon has already run.'
4
+ argument-hint: '[dungeon path, e.g. dungeons/user/acme/acme.js]'
5
+ model: claude-opus-4-6
6
+ effort: max
7
+ ---
8
+
9
+ # Deploy Warehouse Tables and Metrics
10
+
11
+ Load the generated warehouse tables for a dungeon into BigQuery, connect the dataset to Mixpanel with the existing powertools macro, preview each metric SQL, and save the warehouse metrics when the CRUD endpoints are available.
12
+
13
+ **Dungeon file:** `$ARGUMENTS`
14
+
15
+ ## What it does
16
+
17
+ The orchestrator is `.claude/skills/warehouse-metrics/deploy.mjs`. It works from the warehouse manifest emitted by a completed dungeon run.
18
+
19
+ 1. Loads the dungeon with the package loader and requires `warehouseMetrics`.
20
+ 2. Finds the latest warehouse manifest and table files, or uses `--data-prefix` when supplied.
21
+ 3. Normalizes the BigQuery dataset name to `dm_<dungeon_name>`, unless `--dataset` overrides it.
22
+ 4. Writes per-table SQL files under the dungeon's sibling `warehouse/` directory with `{{DATASET}}` already substituted for the dataset id. The metric SQL itself is fully qualified to `mixpanel-gtm-training.<dataset>.<table>`.
23
+ 5. Runs a non-destructive `bq ls` preflight first so missing CLI or ADC fails before any write.
24
+ 6. Probes `GET /crud/getWarehouseMetrics` first and, when available, lists metrics before any BigQuery writes so malformed list payloads or upstream 500s fail early.
25
+ 7. Loads the tables into BigQuery with explicit schemas from the manifest, then reuses `.claude/skills/powertools/pt.mjs` to call `/macro/setup-bq-warehouse`. Do not reimplement that flow here. Only the macro performs the GCP-side IAM grant.
26
+ 8. If the docs route 404s, the script still completes the BigQuery load and source setup, then writes `warehouse/GAPS.md` from the template for manual metric setup.
27
+ 9. When the endpoint exists, it dedupes by `name`, previews SQL with `previewWarehouseMetric`, then saves new metrics with `createWarehouseMetric`.
28
+
29
+ ## Flags
30
+
31
+ ```bash
32
+ node .claude/skills/warehouse-metrics/deploy.mjs <dungeon-path> [--dataset dm_name] [--data-prefix path/prefix] [--dry-run]
33
+ ```
34
+
35
+ - `--dataset`: override the normalized `dm_<name>` dataset.
36
+ - `--data-prefix`: explicit run artifact prefix, for example `/tmp/run/warehouse-demo` for `/tmp/run/warehouse-demo-WAREHOUSE-MANIFEST.json`.
37
+ - `--dry-run`: prints the full `bq ls`, docs probe, metric list, load, source, preview, and create plan without executing commands or requiring credentials. It still writes the SQL files and renders `warehouse/GAPS.md` for review.
38
+
39
+ Dry-run is not read-only. Preserve any existing actual deployment report before
40
+ running it. Keep proposed setup gaps separate from recorded live outcomes.
41
+
42
+ ## Preflight
43
+
44
+ - Apply the [1.8.1 verification contract](../verify-dungeon/references/alignment-contract.md).
45
+ Offline verification stops at local evidence and the deployment handoff. Do not
46
+ automatically run deployment, endpoint probes, previews, or cloud commands.
47
+ - The dungeon must have passed `/verify-dungeon` and produced local warehouse
48
+ files with `writeToDisk: true` and `gzip: false`. Use the exact verified
49
+ `--data-prefix` and its matching `-WAREHOUSE-MANIFEST.json`; preserve all table
50
+ files referenced by the manifest. Do not use blanket prune before deployment.
51
+ - Live mode requires `.env` `BEARER_TOKEN` for powertools.
52
+ - Live mode requires working `bq` / gcloud ADC.
53
+ - The dungeon must already have `credentials.projectId` from `/create-project`.
54
+ - The Power Tools runtime principal needs `roles/resourcemanager.projectIamAdmin`
55
+ to grant project-level `roles/bigquery.jobUser`, and `roles/bigquery.admin`
56
+ (or equivalent permissions) for dataset creation and ACL changes. The macro
57
+ grants the Mixpanel principal `roles/bigquery.dataViewer` on the source dataset.
58
+ Keep these prerequisites; do not describe IAM as currently blocked. The operator
59
+ confirms the grant is fixed. Local Power Tools revision `7ae78aa` records the
60
+ successful one-shot live path and legacy `READER`/`WRITER`/`OWNER` ACL fix.
61
+ This audit used local evidence only and made no live calls.
62
+
63
+ ## Warnings
64
+
65
+ - `bq load --replace` overwrites the destination table contents. Treat live execution as destructive for existing warehouse tables and get explicit user confirmation before running it.
66
+ - `createWarehouseMetric` does not validate SQL. This skill previews every query first so the summary means something.
67
+ - `source_id` is immutable on update. This flow is create-or-skip by metric name; it does not try to update a metric onto a new source.
68
+ - `refreshWarehouseMetric` only invalidates cache. It does not execute the query.
69
+
70
+ ## Preview gotcha
71
+
72
+ `previewWarehouseMetric` rejects raw SQL containing `DROP`, `DELETE`, `TRUNCATE`, `ALTER`, `CREATE`, `INSERT`, or `UPDATE` as plain substrings. That means `created_at` trips `CREATE` and `updated_at` trips `UPDATE`.
73
+
74
+ This skill fails clearly in that case. It does not pretend preview succeeded. It also does not auto-rewrite the SQL. Aliasing only helps if the blocked text disappears from the query entirely. If the generated table uses one of those names, rename the column or finish the metric manually.
75
+
76
+ ## Typical flow
77
+
78
+ ### 1. Show the plan
79
+
80
+ ```bash
81
+ node .claude/skills/warehouse-metrics/deploy.mjs <dungeon-path> --data-prefix <verified-prefix> --dry-run
82
+ ```
83
+
84
+ Review the printed commands, the emitted SQL files, and the rendered `warehouse/GAPS.md`.
85
+
86
+ ### 2. Confirm live execution
87
+
88
+ Live mode writes or replaces BigQuery tables and saves metrics into a real Mixpanel project. Confirm with the user before running it.
89
+
90
+ ### 3. Run live
91
+
92
+ ```bash
93
+ node .claude/skills/warehouse-metrics/deploy.mjs <dungeon-path> --data-prefix <verified-prefix>
94
+ ```
95
+
96
+ ### 4. Report
97
+
98
+ Relay:
99
+
100
+ - dataset loaded
101
+ - source id returned by `/macro/setup-bq-warehouse`
102
+ - metrics saved vs skipped by name
103
+ - SQL file paths
104
+ - whether `warehouse/GAPS.md` was written or an older one was intentionally left in place
105
+
106
+ ## Error handling
107
+
108
+ - A missing manifest or missing warehouse files is a hard stop. Tell the user to run `node scripts/run-dungeon.mjs <dungeon>` first, or pass `--data-prefix`.
109
+ - A `GET /crud/getWarehouseMetrics` 404 is the only fallback. The script still loads tables and connects the source, then writes `warehouse/GAPS.md` instead of pretending metrics were saved.
110
+ - Any other docs probe error, `bq` failure, preview failure, or create failure surfaces immediately. No catch-and-continue.
111
+ - Existing `warehouse/GAPS.md` is never deleted silently. If a new one is written, the script says so. If CRUD is now available, the old file is left in place and reported as stale.