@elevasis/sdk 1.6.0 → 1.7.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 (28) hide show
  1. package/dist/cli.cjs +5 -5
  2. package/package.json +2 -2
  3. package/reference/claude-config/hooks/__tests__/pre-edit-vibe-gate.test.mjs +169 -0
  4. package/reference/claude-config/hooks/pre-edit-vibe-gate.mjs +128 -0
  5. package/reference/claude-config/logs/pre-edit-vibe-gate.log +23 -0
  6. package/reference/claude-config/rules/organization-os.md +55 -8
  7. package/reference/claude-config/rules/vibe.md +210 -0
  8. package/reference/claude-config/settings.json +11 -0
  9. package/reference/claude-config/skills/configure/SKILL.md +100 -0
  10. package/reference/claude-config/skills/configure/operations/codify-level-a.md +100 -0
  11. package/reference/claude-config/skills/configure/operations/codify-level-b.md +158 -0
  12. package/reference/claude-config/skills/configure/operations/customers.md +150 -0
  13. package/reference/claude-config/skills/configure/operations/features.md +163 -0
  14. package/reference/claude-config/skills/configure/operations/goals.md +147 -0
  15. package/reference/claude-config/skills/configure/operations/identity.md +133 -0
  16. package/reference/claude-config/skills/configure/operations/labels.md +128 -0
  17. package/reference/claude-config/skills/configure/operations/offerings.md +159 -0
  18. package/reference/claude-config/skills/configure/operations/roles.md +153 -0
  19. package/reference/claude-config/skills/configure/operations/techStack.md +139 -0
  20. package/reference/claude-config/skills/setup/SKILL.md +81 -32
  21. package/reference/packages/core/src/organization-model/README.md +16 -12
  22. package/reference/scaffold/core/organization-graph.mdx +1 -0
  23. package/reference/scaffold/core/organization-model.mdx +84 -19
  24. package/reference/scaffold/recipes/add-a-feature.md +1 -1
  25. package/reference/scaffold/recipes/customize-organization-model.md +5 -5
  26. package/reference/scaffold/recipes/gate-by-feature-or-admin.md +3 -3
  27. package/reference/scaffold/reference/contracts.md +115 -7
  28. package/reference/scaffold/reference/glossary.md +25 -4
@@ -0,0 +1,210 @@
1
+ ---
2
+ description: Ambient intent classifier -- routes natural-language input to 7 intent buckets without a slash command; Codify and Toggle delegate to /configure
3
+ paths:
4
+ - "**/*"
5
+ ---
6
+
7
+ # Vibe Layer
8
+
9
+ Vibe is an **ambient, always-on** intent classifier. It activates automatically whenever the user speaks in plain language -- no slash command, no activation phrase, no special syntax. Every natural-language message passes through vibe classification before the agent acts.
10
+
11
+ This rule applies to all sessions inside external projects. It does NOT apply in the monorepo (ambient routing is off there by default).
12
+
13
+ ## What Vibe Is
14
+
15
+ Vibe is the translation layer between the user's natural language and the correct agent action. The user describes reality -- "we track deals by Shopify platform", "I'm stuck on this task", "what should I work on next" -- and vibe determines which of the seven intent types the message represents. The agent then routes to the right behavior without the user ever knowing the classification happened.
16
+
17
+ Vibe coders (non-technical builders) are the primary audience. They build by describing. They never memorize commands, IDs, or schema. The ambient layer closes the gap between what they say and what the system can act on.
18
+
19
+ ## The Seven Intent Types
20
+
21
+ ### 1. Capture
22
+
23
+ The user wants to record something new -- a task, a note, a piece of information that should persist.
24
+
25
+ **Recognize by:** action verbs like "add", "create", "remember", "track", "log", "note down", "write down", combined with a thing to record.
26
+
27
+ **Fixture examples:**
28
+
29
+ | Input | Why it's Capture |
30
+ | ------------------------------------------------- | ------------------------------------------- |
31
+ | "Add a task to follow up with the Shopify client" | Explicit "add a task" with a described item |
32
+ | "Remember to run the campaign report on Friday" | "Remember to" signals something to persist |
33
+ | "Track this conversation as a deal note" | Explicit "track" with a described artifact |
34
+
35
+ **Agent action:** draft the capture in plain language, confirm with the user, then execute via `elevasis-sdk project:*` commands. Never write without confirmation.
36
+
37
+ ### 2. Query
38
+
39
+ The user wants to know something about current state -- task priorities, what is pending, what is running, what failed.
40
+
41
+ **Recognize by:** questions about the current list, status, or queue of things. Includes both static-model queries ("what features are on?") and runtime-entity queries ("what's pending in the queue?"). Route Query to static-model sources (org model, features config) or runtime sources (operations domain) based on the referenced entity.
42
+
43
+ **Fixture examples:**
44
+
45
+ | Input | Why it's Query |
46
+ | --------------------------------------------- | ------------------------------------------- |
47
+ | "What should I work on next?" | Asking for prioritized task list |
48
+ | "What's pending in the HITL queue?" | Runtime-entity query about operations state |
49
+ | "What features are enabled for this project?" | Static-model query about features config |
50
+
51
+ **Agent action:** read the relevant source (org model, `prj_tasks`, operations domain as available) and narrate the answer in plain language. No writes.
52
+
53
+ ### 3. Describe
54
+
55
+ The user wants the agent to explain something -- a scope, an entity, a concept within the project.
56
+
57
+ **Recognize by:** "what is", "what does", "tell me about", "explain", "where am I", "what's going on", "describe", "show me" without an action intent attached.
58
+
59
+ **Fixture examples:**
60
+
61
+ | Input | Why it's Describe |
62
+ | ------------------------------------------ | ----------------------------------------------------- |
63
+ | "What's going on with the ZentaraHQ deal?" | Asking for a plain-language description of an entity |
64
+ | "Tell me about the CRM feature" | Asking the agent to narrate what a model element does |
65
+ | "Where am I in this project?" | Asking for current scope narration |
66
+
67
+ **Agent action:** read the relevant org-model label, entity, or scope. Narrate in plain language using label fields from the model -- never invent vocabulary not present in the model. Phase-1 scope covers Model, Features, and Foundations layers only.
68
+
69
+ ### 4. Transition
70
+
71
+ The user wants to change the status of a task or entity.
72
+
73
+ **Recognize by:** single-word or short-phrase state signals -- "done", "finished", "complete", "blocked", "stuck", "waiting", "in review", "cancelled" -- applied to a current task or named entity.
74
+
75
+ **Fixture examples:**
76
+
77
+ | Input | Why it's Transition |
78
+ | --------------------------------------------- | ------------------------------------------- |
79
+ | "Done with the proposal draft" | "Done" + named artifact = status transition |
80
+ | "Stuck -- blocked waiting on client feedback" | "Stuck" + reason = blocked transition |
81
+ | "Mark the onboarding task as complete" | Explicit status-change vocabulary |
82
+
83
+ **Agent action:** identify the task or entity being transitioned, confirm the new status with the user, then apply the transition via `elevasis-sdk project:task:save` or equivalent. Never auto-transition without confirmation if the target entity is ambiguous.
84
+
85
+ ### 5. Navigate
86
+
87
+ The user wants to shift focus -- to a different task, project, feature, or layer of the model.
88
+
89
+ **Recognize by:** focus-shift vocabulary -- "focus on", "let's look at", "switch to", "back to", "move to", "open", "go to" -- followed by a scope target.
90
+
91
+ **Fixture examples:**
92
+
93
+ | Input | Why it's Navigate |
94
+ | -------------------------------------------- | --------------------------------------------------- |
95
+ | "Let's focus on the onboarding flow for now" | "Focus on" + scope target |
96
+ | "Switch to the Shopify integration project" | "Switch to" = navigate to a different project scope |
97
+ | "Back to the CRM tasks" | "Back to" = return to a prior scope |
98
+
99
+ **Agent action:** update the active scope in `prj_tasks.resume_context` (current project + task pointer), then narrate the new scope in plain language so the user knows where they are.
100
+
101
+ ### 6. Codify
102
+
103
+ The user describes organizational reality that is not yet expressed in the model -- industry type, entity kinds, custom attributes, renamed stages, domain vocabulary.
104
+
105
+ **Recognize by:** declarative "we are" / "we use" / "we track" statements, repeated attribute mentions (second time the same attribute appears), or explicit "add a type / add a field / model X as Y" requests.
106
+
107
+ **Fixture examples:**
108
+
109
+ | Input | Why it's Codify |
110
+ | -------------------------------------------------------------------------------- | -------------------------------------------------------- |
111
+ | "We're an e-commerce company -- all our deals come from Shopify or Amazon" | Declares industry + platform attributes not yet in model |
112
+ | "We track deal stage as discovery, scoping, proposal, closed" | Describes custom CRM stages that should replace defaults |
113
+ | "Add a project type called 'retainer' with monthly billing and a contract field" | Explicit request to add a new entity extension |
114
+
115
+ **Agent action:** delegate immediately to `/configure`. Do not attempt the ceremony yourself. Invoke with the relevant domain: `/configure crm` for deal/contact changes, `/configure projects` for project types, `/configure features` for feature toggles. Plain-language summary of what was detected is acceptable before delegating, but the actual draft-confirm-write ceremony belongs to `/configure`.
116
+
117
+ This routing applies to both codify levels (decision #21 -- Codify ceremony delegated to `/configure`):
118
+
119
+ - **Level A** (config-only edits to `organization-model.ts`, feature toggles, label renames): delegate to `/configure <domain>` immediately.
120
+ - **Level B** (new Zod extension files in `foundations/config/extensions/`): also delegate to `/configure <domain>`; `/configure` gates Level B to explicit user asks before scaffolding a new TS file.
121
+
122
+ Vibe detects the intent and delegates in both cases. It does not run either pipeline itself.
123
+
124
+ Heuristics for when to propose codification (passed to `/configure` as context):
125
+
126
+ - First mention of a new attribute: note to `resume_context`, do not propose yet
127
+ - Second mention OR explicit declaration ("we're ecom"): propose extension
128
+ - Explicit ask ("track ecom deals separately"): propose immediately with fuller scope
129
+ - Attribute appearing across 3+ tasks: propose adding field to existing extension
130
+
131
+ ### 7. Toggle
132
+
133
+ The user wants to enable or disable a feature.
134
+
135
+ **Recognize by:** feature-control vocabulary -- "turn on", "enable", "disable", "turn off", "activate", "deactivate" -- followed by a feature name or description.
136
+
137
+ **Fixture examples:**
138
+
139
+ | Input | Why it's Toggle |
140
+ | ------------------------------- | --------------------------------------------- |
141
+ | "Turn on the lead-gen feature" | Explicit "turn on" + feature name |
142
+ | "Disable monitoring for now" | "Disable" + feature reference |
143
+ | "We don't use SEO, turn it off" | Declarative + "turn it off" = feature disable |
144
+
145
+ **Agent action:** delegate to `/configure features`. The ceremony (confirm + edit `foundations/config/organization-model.ts` + typecheck) belongs to `/configure`, not to the ambient rule.
146
+
147
+ ## Quick Reference Table
148
+
149
+ | Intent | Trigger signal | Routed to |
150
+ | ---------- | --------------------------------------------------------------- | ------------------------------------------ |
151
+ | Capture | "add", "remember", "track", "log" + a thing | Agent -- draft + confirm + `project:*` CLI |
152
+ | Query | "what's next", "what's pending", "what failed", "what features" | Agent -- read + narrate |
153
+ | Describe | "what is", "tell me about", "explain", "where am I" | Agent -- narrate from org model labels |
154
+ | Transition | "done", "stuck", "blocked", "finished", "complete" | Agent -- confirm + `project:task:save` |
155
+ | Navigate | "focus on", "switch to", "back to", "look at" | Agent -- update scope + narrate |
156
+ | Codify | "we are X", "we track Y", repeated attribute, "add type/field" | Delegate to `/configure \<domain>` |
157
+ | Toggle | "enable", "disable", "turn on/off" + feature | Delegate to `/configure features` |
158
+
159
+ ## Source of Truth for Plain Language
160
+
161
+ All plain-language labels come from the OrganizationModel itself -- never from hardcoded strings in this rule file. Every status, entity kind, and layer name in the model carries an inline `label` field (e.g., `{ id: 'revision_requested', label: 'changes needed', semanticClass: 'blocked' }`). When narrating state or confirming an action, read the label from the model and use it verbatim. Do not invent synonyms or fallback vocabulary.
162
+
163
+ The unified manifest (delivered via `@elevasis/core/organization-model`) is the canonical vocabulary surface. Vibe classifies against it -- capabilities, features, statuses, operations entities, and resource kinds are all discoverable from the manifest without hardcoding.
164
+
165
+ ## Ambiguous Intent
166
+
167
+ When the user's input does not clearly map to one of the seven types, ask one clarifying question. Do not guess. Do not apply a precedence rule. Do not route to the "closest" intent.
168
+
169
+ Format: a single neutral question that presents the two (or three) plausible intents as options and asks which the user means.
170
+
171
+ Example: "That could be a note to capture or a status update on the current task -- which did you mean?"
172
+
173
+ Never ask more than one question per ambiguous input. If the user's reply is still ambiguous, ask once more, then surface the options explicitly.
174
+
175
+ ## Enforcement and Trust Marker
176
+
177
+ Raw edits to `foundations/config/organization-model.ts` and `foundations/config/extensions/*.ts` are blocked by the `pre-edit-vibe-gate.mjs` PreToolUse hook unless the `VIBE_APPROVED=1` environment variable is set.
178
+
179
+ This variable is set automatically by `/configure` after the user confirms a codify or toggle ceremony. It is subshell-scoped -- no filesystem state to clean up. Power users who invoke `/configure` directly get the marker without triggering the hook error.
180
+
181
+ If you encounter the hook block outside of a `/configure` ceremony, do not attempt to bypass it. Surface the message to the user and suggest running `/configure \<domain>` to proceed through the approved ceremony.
182
+
183
+ ## Classifier Threshold
184
+
185
+ Default threshold: `balanced`.
186
+
187
+ The threshold controls how aggressively the classifier proposes codification from ambiguous signals:
188
+
189
+ - `strict` -- only explicit declarations or repeat mentions trigger codify proposals
190
+ - `balanced` -- second mention OR explicit declaration triggers; default
191
+ - `loose` -- first strong signal triggers a proposal
192
+
193
+ Override per project in `foundations/config/organization-model.ts` under `vibe.classifierThreshold`. The override is merge-aware (Tier 2 sync) and will not be overwritten by template sync operations.
194
+
195
+ ## Phase-1 Scope
196
+
197
+ This rule covers Phase 1 of the vibe layer rollout. The layers the ambient classifier can narrate and codify in Phase 1 are:
198
+
199
+ - Layer 1 (Model): narrate schema shape, propose codification edits via `/configure`
200
+ - Layer 4 (Features): describe which features are on/off, propose enabling one via `/configure`
201
+ - Layer 7 (Foundations): explain and edit `organization-model.ts` and `extensions/` via `/configure`
202
+
203
+ Layers 2 (Public API), 3 (UI Shell Runtime), 5 (Toolkit), and 6 (Graph) require runtime read APIs that are not yet available. Do not attempt to narrate or classify against those layers in Phase 1. If the user's input clearly references one of those layers, acknowledge the scope and explain that full support arrives in a later phase.
204
+
205
+ ## What Vibe Is Not
206
+
207
+ - Vibe is not a slash command. There is no `/vibe` invocation (decision #19 -- ambient rule, not a skill or command).
208
+ - Vibe is not a skill. It lives in this rule file + CLAUDE.md + the PreToolUse hook -- not in `.claude/skills/`.
209
+ - Vibe does not own the codify ceremony. `/configure` owns draft, confirm, write, and typecheck for both Level A and Level B codify pipelines (decision #21 -- Codify ceremony delegated to `/configure`). Vibe detects intent and hands off.
210
+ - Vibe is not active in the monorepo. If working inside the monorepo (not an `external/` project), this ambient routing does not apply.
@@ -4,6 +4,17 @@
4
4
  "command": "node .claude/scripts/statusline-command.js"
5
5
  },
6
6
  "hooks": {
7
+ "PreToolUse": [
8
+ {
9
+ "matcher": "Write|Edit|MultiEdit",
10
+ "hooks": [
11
+ {
12
+ "type": "command",
13
+ "command": "node .claude/hooks/pre-edit-vibe-gate.mjs"
14
+ }
15
+ ]
16
+ }
17
+ ],
7
18
  "PostToolUse": [
8
19
  {
9
20
  "matcher": "Write|Edit|MultiEdit",
@@ -0,0 +1,100 @@
1
+ ---
2
+ name: configure
3
+ description: "Recurring organization model editor — layered QA flow across identity, customers, offerings, roles, goals, and techStack. Idempotent, confirm-before-overwrite. Codifies changes to foundations/config/organization-model.ts with runtime validation gate."
4
+ argument-hint: "[identity|customers|offerings|roles|goals|techStack|features|labels]"
5
+ context: fork
6
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
7
+ ---
8
+
9
+ # Configure
10
+
11
+ Recurring, safe-to-re-run org model editor for external projects. Reads the organization model as the single source of truth and guides the user through structured updates — either across all domains in a layered flow, or targeted at a single domain by argument.
12
+
13
+ **Usage:**
14
+
15
+ - `/configure` -- Layered flow: walks identity → customers → offerings → roles → goals → techStack in sequence
16
+ - `/configure identity` -- Target only the identity domain
17
+ - `/configure customers` -- Target only the customers domain
18
+ - `/configure offerings` -- Target only the offerings domain
19
+ - `/configure roles` -- Target only the roles domain
20
+ - `/configure goals` -- Target only the goals domain
21
+ - `/configure techStack` -- Target only the techStack domain (resource mapping extensions)
22
+ - `/configure features` -- Enable, disable, or add features; Level A (defaults) or Level B (new extension TS files)
23
+ - `/configure labels` -- Edit inline display labels on enum entries (statuses, stages, categories)
24
+
25
+ **Distinction from `/org-os manage`:** `/configure` edits structural organizational reality (who the org is, who it serves, what it offers). `/org-os manage` controls feature gating (what platform capabilities are enabled). Use `/configure` for org-model content; use `/org-os manage` for feature flags.
26
+
27
+ **Distinction from `/setup`:** `/setup` is for first-time bootstrap (placeholder replacement, dependency install, build verification). `/configure` is for recurring org-model updates. After first run, `/setup` delegates here.
28
+
29
+ ---
30
+
31
+ ## Goal
32
+
33
+ Keep `foundations/config/organization-model.ts` accurate and validated. Every edit proposed by this skill ends with `resolveOrganizationModel()` + `OrganizationModelSchema.parse()` confirming the merged result is valid — and a full TypeScript type-check via `pnpm -C operations check-types` to catch static errors. If validation fails, the change is rolled back.
34
+
35
+ ---
36
+
37
+ ## Pre-Flight: Read the Current Model
38
+
39
+ Before any domain flow, read the current organization model adapter:
40
+
41
+ ```
42
+ Read("foundations/config/organization-model.ts")
43
+ ```
44
+
45
+ This is the single source of truth. All proposals must start from what is currently in this file, not from stale context.
46
+
47
+ ---
48
+
49
+ ## Mode Detection
50
+
51
+ - **No argument:** run the layered flow (all domains, one at a time in the order below).
52
+ - **Argument matches a domain name** (`identity`, `customers`, `offerings`, `roles`, `goals`, `techStack`): run only that domain's operation.
53
+ - **Argument is `features`:** run the features operation.
54
+ - **Argument is `labels`:** run the labels operation.
55
+ - **Argument is unrecognized:** ask the user which domain they meant.
56
+
57
+ ---
58
+
59
+ ## Layered Flow (Default)
60
+
61
+ When run without an argument, execute operations in this order. After each domain, ask "Ready to move on to [next domain]?" and pause for confirmation. The user can stop after any domain — partial updates are valid.
62
+
63
+ 1. `identity` -- EXECUTE `.claude/skills/configure/operations/identity.md`
64
+ 2. `customers` -- EXECUTE `.claude/skills/configure/operations/customers.md`
65
+ 3. `offerings` -- EXECUTE `.claude/skills/configure/operations/offerings.md`
66
+ 4. `roles` -- EXECUTE `.claude/skills/configure/operations/roles.md`
67
+ 5. `goals` -- EXECUTE `.claude/skills/configure/operations/goals.md`
68
+ 6. `techStack` -- EXECUTE `.claude/skills/configure/operations/techStack.md`
69
+
70
+ ---
71
+
72
+ ## Operations
73
+
74
+ | Operation | File | Description |
75
+ | ---------------- | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
76
+ | `identity` | `.claude/skills/configure/operations/identity.md` | Legal identity, mission, vision, industry, geography, timezone, business hours |
77
+ | `customers` | `.claude/skills/configure/operations/customers.md` | Customer segments with jobs-to-be-done, pains, gains, firmographics, value props |
78
+ | `offerings` | `.claude/skills/configure/operations/offerings.md` | Products and services with pricing model, price, currency, and segment/feature refs |
79
+ | `roles` | `.claude/skills/configure/operations/roles.md` | Role chart with responsibilities, reporting lines, and role holders |
80
+ | `goals` | `.claude/skills/configure/operations/goals.md` | Organizational goals with period and measurable outcomes |
81
+ | `techStack` | `.claude/skills/configure/operations/techStack.md` | External integration registry — platform, purpose, credential status, system-of-record flag |
82
+ | `features` | `.claude/skills/configure/operations/features.md` | Enable/disable features or add new ones (Level A config edit vs Level B extension file) |
83
+ | `labels` | `.claude/skills/configure/operations/labels.md` | Edit inline display labels on enum entries (statuses, stages, categories) |
84
+ | `codify-level-a` | `.claude/skills/configure/operations/codify-level-a.md` | Codify pipeline for config-only edits (Level A): propose, confirm, write, validate, rollback |
85
+ | `codify-level-b` | `.claude/skills/configure/operations/codify-level-b.md` | Codify pipeline for new extension TS files (Level B): scaffold file, propose, confirm, write, validate, rollback |
86
+
87
+ ---
88
+
89
+ ## Validation Gate (MANDATORY)
90
+
91
+ Every codify operation (Level A or B) must end with this validation sequence before reporting success:
92
+
93
+ 1. **TypeScript type-check:** `pnpm -C operations check-types` (catches static errors in the generated extension files)
94
+ 2. **Runtime schema parse:** confirm that the adapter calls `resolveOrganizationModel()` and `OrganizationModelSchema.parse()` is satisfied (Zod cross-refs, enum values, required fields)
95
+
96
+ If either fails: roll back the file to its pre-edit state and report the error to the user. See `codify-level-a.md` and `codify-level-b.md` for the full rollback procedure.
97
+
98
+ ---
99
+
100
+ **Last Updated:** 2026-04-20
@@ -0,0 +1,100 @@
1
+ # Codify Pipeline: Level A (Config-Only Edits)
2
+
3
+ Level A is the codify pipeline for changes that land exclusively in
4
+ `foundations/config/organization-model.ts`. No new TypeScript files are created. The entire
5
+ ceremony is: snapshot current file, propose the edit, write the edit, validate, and roll back on
6
+ failure.
7
+
8
+ This pipeline is called by domain operations (identity, customers, offerings, roles, goals,
9
+ techStack, features, labels) after the user has confirmed the proposed change. The caller provides
10
+ the specific field/block being changed and the proposed new value.
11
+
12
+ ---
13
+
14
+ ## Pipeline
15
+
16
+ ### Step 1: Snapshot
17
+
18
+ Before any write, read `foundations/config/organization-model.ts` and keep the full file content
19
+ in memory as the rollback snapshot. Do not write any file during this step.
20
+
21
+ ```
22
+ Read("foundations/config/organization-model.ts")
23
+ -- store as ROLLBACK_SNAPSHOT
24
+ ```
25
+
26
+ ### Step 2: Apply the edit
27
+
28
+ Use the Edit tool to apply the caller's proposed change to
29
+ `foundations/config/organization-model.ts`.
30
+
31
+ Rules for the edit:
32
+
33
+ - Edit only the specific field or block the caller specified. Do not reformat or restructure
34
+ unrelated sections.
35
+ - Preserve all other keys in `defineOrganizationModel({...})` exactly as they are.
36
+ - Maintain the existing code style (trailing commas, quote style, indentation) of the file.
37
+ - If the target field does not yet exist in the adapter call, add it as a new property in the
38
+ appropriate position (following the declared domain order in the schema).
39
+
40
+ ### Step 3: TypeScript type-check
41
+
42
+ Run the type-check for the operations package:
43
+
44
+ ```bash
45
+ pnpm -C operations check-types
46
+ ```
47
+
48
+ Capture stdout and stderr. If the command exits non-zero, proceed to Step 5 (rollback).
49
+
50
+ ### Step 4: Runtime schema validation
51
+
52
+ Confirm that the adapter's output passes `OrganizationModelSchema.parse()`. The adapter calls
53
+ `resolveOrganizationModel()` internally, which merges defaults with overrides and then parses the
54
+ result. A successful `check-types` pass is strong evidence that the schema is valid, but
55
+ cross-reference checks (segment ID refs in offerings, role reporting refs, period ordering in
56
+ goals) are runtime-only.
57
+
58
+ If the project exposes a validation script (e.g. `pnpm -C operations check`), run that too:
59
+
60
+ ```bash
61
+ pnpm -C operations check
62
+ ```
63
+
64
+ If either validation step fails, proceed to Step 5 (rollback).
65
+
66
+ ### Step 5: Rollback (on failure only)
67
+
68
+ If Step 3 or Step 4 failed:
69
+
70
+ 1. Write the ROLLBACK_SNAPSHOT content back to `foundations/config/organization-model.ts`
71
+ verbatim (use the Write tool with the exact snapshot content).
72
+ 2. Confirm the file has been restored by checking that the content matches the snapshot.
73
+ 3. Return the error message to the caller.
74
+
75
+ The caller is responsible for reporting the rollback to the user.
76
+
77
+ ### Step 6: Success signal
78
+
79
+ If Steps 3 and 4 both passed, return a success signal to the caller with:
80
+
81
+ - The fields changed
82
+ - `Type-check: PASS`
83
+ - `Schema validation: PASS`
84
+
85
+ The caller formats and presents the final report.
86
+
87
+ ---
88
+
89
+ ## Caller Contract
90
+
91
+ Callers must provide before invoking this pipeline:
92
+
93
+ - **Target file:** always `foundations/config/organization-model.ts`
94
+ - **Target block:** the specific domain key or sub-key being changed (e.g. `identity`,
95
+ `customers.segments`, `roles.roles`, `resourceMappings[id="rm-hubspot"].techStack`)
96
+ - **Proposed value:** the new TypeScript literal to write for that block
97
+ - **Confirmed:** the user has already said yes to the proposed change
98
+
99
+ This pipeline does not ask the user any questions. All confirmation happens in the domain
100
+ operation before this pipeline is invoked.
@@ -0,0 +1,158 @@
1
+ # Codify Pipeline: Level B (New Extension TypeScript Files)
2
+
3
+ Level B is the codify pipeline for changes that require creating a new TypeScript file under
4
+ `foundations/config/extensions/`. This pipeline is used when the user wants to add a custom
5
+ feature, a custom entity type, or any structural addition that cannot be expressed as a simple
6
+ field override in `foundations/config/organization-model.ts`.
7
+
8
+ Level B is **only offered when the user explicitly asks** for something that requires a new file.
9
+ Never silently escalate from Level A to Level B. If Level A is sufficient, use it.
10
+
11
+ ---
12
+
13
+ ## When Level B applies
14
+
15
+ - Adding a custom feature that does not exist in the platform defaults (new `FeatureSchema` entry
16
+ with a custom ID, manifest wiring, and route references)
17
+ - Adding a custom entity extension (new Zod schema extending a base entity type)
18
+ - Any structural addition the caller's domain operation has determined cannot be expressed as a
19
+ field value in the existing adapter
20
+
21
+ The calling operation (e.g. `features.md`) is responsible for deciding when Level B is needed
22
+ and for confirming the intent with the user before invoking this pipeline.
23
+
24
+ ---
25
+
26
+ ## Pipeline
27
+
28
+ ### Step 1: Snapshot all files that will be touched
29
+
30
+ Before any write, read and snapshot:
31
+
32
+ 1. `foundations/config/organization-model.ts` (always touched for wiring)
33
+ 2. The target extension file path (if it already exists -- confirm overwrite with user)
34
+
35
+ ```
36
+ Read("foundations/config/organization-model.ts") -- store as ROLLBACK_ADAPTER
37
+ Read("foundations/config/extensions/{target}.ts") -- store as ROLLBACK_EXTENSION (if exists)
38
+ ```
39
+
40
+ The target extension file path follows the naming convention:
41
+ `foundations/config/extensions/{kebab-case-feature-id}.ts`
42
+
43
+ ### Step 2: Scaffold the extension file
44
+
45
+ Create `foundations/config/extensions/{id}.ts` using the Write tool.
46
+
47
+ The file shape depends on the extension type:
48
+
49
+ **Custom feature (most common Level B case):**
50
+
51
+ ```typescript
52
+ /**
53
+ * {Feature label} feature extension.
54
+ * Registered in foundations/config/organization-model.ts.
55
+ */
56
+ import type { OrganizationModelFeature } from '@elevasis/core/organization-model'
57
+
58
+ export const {FEATURE_CONST}: OrganizationModelFeature = {
59
+ id: '{feature-id}',
60
+ label: '{Feature Label}',
61
+ description: '{optional description}',
62
+ enabled: true,
63
+ entityIds: [],
64
+ surfaceIds: [],
65
+ resourceIds: [],
66
+ capabilityIds: [],
67
+ }
68
+ ```
69
+
70
+ Replace `{FEATURE_CONST}` with the SCREAMING_SNAKE_CASE version of the feature ID
71
+ (e.g. `CLIENT_PORTAL_FEATURE`).
72
+
73
+ The caller provides the exact field values based on what the user confirmed.
74
+
75
+ ### Step 3: Wire the extension into the adapter
76
+
77
+ Edit `foundations/config/organization-model.ts` to:
78
+
79
+ 1. Import the new constant from the extension file.
80
+ 2. Add it to the `features` array in the `defineOrganizationModel({...})` call.
81
+
82
+ Example import addition:
83
+
84
+ ```typescript
85
+ import { CLIENT_PORTAL_FEATURE } from './extensions/client-portal'
86
+ ```
87
+
88
+ Example features array addition:
89
+
90
+ ```typescript
91
+ features: [
92
+ ...existingFeatures,
93
+ CLIENT_PORTAL_FEATURE,
94
+ ],
95
+ ```
96
+
97
+ ### Step 4: TypeScript type-check
98
+
99
+ ```bash
100
+ pnpm -C operations check-types
101
+ ```
102
+
103
+ Capture stdout and stderr. If the command exits non-zero, proceed to Step 6 (rollback).
104
+
105
+ ### Step 5: Runtime schema validation
106
+
107
+ ```bash
108
+ pnpm -C operations check
109
+ ```
110
+
111
+ If either check fails, proceed to Step 6 (rollback).
112
+
113
+ ### Step 6: Rollback (on failure only)
114
+
115
+ If Step 4 or Step 5 failed:
116
+
117
+ 1. Restore `foundations/config/organization-model.ts` from ROLLBACK_ADAPTER.
118
+ 2. If the extension file did not previously exist, delete it. If it previously existed, restore
119
+ from ROLLBACK_EXTENSION.
120
+ 3. Re-run `pnpm -C operations check-types` to confirm the restore is clean. If the restore
121
+ itself fails type-check, report both the original error and the restore state to the user --
122
+ do not silently leave the project in a broken state.
123
+ 4. Return the error message to the caller.
124
+
125
+ ### Step 7: Success signal
126
+
127
+ If Steps 4 and 5 both passed, return a success signal to the caller with:
128
+
129
+ - Extension file path created
130
+ - Adapter wiring changes (import + features array entry)
131
+ - `Type-check: PASS`
132
+ - `Schema validation: PASS`
133
+
134
+ The caller formats and presents the final report to the user.
135
+
136
+ ---
137
+
138
+ ## Caller Contract
139
+
140
+ Callers must provide before invoking this pipeline:
141
+
142
+ - **Extension file path:** `foundations/config/extensions/{id}.ts`
143
+ - **Extension file content:** the full TypeScript content for the new file
144
+ - **Adapter changes:** the exact import line and features-array addition to write into the adapter
145
+ - **Confirmed:** the user has already said yes to the proposed change and explicitly requested
146
+ a new extension file
147
+
148
+ This pipeline does not ask the user any questions. All confirmation and escalation decisions
149
+ happen in the domain operation before this pipeline is invoked.
150
+
151
+ ---
152
+
153
+ ## Constraint: Extension files are Tier 3 (never synced)
154
+
155
+ Files under `foundations/config/extensions/` are Tier 3 -- project-specific, never overwritten
156
+ by `/external sync`. This means custom features and entity extensions survive template upgrades
157
+ automatically. Do not put platform-default overrides in extension files; those belong directly in
158
+ `foundations/config/organization-model.ts` (Tier 2, merge-aware).