@imfusion/web-ui 0.5.1-dev.3.g8e0a047a → 0.5.1-dev.32.gddf4b438

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 (57) hide show
  1. package/README.md +148 -55
  2. package/bin/install.js +374 -0
  3. package/bin/install.test.ts +243 -0
  4. package/dist/build/vite-css-module-names/index.d.ts +20 -0
  5. package/dist/build/vite-css-module-names.js +17 -0
  6. package/dist/components/field/field.d.ts +104 -0
  7. package/dist/components/field/field.meta.d.ts +2 -0
  8. package/dist/components/field/index.d.ts +2 -0
  9. package/dist/components/fieldset/fieldset.d.ts +29 -0
  10. package/dist/components/fieldset/fieldset.meta.d.ts +2 -0
  11. package/dist/components/fieldset/index.d.ts +2 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +4956 -4317
  14. package/dist/integrations/image-display-options.js +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/{tabs-DqBFSqq6.js → tabs-CVp_SgBl.js} +1 -1
  17. package/package.json +35 -24
  18. package/src/docgen/doc.gen.json +327 -0
  19. package/src/llms/llms.gen.txt +12 -0
  20. package/src/llms/skills/imf-web-ui/SKILL.md +15 -11
  21. package/src/llms/skills/imf-web-ui-agent-setup/SKILL.md +82 -0
  22. package/src/llms/skills/imf-web-ui-agent-setup/templates/hooks/baseline-staleness.sh +17 -0
  23. package/src/llms/skills/imf-web-ui-agent-setup/templates/hooks/post-tool-use.sh +33 -0
  24. package/src/llms/skills/imf-web-ui-agent-setup/templates/hooks/session-start.sh +4 -0
  25. package/src/llms/skills/imf-web-ui-agent-setup/templates/hooks/user-prompt-submit.sh +4 -0
  26. package/src/llms/skills/imf-web-ui-agent-setup/templates/settings.json +37 -0
  27. package/src/llms/skills/imf-web-ui-components/SKILL.md +2 -1
  28. package/src/llms/skills/imf-web-ui-frontend-conventions/SKILL.md +46 -0
  29. package/src/llms/skills/imf-web-ui-frontend-conventions/references/assets.md +23 -0
  30. package/src/llms/skills/imf-web-ui-frontend-conventions/references/class-names.md +42 -0
  31. package/src/llms/skills/imf-web-ui-frontend-conventions/references/components.md +63 -0
  32. package/src/llms/skills/imf-web-ui-frontend-conventions/references/data.md +201 -0
  33. package/src/llms/skills/imf-web-ui-frontend-conventions/references/docs-structure.md +44 -0
  34. package/src/llms/skills/imf-web-ui-frontend-conventions/references/git.md +33 -0
  35. package/src/llms/skills/imf-web-ui-frontend-conventions/references/library-boundary.md +37 -0
  36. package/src/llms/skills/imf-web-ui-frontend-conventions/references/npm-project.md +57 -0
  37. package/src/llms/skills/imf-web-ui-frontend-conventions/references/project-structure.md +21 -0
  38. package/src/llms/skills/{imf-web-ui-frontend-patterns/references/react-patterns.md → imf-web-ui-frontend-conventions/references/react.md} +28 -12
  39. package/src/llms/skills/imf-web-ui-frontend-conventions/references/stack.md +39 -0
  40. package/src/llms/skills/imf-web-ui-frontend-conventions/references/styling.md +91 -0
  41. package/src/llms/skills/imf-web-ui-frontend-conventions/references/testing.md +18 -0
  42. package/src/llms/skills/imf-web-ui-frontend-conventions/references/tooling.md +76 -0
  43. package/src/llms/skills/imf-web-ui-frontend-conventions/references/typescript.md +46 -0
  44. package/src/llms/skills/imf-web-ui-frontend-conventions/references/validation.md +88 -0
  45. package/src/llms/skills/imf-web-ui-frontend-setup/SKILL.md +66 -0
  46. package/src/llms/skills/imf-web-ui-frontend-setup/templates/AGENTS.md +34 -0
  47. package/src/llms/skills/imf-web-ui-frontend-setup/templates/FRONTEND_SETUP_REPORT.md +45 -0
  48. package/src/llms/skills/imf-web-ui-frontend-setup/templates/README.md +27 -0
  49. package/src/llms/skills/imf-web-ui-library-setup/SKILL.md +36 -0
  50. package/src/llms/skills/imf-web-ui-update/SKILL.md +153 -0
  51. package/src/llms/skills/imf-web-ui-ux/SKILL.md +4 -4
  52. package/src/llms/skills/imf-web-ui-ux/references/forms.md +1 -1
  53. package/bin/install-skill.js +0 -180
  54. package/src/llms/skills/imf-web-ui-frontend-patterns/SKILL.md +0 -93
  55. package/src/llms/skills/imf-web-ui-frontend-patterns/references/code-conventions.md +0 -133
  56. package/src/llms/skills/imf-web-ui-imfusion-frontend-setup/SKILL.md +0 -201
  57. package/src/llms/skills/imf-web-ui-setup/SKILL.md +0 -57
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  `@imfusion/web-ui` — the official shared Web UI library for ImFusion web apps, built on Base UI.
4
4
 
5
+ - [Usage](#usage) — install, wire up, and keep the version current
6
+ - [Documentation](#documentation) — Storybook and the developer docs
7
+ - [Development](#development) — working on the library itself, including the Agent Skills
8
+ - [Releasing](#releasing) — how versions are derived and how to cut one
9
+
5
10
  ## Usage
6
11
 
7
12
  The packages are private on npmjs.com.
@@ -33,19 +38,55 @@ import "@imfusion/web-ui/styles.css";
33
38
  import { WebUIProvider } from "@imfusion/web-ui";
34
39
  ```
35
40
 
36
- **There is also an AI skill to help you set up the Web UI library in your project:
37
- [`/imf-web-ui-setup`](./src/llms/skills/imf-web-ui-setup/SKILL.md). **
41
+ ### LLM integration
38
42
 
39
- ## Development
43
+ The `web-ui` package does offer first-class support for LLMs, but it's not wired up by default.
40
44
 
41
- Install the deps and configure git:
45
+ To install the skills, run this command after the package is installed:
42
46
 
43
47
  ```bash
44
- npm install
45
- npm run git:config # hooks path + rebase-only pull/merge
48
+ npx web-ui-install
46
49
  ```
47
50
 
48
- **Try out **`/web-ui-dev-getting-started`** for an ai assisted start.**
51
+ The binary asks which LLM client you use and installs everything it needs. Run it again after a version bump and it refreshes
52
+ the directories it already installed into, without asking again — `--reconfigure` re-opens that choice.
53
+
54
+ **Available consumer skills - `/imf-web-ui-*`**
55
+
56
+ | Skill | What it does |
57
+ | ---------------------------------- | ------------------------------------------------------------------------------ |
58
+ | `/imf-web-ui` | The router: decides whether guidance is needed, then which companion to open. |
59
+ | `/imf-web-ui-library-setup` | One-time wiring in a consumer project — the styles import and the provider. |
60
+ | `/imf-web-ui-components` | Component reference — what exists and how it's meant to be used. |
61
+ | `/imf-web-ui-ux` | UX guidance for building interfaces with the library. |
62
+ | `/imf-web-ui-frontend-conventions` | The frontend conventions baseline, including the sanctioned styling seams. |
63
+ | `/imf-web-ui-frontend-setup` | Assess an ImFusion frontend and write a reviewable setup report. |
64
+ | `/imf-web-ui-agent-setup` | Install or update the vendored skills, agent hooks, and TanStack Intent. |
65
+ | `/imf-web-ui-update` | Update the library, skills, and optional hooks, then verify before committing. |
66
+
67
+ Start at `/imf-web-ui` — it routes to the rest. Storybook's **User Guide → AI Agents** page covers the whole family.
68
+
69
+ ### Versions and updates
70
+
71
+ Every merge to master publishes a new build under the `dev` dist-tag. Which spec you install decides how you pick those up:
72
+
73
+ | Spec in `package.json` | Gets | Update with |
74
+ | ---------------------------------- | -------------------------- | ------------------------------ |
75
+ | `"@imfusion/web-ui": "^0.5.0"` | matching releases | `npm update @imfusion/web-ui` |
76
+ | `"@imfusion/web-ui": "latest"` | the newest release | `npm update @imfusion/web-ui` |
77
+ | `"@imfusion/web-ui": "dev"` | the newest build of master | `npm update @imfusion/web-ui` |
78
+ | `"@imfusion/web-ui": "file:….tgz"` | a packed tarball, frozen | re-pack and re-install by hand |
79
+
80
+ - **Two dist-tags.** `latest` moves when a release is tagged, `dev` on every build of master (and onto the release when one
81
+ is cut).
82
+ - **A range like `^0.5.0` is the usual choice.** It tracks releases and states which major you expect; bare `latest` follows
83
+ releases across majors, breaking changes included.
84
+ - **Dist-tag specs stay literal.** npm keeps `dev` or `latest` as-is in `package.json` and re-resolves on every `npm update`.
85
+ The concrete version lands in `package-lock.json`, so builds stay reproducible until you update.
86
+ - **Track `dev` while building against the library**, to get new components as they land. Use a release spec for anything you
87
+ cut a production release from, since `dev` moves whenever someone merges.
88
+ - **A `file:` tarball never updates.** npm copies the archive into `node_modules` and re-copies the same one on every
89
+ install. Switch to `dev` or a version range to get updates.
49
90
 
50
91
  ## Documentation
51
92
 
@@ -58,51 +99,103 @@ npm run dev # builds the library, then Storybook + a rebuild watcher
58
99
 
59
100
  See the [Developer Docs](./docs/README.md).
60
101
 
61
- ## AI agents
62
-
63
- Two families of Agent Skills, told apart by their prefix:
64
-
65
- | Prefix | For | Lives in | How to get it |
66
- | -------------- | ----------------------------- | -------------------------- | --------------------------- |
67
- | `imf-web-ui-*` | Apps consuming the library | shipped in the npm package | `npx web-ui-install-skills` |
68
- | `web-ui-dev-*` | Developing the library itself | `.agents/skills/` | already there after cloning |
69
-
70
- ### Development skills — `web-ui-dev-*`
71
-
72
- **`web-ui-dev-*`** never ships; it's the workflow for working on this repo — scaffolding a component, authoring a story,
73
- committing. Start with `/web-ui-dev-getting-started`, which routes you the same way.
74
-
75
- | Skill | What it does |
76
- | ----------------------------------------- | ------------------------------------------------------------------------------------- |
77
- | `/web-ui-dev-getting-started` | Interactive intro — gauges your experience, works out your goal, routes you. |
78
- | `/web-ui-dev-start` | Starting ritual for any task: Jira context, `master` vs. a worktree, context summary. |
79
- | `/web-ui-dev-new-component` | Scaffolds an architecture-compliant primitive (adapted or absorbed). |
80
- | `/web-ui-dev-update-component` | Pointers to every file a prop, variant, or sub-component change touches. |
81
- | `/web-ui-dev-design-component` | Brand design pass for a component that works but isn't styled yet. |
82
- | `/web-ui-dev-story` | Author or update a Storybook story. |
83
- | `/web-ui-dev-commit` | Commit workflow: staged docs audit, CI-parity checks, house commit format. |
84
- | `/web-ui-dev-audit-docs` | Audit docs against staged or recent changes for staleness, gaps, and drift. |
85
- | `/web-ui-dev-audit-pass-through-defaults` | Check `@default` annotations on pass-through props against Base UI upstream. |
86
- | `/web-ui-dev-manage-worktrees` | Create, close, or discard a worktree in `.workspaces/`. |
87
- | `/web-ui-dev-refresh-design-reference` | Refresh the committed brand snapshots in `design/` from the Figma styleguide. |
88
- | `/web-ui-dev-mcp` | Set up or recover Storybook, DevTools, Atlassian, or Figma MCP access. |
89
-
90
- ### Consumer skills — `imf-web-ui-*`
91
-
92
- **`imf-web-ui-*`** travels with the package, so an agent in a consumer app gets library guidance without reading this
93
- library's source. ` imf-web-ui` — the bare name, no suffix — is the router: it costs little to load and decides which
94
- companion applies, or that none does.
95
-
96
- The companions cover library wiring (`-setup`), the component reference (`-components`), UX guidance (`-ux`), frontend
97
- patterns (`-frontend-patterns`), and ImFusion project tooling (`-imfusion-frontend-setup`).
98
-
99
- | Skill | What it does |
100
- | ------------------------------------- | ------------------------------------------------------------------------------------ |
101
- | `/imf-web-ui` | The router: decides whether guidance is needed, then which companion to open. |
102
- | `/imf-web-ui-setup` | One-time wiring in a consumer project — the styles import and the provider. |
103
- | `/imf-web-ui-components` | Component reference — what exists and how it's meant to be used. |
104
- | `/imf-web-ui-ux` | UX guidance for building interfaces with the library. |
105
- | `/imf-web-ui-frontend-patterns` | Frontend patterns, including the sanctioned styling seams (tokens, data attributes). |
106
- | `/imf-web-ui-imfusion-frontend-setup` | Set up or audit an ImFusion frontend's tooling against the house baseline. |
107
-
108
- Keep these tables current when a skill is added, renamed, or removed — `/web-ui-dev-audit-docs` checks them.
102
+ ## Development
103
+
104
+ Install the deps and configure git:
105
+
106
+ ```bash
107
+ npm install
108
+ npm run git:config # hooks path + rebase-only pull/merge
109
+ ```
110
+
111
+ **Try out **`/web-ui-dev-getting-started`** for an ai assisted start.**
112
+
113
+ ### LLM integration
114
+
115
+ These skills are shipped with a `/web-ui-dev-*` prefix, so to make their names identifiable and not pollute the skill
116
+ namespace.
117
+
118
+ | Skill | What it does |
119
+ | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
120
+ | `/web-ui-dev-getting-started` | Interactive intro — gauges your experience, works out your goal, routes you. |
121
+ | `/web-ui-dev-start` | Starting ritual for any task: Jira context, `master` vs. a worktree, context summary. |
122
+ | `/web-ui-dev-new-component` | Scaffolds an architecture-compliant primitive (adapted or absorbed). |
123
+ | `/web-ui-dev-update-component` | Pointers to every file a prop, variant, or sub-component change touches. |
124
+ | `/web-ui-dev-design-component` | Brand design pass for a component that works but isn't styled yet. |
125
+ | `/web-ui-dev-story` | Author or update a Storybook story. |
126
+ | `/web-ui-dev-commit` | Commit workflow: changelog skill, staged docs audit, CI-parity checks, house commit format. |
127
+ | `/web-ui-dev-changelog` | Generate and validate the required one-line CHANGELOG.md entry for a web-ui change, including direct commits to master. |
128
+ | `/web-ui-dev-audit-docs` | Audit docs against staged or recent changes for staleness, gaps, and drift. |
129
+ | `/web-ui-dev-audit-pass-through-defaults` | Check `@default` annotations on pass-through props against Base UI upstream. |
130
+ | `/web-ui-dev-teardown-worktree` | Tear down a worktree, wherever it lives — merging its branch first or dropping it. |
131
+ | `/web-ui-dev-refresh-design-reference` | Refresh the committed brand snapshots in `design/` from the Figma styleguide. |
132
+ | `/web-ui-dev-mcp` | Set up or recover Storybook, DevTools, Atlassian, or Figma MCP access. |
133
+
134
+ ## Releasing
135
+
136
+ Release-facing changes are recorded as one-line entries in [`CHANGELOG.md`](./CHANGELOG.md) under `## [Unreleased]`. The
137
+ commit workflow requires an entry for pull-request commits and direct commits to `master`, with only narrow mechanical
138
+ exceptions.
139
+
140
+ The published version is derived from git tags, not from `package.json`.
141
+
142
+ The `version` field stays at `0.0.0` in the repository and he CI computes the real number with
143
+ [`scripts/version.ts`](./scripts/version.ts) and writes it into `package.json` on the build agent just before publishing.
144
+
145
+ That working copy is thrown away, so nothing is committed back.
146
+
147
+ `scripts/version.ts` reads `git describe` and applies two rules:
148
+
149
+ Given the tag `web-ui/v0.5.0`:
150
+
151
+ | Where HEAD sits | Published version | dist-tag |
152
+ | -------------------------- | ----------------------- | -------- |
153
+ | Exactly on `web-ui/v0.5.0` | `0.5.0` | `latest` |
154
+ | 5 commits after that tag | `0.5.1-dev.5.gb4de52d7` | `dev` |
155
+
156
+ The off-tag string breaks down as:
157
+
158
+ ```
159
+ 0.5.1-dev.5.gb4de52d7
160
+ └─┬─┘ └┬┘ │ └───┬────┘
161
+ │ │ │ └── commit hash, abbreviated; the leading g means "git"
162
+ │ │ └──────── commits since the tag
163
+ │ └─────────── pre-release marker, which is what puts it on the dev tag
164
+ └──────────────── the tag's version, patch bumped
165
+ ```
166
+
167
+ Bumping the patch is what makes a dev build sort above the release it follows and below the next one.
168
+
169
+ Every build of `master` publishes a `dev` version automatically. To check what the current checkout would publish:
170
+
171
+ ```bash
172
+ npx tsx scripts/version.ts # prints, changes nothing
173
+ ```
174
+
175
+ ### Cutting a release
176
+
177
+ Tag the commit you want to ship and push the tag:
178
+
179
+ ```bash
180
+ git tag -a web-ui/v0.5.1 -m "web-ui 0.5.1"
181
+ git push origin web-ui/v0.5.1
182
+ ```
183
+
184
+ The tag triggers a build that publishes `0.5.1` as `latest` and repoints the `dev` dist-tag at the same version.
185
+
186
+ **The tag must be annotated (`-a`).** `git describe` ignores lightweight tags, so a tag pushed without `-a` is invisible to
187
+ the version script — the build reads through it to the previous release tag and publishes another `dev` version instead of
188
+ the release.
189
+
190
+ The tag name must match `web-ui/vX.Y.Z` exactly. Both the version script's `--match` and the TeamCity branch filter in
191
+ [`.teamcity/settings.kts`](./.teamcity/settings.kts) key off that shape; a tag in any other form publishes nothing.
192
+
193
+ ### Building locally with a real version
194
+
195
+ A local `npm run build` stamps `dist` with `0.0.0`. When you need the true version in a local artifact:
196
+
197
+ ```bash
198
+ npx tsx scripts/version.ts --write # writes it into package.json
199
+ npm run build
200
+ git checkout package.json # discard the write
201
+ ```
package/bin/install.js ADDED
@@ -0,0 +1,374 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Installs this package's agent tooling into the consumer project: the
4
+ // skill family (../src/llms/skills/imf-web-ui*/) and the agent lifecycle
5
+ // hooks the frontend-setup skill ships as templates. Runs in the
6
+ // CONSUMER's environment, so it may only use this package's real runtime
7
+ // dependencies (@clack/prompts). Never wire this into a postinstall hook:
8
+ // ambient script execution on `npm install` is a live supply-chain attack
9
+ // vector — install stays an explicit, user-run command.
10
+ //
11
+ // The skills cross-reference each other, so they install as one bundle.
12
+ // When both targets are selected, .agents/skills/ holds the real copy and
13
+ // .claude/skills/ symlinks it (this repo's own convention) so the two
14
+ // can't drift apart.
15
+ //
16
+ // Flags: bare = skills only; --hooks adds the agent lifecycle hooks (driven
17
+ // by the imf-web-ui-agent-setup skill, which checks the repo's existing hooks
18
+ // first). --target claude|agents (repeatable) for scripted installs,
19
+ // --reconfigure to re-open the target prompt on an existing install.
20
+
21
+ import {
22
+ chmodSync,
23
+ cpSync,
24
+ existsSync,
25
+ lstatSync,
26
+ mkdirSync,
27
+ readdirSync,
28
+ readFileSync,
29
+ rmSync,
30
+ symlinkSync,
31
+ writeFileSync
32
+ } from "node:fs";
33
+ import { spawnSync } from "node:child_process";
34
+ import { dirname, relative, resolve } from "node:path";
35
+ import { fileURLToPath } from "node:url";
36
+ import * as p from "@clack/prompts";
37
+
38
+ const SKILL_PREFIX = "imf-web-ui";
39
+ const VERSION_MARKER = ".imf-web-ui-skill-version.json";
40
+
41
+ const here = dirname(fileURLToPath(import.meta.url));
42
+ // Source is relative to THIS SCRIPT's location (inside node_modules), not
43
+ // the consumer's cwd — the script is invoked from the consumer's project
44
+ // root, but the skills it copies ship alongside this file in the package.
45
+ const skillsRoot = resolve(here, "..", "src", "llms", "skills");
46
+ const packageJson = JSON.parse(readFileSync(resolve(here, "..", "package.json"), "utf-8"));
47
+ const currentVersion = packageJson.version;
48
+
49
+ // Destination is relative to the consumer's project root (cwd), since
50
+ // that's where their `.claude/` or `.agents/` directory lives.
51
+ const projectRoot = process.cwd();
52
+
53
+ const TARGETS = {
54
+ claude: { label: "Claude Code", root: resolve(projectRoot, ".claude", "skills") },
55
+ agents: { label: "Vendor-neutral (.agents/)", root: resolve(projectRoot, ".agents", "skills") }
56
+ };
57
+
58
+ function discoverSkills() {
59
+ if (!existsSync(skillsRoot)) return [];
60
+ return readdirSync(skillsRoot, { withFileTypes: true })
61
+ .filter(entry => entry.isDirectory() && entry.name.startsWith(SKILL_PREFIX))
62
+ .map(entry => entry.name)
63
+ .sort();
64
+ }
65
+
66
+ function displayPath(absPath) {
67
+ return `./${relative(projectRoot, absPath)}`;
68
+ }
69
+
70
+ function readInstalledVersion(dir) {
71
+ const markerPath = resolve(dir, VERSION_MARKER);
72
+ if (!existsSync(markerPath)) return null;
73
+ try {
74
+ return JSON.parse(readFileSync(markerPath, "utf-8")).version ?? null;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ function writeRealCopy(sourceDir, destDir) {
81
+ mkdirSync(dirname(destDir), { recursive: true });
82
+ // force: true makes re-running after a version bump overwrite cleanly.
83
+ cpSync(sourceDir, destDir, { recursive: true, force: true });
84
+ writeFileSync(resolve(destDir, VERSION_MARKER), JSON.stringify({ version: currentVersion }, null, 2) + "\n");
85
+ }
86
+
87
+ function writeSymlink(linkPath, targetPath) {
88
+ mkdirSync(dirname(linkPath), { recursive: true });
89
+ // lstat (not existsSync, which follows symlinks) catches a broken/stale
90
+ // symlink left over from a prior run, not just a real file or directory.
91
+ if (lstatSync(linkPath, { throwIfNoEntry: false })) {
92
+ rmSync(linkPath, { recursive: true, force: true });
93
+ }
94
+ symlinkSync(relative(dirname(linkPath), targetPath), linkPath);
95
+ }
96
+
97
+ function removeOrphanedSkills(selected, skills, both) {
98
+ const bundledSkills = new Set(skills);
99
+ const selectedTargets = both ? ["agents", "claude"] : selected;
100
+
101
+ for (const key of selectedTargets) {
102
+ const { root } = TARGETS[key];
103
+ if (!existsSync(root)) continue;
104
+
105
+ const orphanedSkills = readdirSync(root).filter(name => name.startsWith(`${SKILL_PREFIX}-`) && !bundledSkills.has(name));
106
+ for (const name of orphanedSkills) {
107
+ rmSync(resolve(root, name), { recursive: true, force: true });
108
+ // In the two-target layout, .claude/ is a symlinked view of the
109
+ // canonical .agents/ copy. Remove its matching link along with the
110
+ // orphaned canonical skill.
111
+ if (both && key === "agents") {
112
+ rmSync(resolve(TARGETS.claude.root, name), { recursive: true, force: true });
113
+ }
114
+ p.log.info(`Removed orphaned skill: ${name} (no longer in this bundle)`);
115
+ }
116
+ }
117
+ }
118
+
119
+ // A prior install is recoverable from the filesystem, so a re-run doesn't
120
+ // re-ask: a target counts as chosen when any bundled skill is present under
121
+ // it. Symlinks count — they're how the both-targets layout represents
122
+ // .claude/, and lstat avoids following them into the real copy.
123
+ function detectInstalledTargets(skills) {
124
+ return Object.keys(TARGETS).filter(key =>
125
+ skills.some(name => lstatSync(resolve(TARGETS[key].root, name), { throwIfNoEntry: false }))
126
+ );
127
+ }
128
+
129
+ // Hook templates ship inside the agent-setup skill so they're readable as
130
+ // part of its documentation; the installer copies the scripts into the
131
+ // consumer's .agents/hooks/ and merges the registrations into
132
+ // .claude/settings.json.
133
+ const hooksSourceDir = resolve(skillsRoot, "imf-web-ui-agent-setup", "templates", "hooks");
134
+ const hooksSettingsTemplate = resolve(skillsRoot, "imf-web-ui-agent-setup", "templates", "settings.json");
135
+ // Installer-owned subdirectory: refreshed wholesale on every run, so a repo's
136
+ // own hooks in .agents/hooks/ are never touched.
137
+ const hooksDestDir = resolve(projectRoot, ".agents", "hooks", "imf-web-ui");
138
+ const settingsPath = resolve(projectRoot, ".claude", "settings.json");
139
+
140
+ // Serializing the file reflows entries this installer doesn't own; the
141
+ // consumer's own Prettier puts them back. Best-effort: absent, or the path is
142
+ // .prettierignore'd, nothing happens.
143
+ function formatSettings() {
144
+ let toolRoot = projectRoot;
145
+ while (toolRoot !== dirname(toolRoot) && !existsSync(resolve(toolRoot, "node_modules", ".bin"))) {
146
+ toolRoot = dirname(toolRoot);
147
+ }
148
+ const prettier = resolve(toolRoot, "node_modules", ".bin", "prettier");
149
+ if (!existsSync(prettier)) return;
150
+ spawnSync(prettier, ["--write", settingsPath], { cwd: projectRoot, stdio: "ignore" });
151
+ }
152
+
153
+ function installHookScripts() {
154
+ const scripts = readdirSync(hooksSourceDir).filter(name => name.endsWith(".sh"));
155
+ mkdirSync(hooksDestDir, { recursive: true });
156
+ for (const name of scripts) {
157
+ const dest = resolve(hooksDestDir, name);
158
+ cpSync(resolve(hooksSourceDir, name), dest, { force: true });
159
+ chmodSync(dest, 0o755);
160
+ }
161
+ return scripts.length;
162
+ }
163
+
164
+ // A registration is identified by the script it runs, not the command string:
165
+ // "$VAR/..." and "${VAR}/..." are the same hook.
166
+ const HOOKS_DIR_SEGMENT = ".agents/hooks/imf-web-ui/";
167
+
168
+ function hookScriptId(command) {
169
+ if (typeof command !== "string") return null;
170
+ const at = command.lastIndexOf(HOOKS_DIR_SEGMENT);
171
+ if (at === -1) return null;
172
+ return command.slice(at + HOOKS_DIR_SEGMENT.length).replace(/["'\s]+$/, "");
173
+ }
174
+
175
+ function entryScriptIds(entry) {
176
+ return (entry.hooks ?? []).map(hook => hookScriptId(hook.command)).filter(Boolean);
177
+ }
178
+
179
+ // Merge, never clobber: a registration is added only when no existing entry
180
+ // for that event already runs the same script, so re-runs are idempotent and
181
+ // hand-written settings survive. A run that adds nothing writes nothing.
182
+ function mergeHookRegistrations() {
183
+ const template = JSON.parse(readFileSync(hooksSettingsTemplate, "utf-8"));
184
+ let settings = {};
185
+ if (existsSync(settingsPath)) {
186
+ try {
187
+ settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
188
+ } catch {
189
+ return null;
190
+ }
191
+ }
192
+ settings.hooks ??= {};
193
+ let added = 0;
194
+ for (const [event, entries] of Object.entries(template.hooks)) {
195
+ settings.hooks[event] ??= [];
196
+ for (const entry of entries) {
197
+ const scripts = entryScriptIds(entry);
198
+ const present = settings.hooks[event].some(existing =>
199
+ entryScriptIds(existing).some(script => scripts.includes(script))
200
+ );
201
+ if (!present) {
202
+ settings.hooks[event].push(entry);
203
+ added++;
204
+ }
205
+ }
206
+ }
207
+ if (added === 0) return 0;
208
+ mkdirSync(dirname(settingsPath), { recursive: true });
209
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
210
+ formatSettings();
211
+ return added;
212
+ }
213
+
214
+ // The AGENTS.md baseline note lives inside a fenced block owned by this
215
+ // installer. The template between the markers is the source of truth; an
216
+ // existing AGENTS.md gets the block replaced in place (or appended when
217
+ // absent), everything outside the fence is untouched. No AGENTS.md at all
218
+ // is left alone — scaffolding one is the setup skill's job.
219
+ const AGENTS_BLOCK_BEGIN = "<!-- imf-web-ui:begin";
220
+ const AGENTS_BLOCK_END = "<!-- imf-web-ui:end -->";
221
+ const agentsTemplatePath = resolve(skillsRoot, "imf-web-ui-frontend-setup", "templates", "AGENTS.md");
222
+ const agentsPath = resolve(projectRoot, "AGENTS.md");
223
+
224
+ function extractAgentsBlock(content) {
225
+ const begin = content.indexOf(AGENTS_BLOCK_BEGIN);
226
+ const end = content.indexOf(AGENTS_BLOCK_END);
227
+ if (begin === -1 || end === -1) return null;
228
+ return content.slice(begin, end + AGENTS_BLOCK_END.length);
229
+ }
230
+
231
+ function upsertAgentsBlock() {
232
+ if (!existsSync(agentsPath)) return "absent";
233
+ const block = extractAgentsBlock(readFileSync(agentsTemplatePath, "utf-8"));
234
+ if (!block) return "absent";
235
+ const current = readFileSync(agentsPath, "utf-8");
236
+ const existing = extractAgentsBlock(current);
237
+ const next = existing ? current.replace(existing, block) : `${current.trimEnd()}\n\n${block}\n`;
238
+ if (next === current) return "unchanged";
239
+ writeFileSync(agentsPath, next);
240
+ return existing ? "updated" : "added";
241
+ }
242
+
243
+ // --target claude|agents (repeatable) selects targets without the
244
+ // interactive prompt — for CI and scripted installs.
245
+ function parseTargetFlags(argv) {
246
+ const targets = [];
247
+ for (let i = 0; i < argv.length; i++) {
248
+ if (argv[i] !== "--target") continue;
249
+ const value = argv[i + 1];
250
+ if (!value || !(value in TARGETS)) {
251
+ console.error(`--target expects one of: ${Object.keys(TARGETS).join(", ")}`);
252
+ process.exit(1);
253
+ }
254
+ targets.push(value);
255
+ i++;
256
+ }
257
+ return targets;
258
+ }
259
+
260
+ async function main() {
261
+ const skills = discoverSkills();
262
+ const argv = process.argv.slice(2);
263
+ const flagTargets = parseTargetFlags(argv);
264
+ const reconfigure = argv.includes("--reconfigure");
265
+ // Bare invocation installs skills only. Hooks are opt-in via --hooks — the
266
+ // imf-web-ui-agent-setup skill drives that after checking what the repo
267
+ // already registers; the binary stays the dumb mechanical tail.
268
+ const wantHooks = argv.includes("--hooks");
269
+ const wantSkills = argv.includes("--skills") || !wantHooks;
270
+
271
+ const components = [wantSkills && `${skills.length} skills`, wantHooks && "agent hooks"].filter(Boolean);
272
+ p.intro(`@imfusion/web-ui install — ${components.join(" + ")}`);
273
+
274
+ if (wantSkills && skills.length === 0) {
275
+ p.log.error(`No skills found at ${skillsRoot}. Reinstall @imfusion/web-ui and try again.`);
276
+ p.outro("Nothing installed.");
277
+ process.exitCode = 1;
278
+ return;
279
+ }
280
+
281
+ if (wantHooks) {
282
+ const scriptCount = installHookScripts();
283
+ const added = mergeHookRegistrations();
284
+ p.log.success(`Agent hooks -> ${displayPath(hooksDestDir)} (${scriptCount} scripts)`);
285
+ if (added === null) {
286
+ p.log.warn(`${displayPath(settingsPath)} is not valid JSON — registrations not merged, fix it and re-run.`);
287
+ } else if (added > 0) {
288
+ p.log.success(`Registered ${added} hook(s) in ${displayPath(settingsPath)}`);
289
+ } else {
290
+ p.log.info(`Hook registrations already present in ${displayPath(settingsPath)}`);
291
+ }
292
+ if (!wantSkills) {
293
+ p.outro("Done — hooks installed.");
294
+ return;
295
+ }
296
+ }
297
+
298
+ const installedTargets = detectInstalledTargets(skills);
299
+
300
+ const existingVersions = Object.values(TARGETS)
301
+ .flatMap(({ root }) => skills.map(name => readInstalledVersion(resolve(root, name))))
302
+ .filter(Boolean);
303
+ if (existingVersions.length > 0 && existingVersions.every(v => v === currentVersion)) {
304
+ p.log.info(`Already up to date (v${currentVersion}). Re-running will overwrite with the same content.`);
305
+ } else if (existingVersions.some(v => v !== currentVersion)) {
306
+ const from = existingVersions.find(v => v !== currentVersion);
307
+ p.log.info(`Updating installed skills from v${from} to v${currentVersion}.`);
308
+ }
309
+
310
+ p.log.message(`Skills in this bundle:\n${skills.map(name => ` - ${name}`).join("\n")}`);
311
+
312
+ let selected;
313
+ if (flagTargets.length > 0) {
314
+ selected = flagTargets;
315
+ p.log.info(`Targets from --target flags: ${selected.join(", ")}`);
316
+ } else if (installedTargets.length > 0 && !reconfigure) {
317
+ selected = installedTargets;
318
+ p.log.info(
319
+ `Refreshing the existing install: ${selected.map(key => displayPath(TARGETS[key].root)).join(", ")}` +
320
+ ` — pass --reconfigure to choose different targets.`
321
+ );
322
+ } else {
323
+ selected = await p.multiselect({
324
+ message: "Install into which skill directory (or directories)?",
325
+ options: Object.entries(TARGETS).map(([key, { label, root }]) => ({
326
+ value: key,
327
+ label,
328
+ hint: displayPath(root)
329
+ })),
330
+ required: true
331
+ });
332
+
333
+ if (p.isCancel(selected)) {
334
+ p.cancel("Cancelled — nothing installed.");
335
+ return;
336
+ }
337
+ }
338
+
339
+ const both = selected.includes("claude") && selected.includes("agents");
340
+
341
+ for (const name of skills) {
342
+ const sourceDir = resolve(skillsRoot, name);
343
+ if (both) {
344
+ // .agents/ is the canonical real copy; .claude/ aliases it via symlink.
345
+ const realDir = resolve(TARGETS.agents.root, name);
346
+ writeRealCopy(sourceDir, realDir);
347
+ writeSymlink(resolve(TARGETS.claude.root, name), realDir);
348
+ } else {
349
+ for (const key of selected) {
350
+ writeRealCopy(sourceDir, resolve(TARGETS[key].root, name));
351
+ }
352
+ }
353
+ }
354
+
355
+ removeOrphanedSkills(selected, skills, both);
356
+
357
+ if (both) {
358
+ p.log.success(`Vendor-neutral (.agents/) -> ${displayPath(TARGETS.agents.root)}/${SKILL_PREFIX}*`);
359
+ p.log.success(`Claude Code -> ${displayPath(TARGETS.claude.root)}/${SKILL_PREFIX}* (symlinks -> .agents/)`);
360
+ } else {
361
+ for (const key of selected) {
362
+ p.log.success(`${TARGETS[key].label} -> ${displayPath(TARGETS[key].root)}/${SKILL_PREFIX}*`);
363
+ }
364
+ }
365
+
366
+ const agentsResult = upsertAgentsBlock();
367
+ if (agentsResult === "updated" || agentsResult === "added") {
368
+ p.log.success(`Refreshed the imf-web-ui block in ${displayPath(agentsPath)}`);
369
+ }
370
+
371
+ p.outro(`Done — ${skills.length} skills installed${wantHooks ? " + agent hooks" : ""}.`);
372
+ }
373
+
374
+ await main();