ochreui 0.0.0-stage → 0.0.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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -2
  3. package/cli/ochreui.mjs +502 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +373 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2079 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ochre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://ochreui.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ochreui/ochre/main/.github/assets/logo-dark.svg">
5
+ <img src="https://raw.githubusercontent.com/ochreui/ochre/main/.github/assets/logo-light.svg" alt="Ochre" height="56">
6
+ </picture>
7
+ </a>
8
+ </p>
2
9
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
10
+ <h3 align="center">Angular components for AI products.</h3>
11
+
12
+ <p align="center">
13
+ Agent runs, tool calls, chat, inputs, menus and motion.<br>
14
+ One file each, copied into your app. Yours to keep.
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="https://www.npmjs.com/package/ochreui"><img src="https://img.shields.io/npm/v/ochreui?label=npm&color=4f46e5" alt="npm version"></a>
19
+ <img src="https://img.shields.io/badge/Angular-22%2B-4f46e5" alt="Angular 22 or later">
20
+ <img src="https://img.shields.io/badge/dependencies-0-4f46e5" alt="Zero dependencies">
21
+ <a href="https://github.com/ochreui/ochre/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-4f46e5" alt="MIT license"></a>
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://ochreui.dev"><strong>Website</strong></a> ·
26
+ <a href="https://ochreui.dev/components">Components</a> ·
27
+ <a href="https://ochreui.dev/docs/installation">Installation</a> ·
28
+ <a href="https://ochreui.dev/docs/ai">Using with AI</a> ·
29
+ <a href="https://ochreui.dev/docs/changelog">Changelog</a>
30
+ </p>
31
+
32
+ <br>
33
+
34
+ <p align="center">
35
+ <a href="https://ochreui.dev/components">
36
+ <picture>
37
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ochreui/ochre/main/.github/assets/preview-dark.png">
38
+ <img src="https://raw.githubusercontent.com/ochreui/ochre/main/.github/assets/preview-light.png" alt="Progress Tracker, Message Actions, Notification Stack, Decision Inbox, Comment Thread and Smart Recommendation" width="880">
39
+ </picture>
40
+ </a>
41
+ </p>
42
+
43
+ <br>
44
+
45
+ ## Get started
46
+
47
+ ```bash
48
+ npx ochreui@latest add button
49
+ ```
50
+
51
+ That's the whole setup. The first run adds the design tokens (`ochre.css`) to `angular.json`, then writes the component into your app:
52
+
53
+ ```
54
+ src/app/ui/
55
+ └── button.ts ← template, styles and logic in one file. It's your code now.
56
+ ```
57
+
58
+ Import it like anything else you wrote:
59
+
60
+ ```ts
61
+ import { Component } from '@angular/core';
62
+ import { UiButton } from './ui/button';
63
+
64
+ @Component({
65
+ selector: 'app-save',
66
+ imports: [UiButton],
67
+ template: `<button uiButton variant="primary">Save changes</button>`,
68
+ })
69
+ export class Save {}
70
+ ```
71
+
72
+ ## Why Ochre
73
+
74
+ | | |
75
+ |---|---|
76
+ | **Built for AI products** | Thinking states, tool calls, decision inboxes, message actions and progress, next to the everyday controls every app needs. |
77
+ | **You own the code** | No black box in `node_modules`. Each component is one readable file you can change line by line. |
78
+ | **Modern Angular only** | Standalone, signals (`input()`, `model()`, `output()`), zoneless and SSR ready. Works with signal forms, reactive forms and `ngModel`. |
79
+ | **Zero dependencies** | No Tailwind, no CDK, no icon package. Each file imports only `@angular/*`. |
80
+ | **One set of tokens** | Every color, size and radius is a `--ui-*` variable. Change the accent once and the whole app follows, in light and dark. |
81
+ | **Accessible** | Full keyboard support, ARIA patterns, visible focus, forced colors, reduced motion and translatable labels. |
82
+
83
+ ## Your coding agent already knows it
84
+
85
+ Connect the Ochre MCP server and Claude Code, Cursor, VS Code or Codex can search the library, read a component's full API and add it for you.
86
+
87
+ ```bash
88
+ claude mcp add --transport http ochre https://ochreui.dev/api/mcp
89
+ ```
90
+
91
+ No account needed. There's also an agent skill (`npx ochreui@latest add skill`) and [`llms.txt`](https://ochreui.dev/llms.txt) for tools without MCP. Setup for every editor: [Using with AI](https://ochreui.dev/docs/ai).
92
+
93
+ ## What's inside
94
+
95
+ **75 free items**, each with a live demo, keyboard map and API reference on [ochreui.dev](https://ochreui.dev/components).
96
+
97
+ | | |
98
+ |---|---|
99
+ | **AI and chat** | Thinking Loader · Tool Call Card · Message Actions · Comment Thread · Decision Inbox · Change Summary · Smart Recommendation |
100
+ | **Inputs** | Text Field · Text Area · Number Input · OTP Input · Select · Checkbox · Switch · Rating · Tag Input · Form Field · Filter Menu · Date Picker · Time Picker · Color Picker |
101
+ | **Buttons** | Button · Icon Button |
102
+ | **Menus and overlays** | Dropdown Menu · Context Menu · Popover · Hover Card · Tooltip · Dialog · Profile Menu |
103
+ | **Layout and data** | Card · Tree View · Scroll Area · Resizable · Avatar · Badge · Separator · Code Block · Kbd · Breadcrumb · Pagination · Segmented Control · Toggle Group |
104
+ | **Feedback** | Progress Tracker · Notification Stack · Empty State · Tips Panel · Skeleton · Spinner · Reaction Bar · Email Draft |
105
+ | **Motion** | Grid Background · Number Ticker · Shimmer Loader · Text Reveal |
106
+ | **Blocks** | Logo Marquee · Testimonial Wall |
107
+ | **Illustrations** | 18 small animated scenes for feature cards, empty states and landing pages |
108
+
109
+ ## Make it yours
110
+
111
+ ```css
112
+ /* src/styles/theme.css, loaded after ochre.css */
113
+ :root {
114
+ --ui-accent: light-dark(#0f766e, #2dd4bf);
115
+ --ui-accent-hover: light-dark(#115e59, #5eead4);
116
+ --ui-font-sans: 'Inter', system-ui, sans-serif;
117
+ --ui-radius-md: 10px;
118
+ }
119
+ ```
120
+
121
+ Dark mode follows the system, or set `data-ui-theme="dark"` on `<html>`. More in [Theming](https://ochreui.dev/docs/theming) and the [design system](https://ochreui.dev/design-system).
122
+
123
+ ## CLI
124
+
125
+ | Command | What it does |
126
+ |---|---|
127
+ | `npx ochreui@latest add <name…>` | Copy components into your app (sets Ochre up the first time) |
128
+ | `npx ochreui@latest list` | Every component you can add |
129
+ | `npx ochreui@latest diff <name>` | What changed since your copy |
130
+ | `npx ochreui@latest update [name…]` | Update the copies you haven't edited (`--force` replaces edited ones) |
131
+ | `npx ochreui@latest add skill` | Add the Ochre skill for Claude Code and other agents |
132
+
133
+ Options: `--project`, `--path`, `--dry-run`, `--overwrite`, `--cwd`. Details in [Installation](https://ochreui.dev/docs/installation).
134
+
135
+ ## Ochre Pro
136
+
137
+ Everything in this repo is free and MIT, and stays that way. [Ochre Pro](https://ochreui.dev/pricing) adds Pro components, full app screens and blocks for a one-time payment, installed with the same CLI.
138
+
139
+ ## Contributing
140
+
141
+ Bug reports, component ideas and small fixes are welcome. See [CONTRIBUTING.md](https://github.com/ochreui/ochre/blob/main/CONTRIBUTING.md).
142
+
143
+ If Ochre saves you time, a star helps other Angular developers find it.
144
+
145
+ ## License
146
+
147
+ [MIT](https://github.com/ochreui/ochre/blob/main/LICENSE). Use it in personal, client and commercial work. Every installed file starts with a one-line notice: keep it in your copies.
148
+
149
+ <br>
150
+
151
+ <p align="center"><sub>Made in Morocco 🇲🇦</sub></p>
@@ -0,0 +1,502 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { homedir } from 'node:os';
5
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const REGISTRY = process.env.OCHREUI_REGISTRY ?? join(dirname(fileURLToPath(import.meta.url)), '..', 'registry');
9
+ const CONFIG = 'ochre.json';
10
+ const API = (process.env.OCHREUI_API ?? 'https://ochreui.dev').replace(/\/+$/, '');
11
+ const KEY_FILE = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'ochreui', 'key');
12
+ const tty = process.stdout.isTTY && !process.env.NO_COLOR;
13
+ const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : s);
14
+ const bold = paint(1);
15
+ const dim = paint(2);
16
+ const red = paint(31);
17
+ const green = paint(32);
18
+ const yellow = paint(33);
19
+
20
+ class CliError extends Error {}
21
+
22
+ const HELP = `${bold('ochreui')}: add Ochre components to an Angular app as files you own.
23
+
24
+ ${bold('Usage')}
25
+ npx ochreui@latest add <component...> Copy components into your app (runs init first if needed)
26
+ npx ochreui@latest init Add the design tokens and create ochre.json
27
+ npx ochreui@latest list Show every component you can add
28
+ npx ochreui@latest add skill Add the Ochre skill for Claude Code and other agents
29
+ npx ochreui@latest diff <component> Show what changed upstream since your copy
30
+ npx ochreui@latest update [component...] Update copies you haven't edited
31
+
32
+ ${bold('Options')}
33
+ --project <name> Angular project to use (default: the first application)
34
+ --path <dir> Where components go (default: <sourceRoot>/app/ui)
35
+ --overwrite add: replace an existing file that differs
36
+ --force update: replace files you have edited
37
+ --dry-run Show what would change, write nothing
38
+ --cwd <dir> Run in another directory
39
+
40
+ ${bold('Pro components')}
41
+ Set OCHRE_KEY to your access key, or save it in ~/.config/ochreui/key.
42
+ Create a key at https://ochreui.dev/account.
43
+
44
+ Docs: https://ochreui.dev/docs/installation`;
45
+
46
+ function parseArgs(argv) {
47
+ const flags = { project: undefined, path: undefined, overwrite: false, force: false, dryRun: false, cwd: process.cwd() };
48
+ const rest = [];
49
+ for (let i = 0; i < argv.length; i++) {
50
+ const a = argv[i];
51
+ const value = () => {
52
+ const v = argv[++i];
53
+ if (!v || v.startsWith('--')) throw new CliError(`${a} needs a value.`);
54
+ return v;
55
+ };
56
+ if (a === '--project') flags.project = value();
57
+ else if (a === '--path') flags.path = value();
58
+ else if (a === '--cwd') flags.cwd = resolve(value());
59
+ else if (a === '--overwrite') flags.overwrite = true;
60
+ else if (a === '--force') flags.force = true;
61
+ else if (a === '--dry-run') flags.dryRun = true;
62
+ else if (a === '-h' || a === '--help') rest.unshift('help');
63
+ else if (a.startsWith('--')) throw new CliError(`Unknown option ${a}. Run ochreui --help.`);
64
+ else rest.push(a);
65
+ }
66
+ return { command: rest[0] ?? 'help', names: rest.slice(1), flags };
67
+ }
68
+
69
+ const normalize = (text) => text.replace(/\r\n/g, '\n');
70
+ const hash = (text) => createHash('sha256').update(normalize(text)).digest('hex').slice(0, 16);
71
+ const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'));
72
+ const writeJson = (file, data) => writeFileSync(file, JSON.stringify(data, null, 2) + '\n');
73
+ const posix = (p) => p.split('\\').join('/');
74
+
75
+ function stripJsonComments(text) {
76
+ let out = '';
77
+ let inString = false;
78
+ for (let i = 0; i < text.length; i++) {
79
+ const c = text[i];
80
+ if (inString) {
81
+ out += c;
82
+ if (c === '\\') out += text[++i] ?? '';
83
+ else if (c === '"') inString = false;
84
+ } else if (c === '"') {
85
+ inString = true;
86
+ out += c;
87
+ } else if (c === '/' && text[i + 1] === '/') {
88
+ while (i < text.length && text[i] !== '\n') i++;
89
+ out += '\n';
90
+ } else if (c === '/' && text[i + 1] === '*') {
91
+ i = text.indexOf('*/', i + 2);
92
+ if (i < 0) break;
93
+ i++;
94
+ } else out += c;
95
+ }
96
+ return out.replace(/,(\s*[}\]])/g, '$1');
97
+ }
98
+
99
+ function loadRegistry() {
100
+ const index = readJson(join(REGISTRY, 'index.json'));
101
+ const byName = new Map(index.items.map((item) => [item.name, item]));
102
+ return { index, byName };
103
+ }
104
+
105
+ /** Edit distance between two names, so a typo like "progres-tracker" still finds its component. */
106
+ function distance(a, b) {
107
+ let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
108
+ for (let i = 1; i <= a.length; i++) {
109
+ const row = [i];
110
+ for (let j = 1; j <= b.length; j++) row[j] = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
111
+ prev = row;
112
+ }
113
+ return prev[b.length];
114
+ }
115
+
116
+ /** The access key: OCHRE_KEY, else the key file. Never written to ochre.json, which gets committed. */
117
+ function accessKey() {
118
+ const fromEnv = process.env.OCHRE_KEY?.trim();
119
+ if (fromEnv) return fromEnv;
120
+ return existsSync(KEY_FILE) ? readFileSync(KEY_FILE, 'utf8').trim() || null : null;
121
+ }
122
+
123
+ const SAFE_FILE = /^[a-z0-9][a-z0-9/_.-]*$/;
124
+
125
+ /** Downloads a Pro item with its file contents. Null when the server has no such item. */
126
+ async function fetchPro(name) {
127
+ const key = accessKey();
128
+ if (!key) throw new CliError(`${name} is a Pro component. Set OCHRE_KEY to your access key, or save it in ${KEY_FILE}. Create one at https://ochreui.dev/account.`);
129
+ let res;
130
+ try {
131
+ res = await fetch(`${API}/api/pro/registry/${encodeURIComponent(name)}`, { headers: { authorization: `Bearer ${key}`, accept: 'application/json' }, signal: AbortSignal.timeout(20_000) });
132
+ } catch (e) {
133
+ throw new CliError(`Could not reach ${API} to download ${name}: ${e.cause?.message ?? e.message}`);
134
+ }
135
+ const body = await res.json().catch(() => null);
136
+ if (res.status === 401) throw new CliError(`Your access key was refused: ${body?.error?.message ?? 'check it on https://ochreui.dev/account.'}`);
137
+ if (res.status === 403) throw new CliError(`${name} is a Pro component, and the account behind your key has no active Pro licence. See https://ochreui.dev/pricing.`);
138
+ if (res.status === 404) return null;
139
+ if (!res.ok || !Array.isArray(body?.item?.files)) throw new CliError(`Downloading ${name} failed (HTTP ${res.status}). Try again later.`);
140
+ for (const f of body.item.files) {
141
+ if (typeof f.name !== 'string' || !SAFE_FILE.test(f.name) || f.name.includes('..') || isAbsolute(f.name) || typeof f.content !== 'string') {
142
+ throw new CliError(`Downloading ${name} failed: the server sent an unexpected file.`);
143
+ }
144
+ }
145
+ return { ...body.item, pro: true };
146
+ }
147
+
148
+ /** Puts the Pro items among `names` into the registry, downloaded with the key. Unknown names are tried too when a key is set. */
149
+ async function withPro(registry, names) {
150
+ for (const name of names) {
151
+ const local = registry.byName.get(name);
152
+ if (local && !local.pro) continue;
153
+ if (!local && !accessKey()) continue;
154
+ const item = await fetchPro(name);
155
+ if (item) registry.byName.set(name, item);
156
+ else if (local) throw new CliError(`${local.title ?? name} is not available for download yet.`);
157
+ }
158
+ }
159
+
160
+ /** A registry file's text: inline for downloaded Pro items, else from the bundled registry. */
161
+ const fileText = (file) => file.content ?? readFileSync(join(REGISTRY, file.name), 'utf8');
162
+
163
+ function findItem(registry, name) {
164
+ const item = registry.byName.get(name);
165
+ if (item) return item;
166
+ const close = [...registry.byName.keys()].filter((n) => n.includes(name) || name.includes(n) || distance(n, name) <= 2);
167
+ throw new CliError(`There is no component called "${name}".${close.length ? ` Did you mean ${close.join(', ')}?` : ''} Run ochreui list.`);
168
+ }
169
+
170
+ function findWorkspace(cwd) {
171
+ let dir = cwd;
172
+ while (true) {
173
+ if (existsSync(join(dir, 'angular.json'))) return dir;
174
+ const up = dirname(dir);
175
+ if (up === dir) throw new CliError('No angular.json found here or above. Run this inside an Angular workspace.');
176
+ dir = up;
177
+ }
178
+ }
179
+
180
+ function pickProject(workspace, wanted) {
181
+ const projects = workspace.projects ?? {};
182
+ if (wanted) {
183
+ if (!projects[wanted]) throw new CliError(`No project called "${wanted}" in angular.json. Found: ${Object.keys(projects).join(', ')}.`);
184
+ return [wanted, projects[wanted]];
185
+ }
186
+ const app = Object.entries(projects).find(([, p]) => p.projectType === 'application');
187
+ if (!app) throw new CliError('No application in angular.json. Pass --project <name>.');
188
+ return app;
189
+ }
190
+
191
+ function checkAngular(root, item) {
192
+ if (!item.angular) return;
193
+ const pkgFile = join(root, 'package.json');
194
+ if (!existsSync(pkgFile)) return;
195
+ const pkg = readJson(pkgFile);
196
+ const range = pkg.dependencies?.['@angular/core'] ?? pkg.devDependencies?.['@angular/core'];
197
+ const major = Number(String(range ?? '').match(/\d+/)?.[0]);
198
+ if (major && major < item.angular) {
199
+ throw new CliError(`${item.title} needs Angular ${item.angular} or later; this app uses @angular/core ${range}.`);
200
+ }
201
+ }
202
+
203
+ function missingPackages(root, items) {
204
+ const pkgFile = join(root, 'package.json');
205
+ if (!existsSync(pkgFile)) return [];
206
+ const pkg = readJson(pkgFile);
207
+ const has = (name) => !!(pkg.dependencies?.[name] ?? pkg.devDependencies?.[name] ?? pkg.peerDependencies?.[name]);
208
+ const missing = new Map();
209
+ for (const item of items) for (const name of item.needs ?? []) if (!has(name)) missing.set(name, [...(missing.get(name) ?? []), item.title ?? item.name]);
210
+ return [...missing];
211
+ }
212
+
213
+ function registerStylesheet(root, angularJson, projectName, stylesheet, dryRun, writable) {
214
+ const project = angularJson.projects[projectName];
215
+ const changed = [];
216
+ for (const targetName of ['build', 'test']) {
217
+ const target = project.architect?.[targetName] ?? project.targets?.[targetName];
218
+ if (!target) continue;
219
+ const opts = (target.options ??= {});
220
+ const styles = Array.isArray(opts.styles) ? opts.styles : [];
221
+ const has = styles.some((s) => (typeof s === 'string' ? s : s?.input) === stylesheet);
222
+ if (!has) {
223
+ opts.styles = [stylesheet, ...styles];
224
+ changed.push(targetName);
225
+ }
226
+ }
227
+ if (changed.length && !writable) return { manual: true };
228
+ if (changed.length && !dryRun) writeJson(join(root, 'angular.json'), angularJson);
229
+ return { changed };
230
+ }
231
+
232
+ function context(flags) {
233
+ const root = findWorkspace(flags.cwd);
234
+ const raw = readFileSync(join(root, 'angular.json'), 'utf8');
235
+ let angularJson;
236
+ let writable = true;
237
+ try {
238
+ angularJson = JSON.parse(raw);
239
+ } catch {
240
+ writable = false;
241
+ try {
242
+ angularJson = JSON.parse(stripJsonComments(raw));
243
+ } catch {
244
+ throw new CliError('angular.json could not be read. Fix it, or follow the manual steps at https://ochreui.dev/docs/installation.');
245
+ }
246
+ }
247
+ const configFile = join(root, CONFIG);
248
+ const config = existsSync(configFile) ? readJson(configFile) : null;
249
+ const [projectName, project] = pickProject(angularJson, flags.project ?? config?.project);
250
+ const sourceRoot = project.sourceRoot ?? posix(join(project.root ?? '', 'src'));
251
+ return { root, angularJson, writable, configFile, config, projectName, sourceRoot };
252
+ }
253
+
254
+ function freshConfig(ctx, flags) {
255
+ return {
256
+ project: ctx.projectName,
257
+ paths: { components: posix(flags.path ?? `${ctx.sourceRoot}/app/ui`), styles: `${ctx.sourceRoot}/styles` },
258
+ installed: {},
259
+ };
260
+ }
261
+
262
+ function init(ctx, registry, flags, log = true) {
263
+ const { root, angularJson } = ctx;
264
+ const config = ctx.config ?? freshConfig(ctx, flags);
265
+ if (flags.path) config.paths.components = posix(flags.path);
266
+
267
+ const tokens = findItem(registry, 'tokens');
268
+ writeItem(ctx, config, tokens, registry.index.version, { ...flags, overwrite: false, force: false, update: true });
269
+ const stylesheet = `${config.paths.styles}/${tokens.files[0].name}`;
270
+ const result = registerStylesheet(root, angularJson, config.project, stylesheet, flags.dryRun, ctx.writable);
271
+ if (result.manual) {
272
+ say(`${yellow('!')} angular.json has comments, so it was left as is. Add "${stylesheet}" as the first entry of "styles" in the build and test options.`, flags);
273
+ } else if (result.changed.length) {
274
+ say(`${green('✓')} Added ${stylesheet} to the ${result.changed.join(' and ')} styles in angular.json`, flags);
275
+ }
276
+
277
+ ctx.config = config;
278
+ if (!flags.dryRun) writeJson(ctx.configFile, config);
279
+ if (log && !ctx.wasConfigured) say(`${green('✓')} Wrote ${CONFIG}`, flags);
280
+ return config;
281
+ }
282
+
283
+ const SKILL_DIR = '.claude/skills/ochre';
284
+
285
+ function itemTarget(config, item, file) {
286
+ if (item.type === 'skill') return posix(join(SKILL_DIR, file.name.replace(/^skill\//, '')));
287
+ return posix(join(item.type === 'styles' ? config.paths.styles : config.paths.components, file.name));
288
+ }
289
+
290
+ function writeItem(ctx, config, item, version, flags) {
291
+ const record = { version, files: {} };
292
+ const previous = config.installed[item.name];
293
+ for (const file of item.files) {
294
+ const target = itemTarget(config, item, file);
295
+ const abs = join(ctx.root, target);
296
+ const next = fileText(file);
297
+ if (existsSync(abs)) {
298
+ const current = readFileSync(abs, 'utf8');
299
+ if (normalize(current) === normalize(next)) {
300
+ record.files[target] = hash(next);
301
+ say(`${dim('·')} ${target} is already up to date`, flags);
302
+ continue;
303
+ }
304
+ const recorded = previous?.files?.[target];
305
+ const edited = recorded !== hash(current);
306
+ if (!flags.overwrite && !(flags.update && (!edited || flags.force))) {
307
+ record.files[target] = recorded ?? 'edited';
308
+ say(
309
+ `${yellow('!')} ${target} already exists and differs${edited ? ' (you edited it)' : ''}. ` +
310
+ `Kept your file. See the changes with ${bold(`ochreui diff ${item.name}`)}, or replace it with ${bold('--overwrite')}.`,
311
+ flags,
312
+ );
313
+ continue;
314
+ }
315
+ }
316
+ if (!flags.dryRun) {
317
+ mkdirSync(dirname(abs), { recursive: true });
318
+ writeFileSync(abs, next);
319
+ }
320
+ record.files[target] = hash(next);
321
+ say(`${green('✓')} ${flags.dryRun ? 'Would write' : 'Wrote'} ${target}`, flags);
322
+ }
323
+ config.installed[item.name] = record;
324
+ }
325
+
326
+ function say(message, flags) {
327
+ console.log(flags.dryRun ? `${dim('[dry run]')} ${message}` : message);
328
+ }
329
+
330
+ function resolveWithDeps(registry, names) {
331
+ const order = [];
332
+ const visit = (name) => {
333
+ const item = findItem(registry, name);
334
+ if (order.includes(item)) return;
335
+ for (const dep of item.dependencies ?? []) visit(dep);
336
+ order.push(item);
337
+ };
338
+ names.forEach(visit);
339
+ return order;
340
+ }
341
+
342
+ async function add(names, flags) {
343
+ if (!names.length) throw new CliError('Name at least one component, e.g. ochreui add progress-tracker. Run ochreui list to see them all.');
344
+ const registry = loadRegistry();
345
+ await withPro(registry, names);
346
+ const items = resolveWithDeps(registry, names);
347
+ const ctx = context(flags);
348
+ ctx.wasConfigured = !!ctx.config;
349
+ for (const item of items) checkAngular(ctx.root, item);
350
+ const config = items.every((i) => i.type === 'skill') ? (ctx.config ?? freshConfig(ctx, flags)) : init(ctx, registry, flags);
351
+ for (const item of items) if (item.name !== 'tokens') writeItem(ctx, config, item, registry.index.version, flags);
352
+ if (!flags.dryRun) writeJson(ctx.configFile, config);
353
+
354
+ for (const [name, users] of missingPackages(ctx.root, items)) {
355
+ say(`${yellow('!')} ${users.join(', ')} ${users.length > 1 ? 'import' : 'imports'} ${name}, which this app doesn't list. Install it: ${bold(`npm install ${name}`)}`, flags);
356
+ }
357
+
358
+ if (items.some((i) => i.type === 'skill')) {
359
+ console.log(`\n${bold('Agent skill')}: Claude Code picks up ${SKILL_DIR} on its own. Commit the folder to share it with your team.`);
360
+ console.log(dim(` Other agents: paste ${SKILL_DIR}/INSTRUCTIONS.md into AGENTS.md or CLAUDE.md.`));
361
+ }
362
+
363
+ const components = items.filter((i) => i.exports?.length && (i.type === 'component' || names.includes(i.name)));
364
+ if (components.length) {
365
+ console.log('');
366
+ for (const c of components) {
367
+ const file = itemTarget(config, c, c.files[0]);
368
+ const from = posix(relative(`${ctx.sourceRoot}/app`, file)).replace(/\.ts$/, '');
369
+ console.log(`${bold(c.title)}: import { ${c.exports.join(', ')} } from '${from.startsWith('.') ? from : `./${from}`}';`);
370
+ if (c.type === 'component') console.log(dim(` Docs: https://ochreui.dev/components/${c.name}`));
371
+ }
372
+ }
373
+ }
374
+
375
+ function list() {
376
+ const { index } = loadRegistry();
377
+ const items = index.items.filter((i) => i.type !== 'styles');
378
+ const width = Math.max(...items.map((i) => i.name.length));
379
+ console.log(bold(`Ochre ${index.version}\n`));
380
+ for (const i of items) console.log(` ${i.name.padEnd(width)} ${dim(i.description)}${i.pro ? yellow(' Pro') : ''}`);
381
+ console.log(`\nAdd one with ${bold('npx ochreui@latest add <name>')}`);
382
+ }
383
+
384
+ function diffLines(a, b) {
385
+ const x = a.split('\n');
386
+ const y = b.split('\n');
387
+ const n = x.length;
388
+ const m = y.length;
389
+ const lcs = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
390
+ for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) lcs[i][j] = x[i] === y[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
391
+ const ops = [];
392
+ let i = 0;
393
+ let j = 0;
394
+ while (i < n && j < m) {
395
+ if (x[i] === y[j]) ops.push([' ', x[i++], j++]);
396
+ else if (lcs[i + 1][j] >= lcs[i][j + 1]) ops.push(['-', x[i++]]);
397
+ else ops.push(['+', y[j++]]);
398
+ }
399
+ while (i < n) ops.push(['-', x[i++]]);
400
+ while (j < m) ops.push(['+', y[j++]]);
401
+ return ops;
402
+ }
403
+
404
+ function printDiff(ops, context = 3) {
405
+ const keep = new Set();
406
+ ops.forEach(([op], k) => {
407
+ if (op !== ' ') for (let d = -context; d <= context; d++) keep.add(k + d);
408
+ });
409
+ let gap = false;
410
+ ops.forEach(([op, line], k) => {
411
+ if (!keep.has(k)) {
412
+ if (!gap) console.log(dim(' …'));
413
+ gap = true;
414
+ return;
415
+ }
416
+ gap = false;
417
+ console.log(op === '+' ? green(`+ ${line}`) : op === '-' ? red(`- ${line}`) : dim(` ${line}`));
418
+ });
419
+ }
420
+
421
+ async function diff(names, flags) {
422
+ if (names.length !== 1) throw new CliError('Name one component, e.g. ochreui diff progress-tracker.');
423
+ const registry = loadRegistry();
424
+ await withPro(registry, names);
425
+ const item = findItem(registry, names[0]);
426
+ const ctx = context(flags);
427
+ if (!ctx.config?.installed?.[item.name]) throw new CliError(`${item.name} isn't installed here. Add it with ochreui add ${item.name}.`);
428
+ for (const file of item.files) {
429
+ const target = itemTarget(ctx.config, item, file);
430
+ const abs = join(ctx.root, target);
431
+ if (!existsSync(abs)) {
432
+ console.log(`${yellow('!')} ${target} is missing. ochreui add ${item.name} puts it back.`);
433
+ continue;
434
+ }
435
+ const mine = normalize(readFileSync(abs, 'utf8'));
436
+ const theirs = normalize(fileText(file));
437
+ if (mine === theirs) {
438
+ console.log(`${green('✓')} ${target} matches Ochre ${registry.index.version}`);
439
+ continue;
440
+ }
441
+ console.log(bold(`${target}: ${red('- your copy')} ${green('+ Ochre ' + registry.index.version)}`));
442
+ printDiff(diffLines(mine, theirs));
443
+ }
444
+ }
445
+
446
+ async function update(names, flags) {
447
+ const registry = loadRegistry();
448
+ const ctx = context(flags);
449
+ if (!ctx.config) throw new CliError('Nothing to update: no ochre.json here. Start with ochreui add <component>.');
450
+ const installed = Object.keys(ctx.config.installed);
451
+ const targets = names.length ? names : installed;
452
+ const missing = targets.filter((n) => !installed.includes(n));
453
+ if (missing.length) throw new CliError(`Not installed here: ${missing.join(', ')}.`);
454
+ const ready = [];
455
+ for (const name of targets) {
456
+ try {
457
+ await withPro(registry, [name]);
458
+ ready.push(name);
459
+ } catch (e) {
460
+ // When updating everything, a Pro item that can't be downloaded is skipped, not fatal.
461
+ if (names.length || !(e instanceof CliError)) throw e;
462
+ say(`${yellow('!')} Skipped ${name}: ${e.message}`, flags);
463
+ }
464
+ }
465
+ for (const name of ready) writeItem(ctx, ctx.config, findItem(registry, name), registry.index.version, { ...flags, update: true });
466
+ if (!flags.dryRun) writeJson(ctx.configFile, ctx.config);
467
+ }
468
+
469
+ try {
470
+ const { command, names, flags } = parseArgs(process.argv.slice(2));
471
+ switch (command) {
472
+ case 'add':
473
+ await add(names, flags);
474
+ break;
475
+ case 'init': {
476
+ const ctx = context(flags);
477
+ ctx.wasConfigured = !!ctx.config;
478
+ init(ctx, loadRegistry(), flags);
479
+ break;
480
+ }
481
+ case 'list':
482
+ list();
483
+ break;
484
+ case 'diff':
485
+ await diff(names, flags);
486
+ break;
487
+ case 'update':
488
+ await update(names, flags);
489
+ break;
490
+ case 'help':
491
+ console.log(HELP);
492
+ break;
493
+ default:
494
+ throw new CliError(`Unknown command "${command}". Run ochreui --help.`);
495
+ }
496
+ } catch (e) {
497
+ if (e instanceof CliError) {
498
+ console.error(`${red('✗')} ${e.message}`);
499
+ process.exit(1);
500
+ }
501
+ throw e;
502
+ }