@thebassclef/lite 0.0.1 → 0.1.0

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 (182) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +85 -4
  3. package/dist/cli.cjs +1610 -0
  4. package/dist/cli.js +1587 -0
  5. package/dist/index.cjs +4 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +4 -0
  8. package/package.json +51 -3
  9. package/substrate/.bassclef/lite-manifest.json +1794 -0
  10. package/substrate/.claude/agents/architect.md +70 -0
  11. package/substrate/.claude/agents/builder.md +114 -0
  12. package/substrate/.claude/agents/designer.md +156 -0
  13. package/substrate/.claude/agents/reviewer.md +88 -0
  14. package/substrate/.claude/hooks/artifact-ingestion-gate.sh +357 -0
  15. package/substrate/.claude/hooks/assert-verify-steering.sh +77 -0
  16. package/substrate/.claude/hooks/bassclef-source-config-validate.sh +215 -0
  17. package/substrate/.claude/hooks/bassclef-sync.sh +634 -0
  18. package/substrate/.claude/hooks/compound-noun-scrub.sh +292 -0
  19. package/substrate/.claude/hooks/kiss-expansion-inject.sh +69 -0
  20. package/substrate/.claude/hooks/plain-english-steering.sh +156 -0
  21. package/substrate/.claude/hooks/post-skill-friction-check.sh +177 -0
  22. package/substrate/.claude/hooks/post-skill-telemetry.sh +62 -0
  23. package/substrate/.claude/hooks/pre-build-gate.sh +511 -0
  24. package/substrate/.claude/hooks/pre-commit-gate.sh +452 -0
  25. package/substrate/.claude/hooks/session-end.sh +433 -0
  26. package/substrate/.claude/hooks/session-reflection.sh +303 -0
  27. package/substrate/.claude/hooks/skill-body-grade-gate.sh +219 -0
  28. package/substrate/.claude/hooks/skill-body-intent-drift.sh +107 -0
  29. package/substrate/.claude/hooks/skill-step-list-check.sh +171 -0
  30. package/substrate/.claude/hooks/state-validate.sh +271 -0
  31. package/substrate/.claude/hooks/substrate-clarity-gate.sh +1110 -0
  32. package/substrate/.claude/hooks/temperance-gate.sh +147 -0
  33. package/substrate/.claude/hooks/testing-tier-enforce.sh +233 -0
  34. package/substrate/.claude/hooks/turn-prose-grade-measure.sh +219 -0
  35. package/substrate/.claude/hooks/turn-prose-kiss-check.sh +434 -0
  36. package/substrate/.claude/hooks/vocabulary-migration-check.sh +171 -0
  37. package/substrate/.claude/hooks/whereami-utc-gate.sh +142 -0
  38. package/substrate/.claude/luminaries/alan-cooper.md +170 -0
  39. package/substrate/.claude/luminaries/alistair-cockburn.md +140 -0
  40. package/substrate/.claude/luminaries/amazon-pr-faq.md +34 -0
  41. package/substrate/.claude/luminaries/ash-maurya.md +121 -0
  42. package/substrate/.claude/luminaries/bill-buxton.md +210 -0
  43. package/substrate/.claude/luminaries/charles-sanders-peirce.md +150 -0
  44. package/substrate/.claude/luminaries/david-ogilvy.md +192 -0
  45. package/substrate/.claude/luminaries/don-norman.md +173 -0
  46. package/substrate/.claude/luminaries/edward-tufte.md +179 -0
  47. package/substrate/.claude/luminaries/eric-evans.md +160 -0
  48. package/substrate/.claude/luminaries/frederick-brooks.md +50 -0
  49. package/substrate/.claude/luminaries/gang-of-four.md +157 -0
  50. package/substrate/.claude/luminaries/jason-fried-dhh.md +46 -0
  51. package/substrate/.claude/luminaries/jesse-james-garrett.md +154 -0
  52. package/substrate/.claude/luminaries/john-ousterhout.md +94 -0
  53. package/substrate/.claude/luminaries/karl-popper.md +132 -0
  54. package/substrate/.claude/luminaries/kent-beck.md +168 -0
  55. package/substrate/.claude/luminaries/linus-torvalds.md +218 -0
  56. package/substrate/.claude/luminaries/martin-fowler.md +164 -0
  57. package/substrate/.claude/luminaries/michael-feathers.md +125 -0
  58. package/substrate/.claude/luminaries/michael-nygard.md +118 -0
  59. package/substrate/.claude/luminaries/robert-c-martin.md +164 -0
  60. package/substrate/.claude/luminaries/saltzer-schroeder.md +194 -0
  61. package/substrate/.claude/luminaries/sophia-prater.md +193 -0
  62. package/substrate/.claude/luminaries/stephen-toulmin.md +131 -0
  63. package/substrate/.claude/rules/artifact-ingestion.md +179 -0
  64. package/substrate/.claude/rules/assert-only-after-verify.md +137 -0
  65. package/substrate/.claude/rules/blocked-items.md +146 -0
  66. package/substrate/.claude/rules/branching.md +28 -0
  67. package/substrate/.claude/rules/commit-conventions.md +22 -0
  68. package/substrate/.claude/rules/context-engineering.md +202 -0
  69. package/substrate/.claude/rules/context-management.md +85 -0
  70. package/substrate/.claude/rules/destructive-operations.md +69 -0
  71. package/substrate/.claude/rules/diagnosis.md +38 -0
  72. package/substrate/.claude/rules/guardrails.md +73 -0
  73. package/substrate/.claude/rules/identifier-leak-prevention.md +104 -0
  74. package/substrate/.claude/rules/lite-manifest-schema-change-discipline.md +98 -0
  75. package/substrate/.claude/rules/oo-ad-entry-point.md +117 -0
  76. package/substrate/.claude/rules/operator-facing-prose.md +196 -0
  77. package/substrate/.claude/rules/plain-english-discipline.md +154 -0
  78. package/substrate/.claude/rules/pr-body-shape.md +317 -0
  79. package/substrate/.claude/rules/pr-strategy.md +167 -0
  80. package/substrate/.claude/rules/sdlc-gates.md +149 -0
  81. package/substrate/.claude/rules/session-artifacts.md +236 -0
  82. package/substrate/.claude/rules/state-schema-validation.md +162 -0
  83. package/substrate/.claude/rules/whereami-load-bearing.md +202 -0
  84. package/substrate/.claude/rules/writing-craft-discipline.md +92 -0
  85. package/substrate/.claude/skills/build/SKILL.md +640 -0
  86. package/substrate/.claude/skills/decompose/SKILL.md +280 -0
  87. package/substrate/.claude/skills/diagnose/SKILL.md +297 -0
  88. package/substrate/.claude/skills/howdoi/SKILL.md +105 -0
  89. package/substrate/.claude/skills/ia-model/SKILL.md +108 -0
  90. package/substrate/.claude/skills/interaction-design/SKILL.md +112 -0
  91. package/substrate/.claude/skills/interpret-input/SKILL.md +180 -0
  92. package/substrate/.claude/skills/kiss/SKILL.md +449 -0
  93. package/substrate/.claude/skills/launch/SKILL.md +924 -0
  94. package/substrate/.claude/skills/lean-canvas/SKILL.md +332 -0
  95. package/substrate/.claude/skills/longrun/SKILL.md +426 -0
  96. package/substrate/.claude/skills/luminary/SKILL.md +481 -0
  97. package/substrate/.claude/skills/ogilvy-writing-audit/SKILL.md +177 -0
  98. package/substrate/.claude/skills/onboard-repo/SKILL.md +2190 -0
  99. package/substrate/.claude/skills/pattern-review/SKILL.md +99 -0
  100. package/substrate/.claude/skills/personas/SKILL.md +207 -0
  101. package/substrate/.claude/skills/promote/SKILL.md +283 -0
  102. package/substrate/.claude/skills/requirement/SKILL.md +98 -0
  103. package/substrate/.claude/skills/retro/SKILL.md +117 -0
  104. package/substrate/.claude/skills/riff/SKILL.md +114 -0
  105. package/substrate/.claude/skills/roadmap-reconcile/SKILL.md +163 -0
  106. package/substrate/.claude/skills/session-end/SKILL.md +309 -0
  107. package/substrate/.claude/skills/session-log/SKILL.md +299 -0
  108. package/substrate/.claude/skills/skills/SKILL.md +228 -0
  109. package/substrate/.claude/skills/spec/SKILL.md +105 -0
  110. package/substrate/.claude/skills/sprint/SKILL.md +392 -0
  111. package/substrate/.claude/skills/stage/SKILL.md +384 -0
  112. package/substrate/.claude/skills/state-a-problem/SKILL.md +185 -0
  113. package/substrate/.claude/skills/temperance/SKILL.md +108 -0
  114. package/substrate/.claude/skills/use-case/SKILL.md +417 -0
  115. package/substrate/.claude/skills/user-stories/SKILL.md +268 -0
  116. package/substrate/.claude/skills/value-prop/SKILL.md +251 -0
  117. package/substrate/.claude/skills/verify/SKILL.md +160 -0
  118. package/substrate/.claude/skills/whereami/SKILL.md +307 -0
  119. package/substrate/AGENTS.md +79 -0
  120. package/substrate/CLAUDE-lite.md +85 -0
  121. package/substrate/CODE_OF_CONDUCT.md +28 -0
  122. package/substrate/CONTRIBUTING.md +177 -0
  123. package/substrate/README.md +173 -0
  124. package/substrate/SECURITY.md +19 -0
  125. package/substrate/architecture/decisions/ADR-029-release-pipeline.md +79 -0
  126. package/substrate/architecture/decisions/ADR-031-non-breaking-changes-adopter-discipline.md +139 -0
  127. package/substrate/architecture/decisions/ADR-032-adopter-sync-dispatcher-architecture.md +192 -0
  128. package/substrate/architecture/decisions/ADR-039-release-tagging-scheme.md +145 -0
  129. package/substrate/architecture/decisions/ADR-040-planning-skill-vocabulary-and-lite-profile.md +155 -0
  130. package/substrate/architecture/decisions/ADR-044-unified-skill-body-template.md +162 -0
  131. package/substrate/lib/clean-artifacts-sweep.sh +112 -0
  132. package/substrate/lib/code-comment-discipline.sh +144 -0
  133. package/substrate/lib/composer-preflight.sh +459 -0
  134. package/substrate/lib/hook-inject.sh +255 -0
  135. package/substrate/lib/luminary-pick.sh +96 -0
  136. package/substrate/lib/output-discipline.sh +143 -0
  137. package/substrate/lib/rewrite-check.sh +214 -0
  138. package/substrate/lib/state.sh +1372 -0
  139. package/substrate/lib/telemetry.sh +205 -0
  140. package/substrate/lib/tier-check.sh +138 -0
  141. package/substrate/lib/tier-dependency-audit.sh +933 -0
  142. package/substrate/presence/install/bassclef-hook-connect.sh +178 -0
  143. package/substrate/presence/install/bassclef-sync.dispatcher.template.sh +841 -0
  144. package/substrate/presence/install/bassclef-sync.template.sh +2076 -0
  145. package/substrate/presence/install/schedule-auto-save.cron.sh +88 -0
  146. package/substrate/presence/install/schedule-auto-save.taskscheduler.md +122 -0
  147. package/substrate/scripts/aggregate-telemetry.sh +217 -0
  148. package/substrate/scripts/analyze-tier-dependencies.sh +239 -0
  149. package/substrate/scripts/generate-lite-manifest.sh +489 -0
  150. package/substrate/scripts/generate-tier-manifest.sh +28 -0
  151. package/substrate/scripts/intent-drift-check.sh +456 -0
  152. package/substrate/scripts/lite-manifest-drift-check.sh +146 -0
  153. package/substrate/scripts/render-lite-manifest-doc.sh +150 -0
  154. package/substrate/standards/bassclef-configs-schema.md +232 -0
  155. package/substrate/standards/bassclef-evolution.md +143 -0
  156. package/substrate/standards/bassclef-internal-jargon.md +244 -0
  157. package/substrate/standards/bassclef-managed-sentinel.md +96 -0
  158. package/substrate/standards/bassclef-source-config.md +228 -0
  159. package/substrate/standards/deferred-actions-schema.md +204 -0
  160. package/substrate/standards/docs-sync-allowlist.md +76 -0
  161. package/substrate/standards/graceful-exit.md +227 -0
  162. package/substrate/standards/hook-idempotency.md +102 -0
  163. package/substrate/standards/lite-manifest-schema-changes.md +75 -0
  164. package/substrate/standards/luminary-problem-patterns.md +481 -0
  165. package/substrate/standards/ogilvy-writing-rules.md +225 -0
  166. package/substrate/standards/opener-discipline.md +96 -0
  167. package/substrate/standards/operator-facing-prose-discipline.md +201 -0
  168. package/substrate/standards/project-directory-layout.md +276 -0
  169. package/substrate/standards/release-tagging.md +137 -0
  170. package/substrate/standards/sdlc-compliance.md +286 -0
  171. package/substrate/standards/secrets-lifecycle.md +210 -0
  172. package/substrate/standards/security-scanner-adapter.md +145 -0
  173. package/substrate/standards/skill-output-discipline.md +90 -0
  174. package/substrate/standards/state-spine.md +511 -0
  175. package/substrate/standards/tech-stack-config.md +109 -0
  176. package/substrate/standards/tier-dependency-analysis.md +167 -0
  177. package/substrate/standards/tier-runtime-deps/lite.md +57 -0
  178. package/substrate/standards/tier-tag-schema.md +155 -0
  179. package/substrate/standards/whereami-schema.md +301 -0
  180. package/substrate/standards/writing-guide.md +213 -0
  181. package/substrate/templates/deferred-action-template.md +45 -0
  182. package/substrate/templates/whereami-template.md +101 -0
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env bash
2
+ # lib/telemetry.sh — bassclef telemetry event emission (opt-in, local-only)
3
+ # tier: lite
4
+ # install-class: dual
5
+ #
6
+ # Deep module per @luminary john-ousterhout — small interface (5 functions
7
+ # + CLI), complex implementation (opt-in gate + UUID session + schema
8
+ # validation + append-only write) hidden behind it.
9
+ #
10
+ # Opt-in default OFF per @luminary alan-cooper (privacy) +
11
+ # @luminary donald-norman (affordance — first-session prompt is where
12
+ # consent lives).
13
+ #
14
+ # Schema-enforced no-PII per @luminary tony-hoare (contract — schema
15
+ # validates in; append-only out).
16
+ #
17
+ # Silent-fail wrap per @luminary michael-nygard (stability — telemetry
18
+ # never crashes adopter session).
19
+ #
20
+ # ADR-049 governs the design.
21
+
22
+ set -u
23
+
24
+ # ---------------------------------------------------------------------------
25
+ # Path resolution — respects TELEMETRY_ROOT for tests; falls back to repo
26
+ # root discovered from lib/ position.
27
+ # ---------------------------------------------------------------------------
28
+ if [ -z "${TELEMETRY_ROOT:-}" ]; then
29
+ TELEMETRY_ROOT="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
30
+ fi
31
+ _TELEM_CONFIG="${TELEMETRY_ROOT}/state/telemetry/config.json"
32
+ _TELEM_SESSION="${TELEMETRY_ROOT}/state/telemetry/current-session.uuid"
33
+ _TELEM_EVENTS_DIR="${TELEMETRY_ROOT}/state/telemetry"
34
+ _TELEM_SCHEMA="${TELEMETRY_ROOT}/standards/telemetry-event.schema.json"
35
+
36
+ # ---------------------------------------------------------------------------
37
+ # telemetry_is_enabled — exit 0 when opt-in ON, 1 when OFF.
38
+ # Default is OFF (no config file = OFF).
39
+ # ---------------------------------------------------------------------------
40
+ telemetry_is_enabled() {
41
+ [ -f "$_TELEM_CONFIG" ] || return 1
42
+ grep -q '"enabled"[[:space:]]*:[[:space:]]*true' "$_TELEM_CONFIG" 2>/dev/null
43
+ }
44
+
45
+ # ---------------------------------------------------------------------------
46
+ # telemetry_enable — write config marking opt-in ON.
47
+ # ---------------------------------------------------------------------------
48
+ telemetry_enable() {
49
+ mkdir -p "$(dirname "$_TELEM_CONFIG")"
50
+ printf '{"enabled": true}\n' > "$_TELEM_CONFIG"
51
+ echo "telemetry: ENABLED (config at $_TELEM_CONFIG)"
52
+ }
53
+
54
+ # ---------------------------------------------------------------------------
55
+ # telemetry_disable — remove config; opt-in returns to OFF.
56
+ # Existing event files stay in place; adopter owns their data.
57
+ # ---------------------------------------------------------------------------
58
+ telemetry_disable() {
59
+ rm -f "$_TELEM_CONFIG"
60
+ echo "telemetry: DISABLED (config removed; existing events in $_TELEM_EVENTS_DIR preserved)"
61
+ }
62
+
63
+ # ---------------------------------------------------------------------------
64
+ # telemetry_status — print current opt-in state + storage location.
65
+ # ---------------------------------------------------------------------------
66
+ telemetry_status() {
67
+ if telemetry_is_enabled; then
68
+ echo "telemetry: ON"
69
+ echo " config: $_TELEM_CONFIG"
70
+ echo " events: $_TELEM_EVENTS_DIR/events-YYYYMMDD.jsonl"
71
+ echo " share: bash lib/telemetry.sh share (send report to bassclef)"
72
+ echo " disable: bash lib/telemetry.sh disable"
73
+ else
74
+ echo "telemetry: OFF"
75
+ echo " enable: bash lib/telemetry.sh enable"
76
+ echo " see: docs/telemetry.md for what data ships"
77
+ fi
78
+ }
79
+
80
+ # ---------------------------------------------------------------------------
81
+ # telemetry_share — prepare a report share ready to send upstream.
82
+ # Adopter runs after aggregate. Opens a gh issue prefilled with the report
83
+ # body OR prints a mailto: URL. Adopter is always the sender; the command
84
+ # only lowers friction. Never auto-sends. Per ADR-049 §Alternatives Alt B
85
+ # (remote share deferred to Iteration 4).
86
+ # ---------------------------------------------------------------------------
87
+ telemetry_share() {
88
+ local report_dir="${TELEMETRY_ROOT}/docs/telemetry-reports"
89
+ local latest_report
90
+ latest_report=$(ls -1t "$report_dir"/*.md 2>/dev/null | head -1)
91
+
92
+ if [ -z "$latest_report" ]; then
93
+ echo "telemetry: no report to share — run first:"
94
+ echo " bash scripts/aggregate-telemetry.sh"
95
+ return 1
96
+ fi
97
+
98
+ echo "telemetry: latest report is $latest_report"
99
+ echo ""
100
+
101
+ # Prefer gh CLI if available — prefills a public bassclef issue
102
+ if command -v gh >/dev/null 2>&1; then
103
+ local target_repo="${BASSCLEF_TELEM_SHARE_REPO:-sunj-labs/bassclef}"
104
+ echo "Share via GitHub issue on $target_repo:"
105
+ echo ""
106
+ echo " gh issue create --repo $target_repo \\"
107
+ echo " --title 'telemetry: adopter uptake report — $(date -u +%Y-%m-%d)' \\"
108
+ echo " --label 'telemetry-share' \\"
109
+ echo " --body-file $latest_report"
110
+ echo ""
111
+ echo "Override target repo with BASSCLEF_TELEM_SHARE_REPO env var."
112
+ fi
113
+
114
+ # Also print a mailto: URL for adopters who prefer email
115
+ local subject
116
+ subject="telemetry: adopter uptake report $(date -u +%Y-%m-%d)"
117
+ local body_hint="Report attached at $latest_report — copy the file contents into the email body."
118
+ echo ""
119
+ echo "Or email:"
120
+ echo " mailto:${BASSCLEF_TELEM_SHARE_EMAIL:-hello@bassclef.dev}?subject=$(echo "$subject" | tr ' ' '+')&body=$(echo "$body_hint" | tr ' ' '+')"
121
+ echo ""
122
+ echo "You send the report yourself. Nothing leaves your machine automatically."
123
+ echo "Review $latest_report before sending — it contains only counts, no PII."
124
+ }
125
+
126
+ # ---------------------------------------------------------------------------
127
+ # telemetry_session_id — return current session UUID; generate if absent.
128
+ # UUID v4 per ADR-049; never derived from operator identity or repo path.
129
+ # ---------------------------------------------------------------------------
130
+ telemetry_session_id() {
131
+ if [ ! -f "$_TELEM_SESSION" ]; then
132
+ mkdir -p "$(dirname "$_TELEM_SESSION")"
133
+ if command -v uuidgen >/dev/null 2>&1; then
134
+ uuidgen | tr '[:upper:]' '[:lower:]' > "$_TELEM_SESSION"
135
+ else
136
+ # Fallback bash-only UUID v4 (random hex; v4 variant bits)
137
+ printf '%08x-%04x-4%03x-%04x-%012x\n' \
138
+ $((RANDOM * RANDOM % 4294967296)) \
139
+ $((RANDOM % 65536)) \
140
+ $((RANDOM % 4096)) \
141
+ $((RANDOM % 65536)) \
142
+ $((RANDOM * RANDOM * RANDOM % 281474976710656)) > "$_TELEM_SESSION"
143
+ fi
144
+ fi
145
+ cat "$_TELEM_SESSION"
146
+ }
147
+
148
+ # ---------------------------------------------------------------------------
149
+ # telemetry_reset_session — clear current session UUID.
150
+ # Called by session-end hook to close the current session boundary.
151
+ # ---------------------------------------------------------------------------
152
+ telemetry_reset_session() {
153
+ rm -f "$_TELEM_SESSION"
154
+ }
155
+
156
+ # ---------------------------------------------------------------------------
157
+ # telemetry_emit EVENT_JSON — validate against schema + append one line to
158
+ # today's JSONL file. Silent skip when opt-in OFF (returns 0).
159
+ # Never crashes caller — schema failures silently drop.
160
+ # ---------------------------------------------------------------------------
161
+ telemetry_emit() {
162
+ local event_json="$1"
163
+
164
+ # Opt-in gate FIRST — per pre-mortem R5, order matters
165
+ telemetry_is_enabled || return 0
166
+
167
+ mkdir -p "$_TELEM_EVENTS_DIR"
168
+ local today
169
+ today=$(date -u +%Y%m%d)
170
+ local events_file="$_TELEM_EVENTS_DIR/events-$today.jsonl"
171
+
172
+ # Validate against schema when ajv available. Silent skip on schema fail
173
+ # or missing binary — telemetry never crashes adopter session (R1).
174
+ # Requires ajv-cli + ajv-formats. Both ship together in every bassclef
175
+ # CI job that runs this path (per .github/workflows/*.yml). Adopters
176
+ # get both via bassclef-onboard or npm bassclef-lite install script.
177
+ if command -v ajv >/dev/null 2>&1 && [ -f "$_TELEM_SCHEMA" ]; then
178
+ local tmpfile
179
+ tmpfile="$(mktemp -t bassclef-telem-XXXXXX).json"
180
+ printf '%s\n' "$event_json" > "$tmpfile"
181
+ if ! ajv validate --spec=draft2020 -c ajv-formats -s "$_TELEM_SCHEMA" -d "$tmpfile" >/dev/null 2>&1; then
182
+ rm -f "$tmpfile"
183
+ return 0
184
+ fi
185
+ rm -f "$tmpfile"
186
+ fi
187
+
188
+ # Append one line
189
+ printf '%s\n' "$event_json" >> "$events_file"
190
+ }
191
+
192
+ # ---------------------------------------------------------------------------
193
+ # CLI dispatch — runs only when invoked directly (bash lib/telemetry.sh ...)
194
+ # Sourced use exposes functions without side effects.
195
+ # ---------------------------------------------------------------------------
196
+ if [ "${BASH_SOURCE[0]}" = "${0:-}" ]; then
197
+ cmd="${1:-status}"
198
+ case "$cmd" in
199
+ enable) telemetry_enable ;;
200
+ disable) telemetry_disable ;;
201
+ status) telemetry_status ;;
202
+ share) telemetry_share ;;
203
+ *) echo "usage: bash lib/telemetry.sh {enable|disable|status|share}" >&2; exit 2 ;;
204
+ esac
205
+ fi
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env bash
2
+ # tier: lite
3
+ # lib/tier-check.sh — adopter tier resolution + gate.
4
+ #
5
+ # Deep module per @luminary john-ousterhout. Single interface hides the
6
+ # catalog of tier resolution methods (explicit config, probe, env override,
7
+ # safe default).
8
+ #
9
+ # Consumers: /onboard-repo SKILL body, /launch SKILL body, /longrun body,
10
+ # release harness, cold-adopter harness Check 6 (planned).
11
+ #
12
+ # tier: upstream
13
+ # install-class: dual
14
+ #
15
+ # Rules governed by:
16
+ # - .claude/rules/testing-tier-config.md (Tier 0 strict TDD)
17
+ # - .claude/rules/mechanism-fidelity.md (interface honored end to end)
18
+ #
19
+ # Anchor luminaries: ousterhout (deep module), feathers (probe pin behavior)
20
+
21
+ # Rank map for tier comparison.
22
+ _tier_rank() {
23
+ case "$1" in
24
+ lite) echo 1 ;;
25
+ standard) echo 2 ;;
26
+ pro) echo 3 ;;
27
+ *) echo 0 ;;
28
+ esac
29
+ }
30
+
31
+ # resolve_adopter_tier [repo_root]
32
+ #
33
+ # Returns one of: lite | standard | pro
34
+ # Resolution order:
35
+ # 1. BASSCLEF_TIER env override (test-only; wins over configs)
36
+ # 2. adopter.tier field in .claude/bassclef-configs.jsonc
37
+ # 3. Probe — provision-deploy-host skill present => standard;
38
+ # only lite-tagged skills present => lite
39
+ # 4. Safe default => standard
40
+ resolve_adopter_tier() {
41
+ local repo_root="${1:-$(pwd)}"
42
+ local tier=""
43
+ local source="default"
44
+
45
+ # Method 1: env override
46
+ if [ -n "${BASSCLEF_TIER:-}" ]; then
47
+ tier="$BASSCLEF_TIER"
48
+ source="env BASSCLEF_TIER"
49
+ fi
50
+
51
+ # Method 2: explicit configs field
52
+ if [ -z "$tier" ]; then
53
+ local configs="${repo_root}/.claude/bassclef-configs.jsonc"
54
+ if [ -f "$configs" ]; then
55
+ tier=$(_read_tier_from_configs "$configs" 2>/dev/null || true)
56
+ [ -n "$tier" ] && source="configs adopter.tier"
57
+ fi
58
+ fi
59
+
60
+ # Method 3: probe skills present
61
+ if [ -z "$tier" ]; then
62
+ local skills_dir="${repo_root}/.claude/skills"
63
+ if [ -d "$skills_dir/provision-deploy-host" ]; then
64
+ tier="standard"
65
+ source="probe (provision-deploy-host present)"
66
+ elif [ -d "$skills_dir/onboard-repo" ] || [ -d "$skills_dir/session-log" ]; then
67
+ # lite-tagged skills present; standard skills absent
68
+ tier="lite"
69
+ source="probe (lite skills present; standard absent)"
70
+ fi
71
+ fi
72
+
73
+ # Method 4: safe default
74
+ if [ -z "$tier" ]; then
75
+ tier="standard"
76
+ source="safe default (no configs, no skills probe hit)"
77
+ fi
78
+
79
+ # Validate tier is one of the known names
80
+ case "$tier" in
81
+ lite|standard|pro) : ;;
82
+ *)
83
+ tier="standard"
84
+ source="safe default (unknown tier '$tier' rejected)"
85
+ ;;
86
+ esac
87
+
88
+ # Debug log to stderr when requested
89
+ if [ "${DEBUG_TIER_CHECK:-0}" = "1" ]; then
90
+ echo "tier-check: tier=$tier source=$source" >&2
91
+ fi
92
+
93
+ echo "$tier"
94
+ }
95
+
96
+ # Parse tier from JSONC configs file. Strips comments then extracts adopter.tier.
97
+ _read_tier_from_configs() {
98
+ local configs="$1"
99
+ python3 - "$configs" << 'PYEOF' 2>/dev/null || true
100
+ import json
101
+ import re
102
+ import sys
103
+
104
+ path = sys.argv[1]
105
+ try:
106
+ with open(path) as f:
107
+ content = f.read()
108
+ # Strip // line comments and /* block */ comments
109
+ content = re.sub(r'/\*.*?\*/', '', content, flags=re.DOTALL)
110
+ content = re.sub(r'//[^\n]*', '', content)
111
+ d = json.loads(content)
112
+ tier = d.get('adopter', {}).get('tier', '') or d.get('tier', '')
113
+ if tier:
114
+ print(tier)
115
+ except Exception:
116
+ pass
117
+ PYEOF
118
+ }
119
+
120
+ # tier_at_least <required> [current]
121
+ #
122
+ # Returns 0 if current tier >= required, 1 otherwise.
123
+ # Current tier resolves via resolve_adopter_tier when omitted.
124
+ tier_at_least() {
125
+ local required="$1"
126
+ local current="${2:-$(resolve_adopter_tier)}"
127
+ local req_rank cur_rank
128
+ req_rank=$(_tier_rank "$required")
129
+ cur_rank=$(_tier_rank "$current")
130
+ # Unknown tier => reject
131
+ if [ "$req_rank" -eq 0 ] || [ "$cur_rank" -eq 0 ]; then
132
+ return 1
133
+ fi
134
+ if [ "$cur_rank" -ge "$req_rank" ]; then
135
+ return 0
136
+ fi
137
+ return 1
138
+ }