polishup-cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.opencode/commands/polishup.md +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +177 -3
  4. package/cli/hosts.mjs +171 -0
  5. package/cli/index.mjs +256 -0
  6. package/cli/installations.mjs +300 -0
  7. package/cli/update.mjs +57 -0
  8. package/package.json +53 -6
  9. package/skills/polishup/LICENSE.txt +21 -0
  10. package/skills/polishup/SKILL.md +84 -0
  11. package/skills/polishup/references/code/implementation.md +43 -0
  12. package/skills/polishup/references/code/index.md +13 -0
  13. package/skills/polishup/references/code/rules.md +24 -0
  14. package/skills/polishup/references/colors.md +65 -0
  15. package/skills/polishup/references/research.md +50 -0
  16. package/skills/polishup/references/tools.md +57 -0
  17. package/skills/polishup/references/ui-ux/accessibility.md +136 -0
  18. package/skills/polishup/references/ui-ux/art-direction.md +127 -0
  19. package/skills/polishup/references/ui-ux/audio-and-video.md +121 -0
  20. package/skills/polishup/references/ui-ux/data-visualization.md +130 -0
  21. package/skills/polishup/references/ui-ux/design-ethics.md +98 -0
  22. package/skills/polishup/references/ui-ux/design-evaluation.md +123 -0
  23. package/skills/polishup/references/ui-ux/design-systems.md +110 -0
  24. package/skills/polishup/references/ui-ux/foundations.md +23 -0
  25. package/skills/polishup/references/ui-ux/index.md +29 -0
  26. package/skills/polishup/references/ui-ux/information-architecture.md +132 -0
  27. package/skills/polishup/references/ui-ux/interaction-design.md +155 -0
  28. package/skills/polishup/references/ui-ux/motion-design.md +110 -0
  29. package/skills/polishup/references/ui-ux/performance.md +109 -0
  30. package/skills/polishup/references/ui-ux/responsive-design.md +98 -0
  31. package/skills/polishup/references/ui-ux/rules.md +36 -0
  32. package/skills/polishup/references/ui-ux/ux-research.md +110 -0
  33. package/skills/polishup/references/ui-ux/visual-design.md +147 -0
  34. package/skills/polishup/references/writing/accessibility-and-inclusion.md +57 -0
  35. package/skills/polishup/references/writing/content-and-evidence.md +83 -0
  36. package/skills/polishup/references/writing/content-structure.md +94 -0
  37. package/skills/polishup/references/writing/foundations.md +19 -0
  38. package/skills/polishup/references/writing/index.md +17 -0
  39. package/skills/polishup/references/writing/language-and-style.md +83 -0
  40. package/skills/polishup/references/writing/multilingual-writing.md +51 -0
  41. package/skills/polishup/references/writing/purpose-audience-context.md +72 -0
  42. package/skills/polishup/references/writing/review-and-revision.md +81 -0
  43. package/skills/polishup/references/writing/rules.md +26 -0
  44. package/skills/polishup/references/writing/voice-and-tone.md +72 -0
  45. package/skills/polishup/scripts/NOTICE.txt +27 -0
  46. package/skills/polishup/scripts/color.mjs +5626 -0
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Use PolishUp for research-informed creation, refinement, or review across fields
3
+ ---
4
+ Use the skill with ID `polishup` and follow its instructions for this request:
5
+
6
+ $ARGUMENTS
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fachriaziz
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,177 @@
1
- # Temporary Holding Version
2
-
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.
1
+ # PolishUp
2
+
3
+ An agent skill for research-informed creation, refinement, and review across fields. Preserve user intent and project conventions; research methods and quality criteria suited to the task.
4
+
5
+ Bundled knowledge covers the domains below. Other fields, such as 3D work, data analysis, and learning materials, use task-specific research and appropriate checks, not a claim of complete specialist expertise.
6
+
7
+ | Domain | Guidance |
8
+ | --- | --- |
9
+ | [Writing](skills/polishup/references/writing/index.md) | Purpose, evidence, structure, language, voice, accessibility, and revision |
10
+ | [UI/UX Design](skills/polishup/references/ui-ux/index.md) | Research, navigation, interaction, visual design, responsiveness, accessibility, and evaluation |
11
+ | [Code](skills/polishup/references/code/index.md) | Readability, simplicity, correctness, and proportionate verification |
12
+
13
+ ## Installation
14
+
15
+ ### Local installer
16
+
17
+ With Node.js 22 or newer, open a terminal in the PolishUp checkout or extracted installer package:
18
+
19
+ ```text
20
+ npm start
21
+ ```
22
+
23
+ Choose one or more harnesses and project or personal scope. `install` is an optional alias for the same setup. Project scope uses the nearest Git root, or the current directory without Git. Running from the PolishUp checkout selects that checkout, not another project.
24
+
25
+ This runs the local installer without downloading PolishUp from npm. To target another project, run `node "<path-to-polishup>/cli/index.mjs"` from that project's directory instead.
26
+
27
+ The installer supports the nine harnesses below and custom destinations. It checks conflicts, preserves backups outside skill discovery, and displays the affected paths. Shared project locations are written once; failures in independent targets are reported separately.
28
+
29
+ Use `--help` for optional flags. `--dry-run` previews changes; `--agent` and `--scope` support noninteractive use. Choose `--agent manual --destination <path> --scope project|user` for a custom folder ending in `polishup`. This copies files without registering discovery. `--replace` explicitly backs up and replaces conflicting content.
30
+
31
+ ### npm installer
32
+
33
+ With Node.js 22 or newer, run from the destination project:
34
+
35
+ ```text
36
+ npx polishup-cli
37
+ ```
38
+
39
+ The npm package is named `polishup-cli`; the skill, plugin and executable remain `polishup`. No npm account is needed to install a public package.
40
+
41
+ ### Manual installation
42
+
43
+ Copy the complete `skills/polishup/` directory to one destination below. Preserve `SKILL.md`, `LICENSE.txt`, `references/`, `scripts/`, notices and relative paths; avoid an extra nested `skills/polishup/` inside the destination. Copying and reading the skill needs no runtime or package manager. The optional executable helper needs Node.js 22+.
44
+
45
+ | Harness | Project skill directory | Default personal skill directory |
46
+ | --- | --- | --- |
47
+ | [Codex](https://developers.openai.com/codex/skills) | `.agents/skills/polishup/` | `~/.agents/skills/polishup/` |
48
+ | [Claude Code](https://code.claude.com/docs/en/skills) | `.claude/skills/polishup/` | `~/.claude/skills/polishup/` |
49
+ | [OpenCode](https://opencode.ai/docs/skills/) | `.opencode/skills/polishup/` | `~/.config/opencode/skills/polishup/` |
50
+ | [Cursor](https://cursor.com/docs/skills) | `.cursor/skills/polishup/` | `~/.cursor/skills/polishup/` |
51
+ | [Oh My Pi (OMP)](https://github.com/can1357/oh-my-pi/blob/main/docs/skills.md) | `.omp/skills/polishup/` | `~/.omp/agent/skills/polishup/` |
52
+ | [Gemini CLI](https://geminicli.com/docs/cli/skills/) | `.gemini/skills/polishup/` | `~/.gemini/skills/polishup/` |
53
+ | [GitHub Copilot](https://docs.github.com/en/copilot/concepts/customizations/agent-skills) | `.github/skills/polishup/` | `~/.copilot/skills/polishup/` |
54
+ | [Antigravity](https://antigravity.google/docs/skills) | `.agents/skills/polishup/` | `~/.gemini/config/skills/polishup/` |
55
+ | [Hermes](https://github.com/NousResearch/hermes-agent/blob/main/agent/skill_utils.py) | `.agents/skills/polishup/` | `<effective Hermes home>/skills/polishup/` |
56
+
57
+ `~` means your home directory. These are default locations; the installer honors the following overrides for personal scope:
58
+
59
+ - Codex: an existing `CODEX_HOME` selects its backward-compatible `skills/` location. Claude uses `CLAUDE_CONFIG_DIR`; OpenCode uses `OPENCODE_CONFIG_DIR` or its `XDG_CONFIG_HOME` location.
60
+ - Gemini: `<GEMINI_CLI_HOME>/.gemini/skills/polishup/`; relative home overrides resolve from the working directory.
61
+ - OMP: set `PI_CODING_AGENT_DIR` for a custom agent directory, or choose a manual destination when its profile location is unresolved.
62
+ - Hermes: honors `HERMES_HOME` and `HERMES_DATA_DIR_SUFFIX`; default homes are `~/.hermes` on POSIX and `%LOCALAPPDATA%/hermes` on Windows. `--profile` selects an existing named personal profile. Project discovery requires a trusted Git project; installation does not grant trust.
63
+
64
+ For OpenCode's `/polishup` command, also copy `.opencode/commands/polishup.md` into the corresponding project or personal `commands/` directory. The installer does this automatically. No JavaScript plugin is needed for the skill or command.
65
+
66
+ The source checkout also includes seven generated native skill copies at the project locations above. They offer direct-copy routes to the same knowledge. Cloning the checkout does not install them into unrelated projects.
67
+
68
+ ### Native plugins
69
+
70
+ These alternatives require the source checkout. Plugin manifests are not included in the standalone npm archive, and the local installer does not register or enable plugins.
71
+
72
+ | Host | Source route |
73
+ | --- | --- |
74
+ | Claude Code | `.claude-plugin/plugin.json`; load locally with `claude --plugin-dir "<path-to-polishup>"` |
75
+ | Codex | Root `plugin.json`, `.codex-plugin/plugin.json`, and `.agents/plugins/marketplace.json`; register the root as a local marketplace, then add `polishup@polishup-local` through the host |
76
+ | Antigravity | `.antigravity-plugin/plugin.json`; use its documented plugin manager |
77
+ | Cursor and OMP | Portable `plugin.json` is present; native plugin installation and activation remain unverified |
78
+
79
+ ## Usage
80
+
81
+ State the task, target, and constraints:
82
+
83
+ - "Use PolishUp to draft a product announcement from these facts."
84
+ - "Use PolishUp to refine this interface. Preserve its visual identity."
85
+ - "Use PolishUp to review this function. Report findings without editing it."
86
+ - "Use PolishUp to plan a Blender product render. Research methods for my version and delivery requirements."
87
+
88
+ Review reports findings without editing the target. Refine preserves satisfactory work; Create produces new work; Redesign changes the agreed aspects. These are optional action labels on one skill.
89
+
90
+ Type native invocations in the agent prompt, not the OS terminal:
91
+
92
+ | Harness | Invocation |
93
+ | --- | --- |
94
+ | Codex | `$polishup review ...`, or select it in the skills menu |
95
+ | Claude Code, OpenCode, Antigravity | `/polishup review ...`; Claude plugin skills use the host's namespace |
96
+ | Cursor | Type `/` and select `polishup` in Agent chat |
97
+ | OMP | `/skill:polishup ...` when skill commands are enabled; otherwise request it by name |
98
+ | Hermes | `/skill polishup`, then state the task |
99
+ | Gemini CLI and supported Copilot clients | Request PolishUp by name; approve native activation when prompted |
100
+
101
+ PolishUp requires initial research into applicable methods, quality criteria, and documented failures. Depth follows the task; evidence already checked for it can be reused. Research supports decisions and does not replace checking the actual result. When current research cannot be accessed, the agent must disclose the limitation and avoid unsupported claims.
102
+
103
+ Domain rules and topic references apply selectively. Interface styling restrictions do not govern standalone 3D work or other visual media. The Markdown skill requires no particular model, framework, interpreter, MCP server, or hook; research and artifact checks use available tools. Discovery and available commands depend on the host. Personal installation does not automatically reach cloud or remote sessions.
104
+
105
+ ## Update and uninstall
106
+
107
+ For a Git checkout, pull the current source and run the local installer again to apply it to the selected destinations:
108
+
109
+ ```text
110
+ git pull
111
+ npm start
112
+ ```
113
+
114
+ For npm installations, run `npx polishup-cli update` from the destination project. This checks the registry for a newer installer before applying managed changes. Use `npx polishup-cli uninstall` to remove a registered installation.
115
+
116
+ For a checkout or extracted package, use `npm start -- uninstall`. The CLI selects a single registered consumer automatically or asks you to choose among registered consumers. Unmanaged folders require explicit harness selection; custom destinations require `--agent manual --destination <path> --scope project|user`.
117
+
118
+ Keep the displayed backup paths and inspect interrupted-operation locks before removing them. Uninstalling one registered Codex, Antigravity, or Hermes project consumer retains shared files while another registered consumer remains. Other readers of compatible paths cannot be enumerated.
119
+
120
+ For manual updates, preserve customizations outside discovery roots and replace the complete selected skill. For manual removal, delete or move that exact directory outside discovery roots; renaming it within a scanned directory may leave it discoverable. Instructions already loaded can remain in the current session.
121
+
122
+ Use the original manager for manager-owned installations. Avoid installing the same skill through several routes in one scope without a concrete need.
123
+
124
+ ## Optional tools
125
+
126
+ PolishUp uses suitable tools already available in the harness or project. Its [tools reference](skills/polishup/references/tools.md) guides scoped inspection, checks and evidence reporting. No browser provider, MCP, hooks or setup document is required.
127
+
128
+ The complete skill includes a ready-to-run helper for color-pair checking, five harmony methods, constrained role adjustment and an optional static preview. Node.js 22+ is required; no global CLI, npm dependencies or build step is needed to use it. From this package directory:
129
+
130
+ ```text
131
+ node skills/polishup/scripts/color.mjs check "#222222" "#ffffff" --json
132
+ node skills/polishup/scripts/color.mjs generate --input palette.json --preview preview.html --json
133
+ ```
134
+
135
+ For an installed skill, use its actual absolute `scripts/color.mjs` path. The optional package CLI, `node cli/index.mjs color ...`, uses the same prepared implementation. Read [Color Tools](skills/polishup/references/colors.md) for inputs and limits and preserve the [bundled dependency notice](skills/polishup/scripts/NOTICE.txt). Output is report-only except for an explicitly requested new preview. Color checks do not establish full accessibility or design quality.
136
+
137
+ ## Troubleshooting
138
+
139
+ - **Skill not listed:** check the complete references tree, exact `SKILL.md` filename and case, selected scope/profile, duplicate copies, and host permissions. Refresh through the host's supported mechanism.
140
+ - **Conflict or unsafe path:** inspect local changes and backups. Use the intended physical path instead of a symlink/junction. Do not remove ownership markers or locks to force replacement.
141
+ - **Native discovery unavailable:** provide the installed `SKILL.md` path and ask the agent to read it and only relevant linked references. Supply the texts directly if file access is unavailable. This does not register native discovery.
142
+ - **Windows PowerShell blocks npm:** use `npm.cmd` for development commands; no execution-policy change is needed. Quote paths containing spaces and preserve Unicode filenames.
143
+ - **Custom Hermes path fails:** POSIX variable names are case-sensitive; Windows expansion is case-insensitive. `%NAME%` expansion is Windows-only; `$NAME` and `${NAME}` are also supported. Undefined referenced variables stop installation.
144
+
145
+ To check loading, request a review of a supplied paragraph without editing it. Inspect exposed skill events or file-read records where available. Installed files, a listed skill, loaded instructions, and applied references are separate observations; an answer mentioning PolishUp proves none of them alone.
146
+
147
+ ## Development
148
+
149
+ Run development commands from the `polishup` directory in the source checkout. Install locked dependencies once before development checks. Edit knowledge only in `skills/polishup/`, then synchronize native copies and run checks:
150
+
151
+ ```text
152
+ npm ci --ignore-scripts
153
+ npm run sync
154
+ npm test
155
+ ```
156
+
157
+ `npm run sync` prepares the helper and notices, then updates the repository's native skill copies. Edit helper logic in `cli/color.mjs`, `cli/palette.mjs`, and `cli/color-entry.mjs`; do not hand-edit the prepared `skills/polishup/scripts/` files. The native exporter protects unmarked, locally edited, extra, or linked files. Preserve intended customizations before regeneration; missing generated files can be restored. `npm test` checks prepared-helper and full-tree freshness before the tests. `npm run check` performs those freshness checks without changing files. Existing complete skill copies are ready to use without rebuilding.
158
+
159
+ Plugin manifests point to the canonical source. Destinations live in `cli/hosts.mjs`; the authored OpenCode command lives in `.opencode/commands/polishup.md`. The `.polishup-export.json` marker identifies a generated native copy, not an installer-owned installation.
160
+
161
+ Inspect the npm payload without publishing:
162
+
163
+ ```text
164
+ npm pack --dry-run --json --ignore-scripts
165
+ ```
166
+
167
+ To create an archive, omit `--dry-run` and add `--pack-destination <existing-output-directory>`. npm needs a writable cache. The package includes the complete skill and prepared helper, four installer CLI modules, OpenCode command, README, and package metadata. Color.js and esbuild are development dependencies only. Tests, helper source/build tooling, native exports, source manifests, and development records are excluded. No `dist/` directory or install-time compilation is used.
168
+
169
+ Notable user-facing changes belong in the source checkout's `CHANGELOG.md`. Routine internal cleanup and research notes are not release notes.
170
+
171
+ ## Project status
172
+
173
+ The installer targets Windows, Linux, and macOS, subject to host availability. The [Checks workflow](https://github.com/fachriaziz/polishup/actions/workflows/checks.yml) runs installer and package checks on all three OS families using Node.js 22; inspect the latest run for results. Mechanical checks do not establish automatic activation, output quality, token savings, or cross-harness effectiveness.
174
+
175
+ ## License
176
+
177
+ [MIT](LICENSE), copyright (c) 2026 fachriaziz. Standalone skill copies include `LICENSE.txt`; the bundled Color.js helper retains its [third-party notice](skills/polishup/scripts/NOTICE.txt).
package/cli/hosts.mjs ADDED
@@ -0,0 +1,171 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import { createHash } from 'node:crypto';
4
+ import path from 'node:path';
5
+
6
+ export const HOSTS = {
7
+ codex: { projectDir: '.agents', label: 'Codex', invocation: '$polishup review ...' },
8
+ claude: { projectDir: '.claude', label: 'Claude Code', invocation: '/polishup review ...' },
9
+ opencode: { projectDir: '.opencode', label: 'OpenCode', invocation: '/polishup review ...' },
10
+ cursor: { projectDir: '.cursor', label: 'Cursor', invocation: '/polishup review ... (select the skill in Agent chat)' },
11
+ omp: { projectDir: '.omp', label: 'Oh My Pi (OMP)', invocation: '/skill:polishup review ... (when skill commands are enabled)' },
12
+ gemini: { projectDir: '.gemini', label: 'Gemini CLI', invocation: 'Use the polishup skill to review ...; approve native activation when prompted.' },
13
+ copilot: { projectDir: '.github', label: 'GitHub Copilot', invocation: 'Use the polishup skill to review ...' },
14
+ antigravity: { projectDir: '.agents', label: 'Antigravity', invocation: '/polishup review ...' },
15
+ hermes: { projectDir: '.agents', label: 'Hermes', invocation: '/skill polishup (then state the task and target)' },
16
+ manual: { label: 'Manual destination', invocation: 'Read the installed SKILL.md and follow its linked references.' },
17
+ };
18
+
19
+ export function getStorageGroup(agent, scope) {
20
+ return scope === 'project' && HOSTS[agent]?.projectDir === '.agents' ? 'agents-project' : `${agent}-${scope}`;
21
+ }
22
+ const PROFILE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
23
+ const RESERVED_PROFILES = new Set(['hermes', 'default', 'test', 'tmp', 'root', 'sudo']);
24
+
25
+ function projectRootFor(cwd) {
26
+ let current = path.resolve(cwd);
27
+ while (true) {
28
+ if (fs.existsSync(path.join(current, '.git'))) return current;
29
+ const parent = path.dirname(current);
30
+ if (parent === current) return path.resolve(cwd);
31
+ current = parent;
32
+ }
33
+ }
34
+
35
+ function expandHome(value, home) {
36
+ return value === '~' || value.startsWith(`~${path.sep}`) || value.startsWith('~/') || value.startsWith('~\\')
37
+ ? path.join(home, value.slice(2))
38
+ : value;
39
+ }
40
+
41
+ function expandHermesPath(value, { home, env, cwd, platform }) {
42
+ let unresolved = false;
43
+ const expanded = expandHome(value, home).replace(/%([^%]+)%|\$\{([^}]+)\}|\$([A-Za-z0-9_]+)/g, (match, win, braced, plain) => {
44
+ if (win && platform !== 'win32') return match;
45
+ const key = win || braced || plain;
46
+ const result = env[key] ?? (platform === 'win32'
47
+ ? Object.entries(env).find(([name]) => name.toLowerCase() === key.toLowerCase())?.[1]
48
+ : undefined);
49
+ if (result === undefined) { unresolved = true; return match; }
50
+ return result;
51
+ });
52
+ if (unresolved) throw new Error('HERMES_HOME contains an environment variable that is not set.');
53
+ return path.resolve(cwd, expanded);
54
+ }
55
+
56
+ function hermesDefaultHome({ home, env, platform }) {
57
+ const suffix = env.HERMES_DATA_DIR_SUFFIX || '';
58
+ if (platform === 'win32') {
59
+ const local = env.LOCALAPPDATA || path.join(home, 'AppData', 'Local');
60
+ return path.join(local, `hermes${suffix}`);
61
+ }
62
+ return path.join(home, `.hermes${suffix}`);
63
+ }
64
+
65
+ function relativeName(root, candidate, leaf) {
66
+ const rel = path.relative(path.resolve(root), path.resolve(candidate));
67
+ const parts = rel.split(path.sep);
68
+ return parts.length === 2 && parts[0] === leaf ? parts[1] : null;
69
+ }
70
+
71
+ function hermesTargetHome({ home, env, cwd, platform, profile }) {
72
+ const defaultHome = hermesDefaultHome({ home, env, platform });
73
+ const configuredHome = env.HERMES_HOME?.trim()
74
+ ? expandHermesPath(env.HERMES_HOME.trim(), { home, env, cwd, platform })
75
+ : defaultHome;
76
+ const configuredProfileRoot = path.basename(path.dirname(configuredHome)) === 'profiles'
77
+ ? path.dirname(path.dirname(configuredHome))
78
+ : configuredHome;
79
+ if (profile) {
80
+ if (!PROFILE_NAME.test(profile) || RESERVED_PROFILES.has(profile)) throw new Error('Invalid Hermes profile name. Use an existing lowercase profile name of up to 64 characters.');
81
+ const profileHome = path.join(configuredProfileRoot, 'profiles', profile);
82
+ if (!fs.statSync(profileHome, { throwIfNoEntry: false })?.isDirectory()) {
83
+ throw new Error(`Hermes profile "${profile}" does not exist at ${profileHome}.`);
84
+ }
85
+ return { home: profileHome, profile };
86
+ }
87
+ if (env.HERMES_HOME?.trim()) return { home: configuredHome, profile: relativeName(configuredProfileRoot, configuredHome, 'profiles') || (path.resolve(configuredHome) === path.resolve(defaultHome) ? 'default' : 'custom') };
88
+ return { home: defaultHome, profile: 'default' };
89
+ }
90
+
91
+ export function getTarget({ agent, scope, cwd = process.cwd(), home = os.homedir(), env = process.env, profile, platform = process.platform }) {
92
+ const definition = HOSTS[agent];
93
+ if (!definition) throw new Error(`Unknown agent: ${agent}`);
94
+ if (agent === 'manual') throw new Error('Use getManualTarget with an explicit manual destination.');
95
+ if (!['project', 'user'].includes(scope)) throw new Error(`Unknown scope: ${scope}`);
96
+ if (profile && agent !== 'hermes') throw new Error('--profile only applies to Hermes.');
97
+
98
+ const projectRoot = projectRootFor(cwd);
99
+ const base = scope === 'project' ? projectRoot : path.resolve(home);
100
+ let configRoot, effectiveProfile = null;
101
+ if (scope === 'project') {
102
+ if (agent === 'hermes' && !fs.existsSync(path.join(projectRoot, '.git'))) {
103
+ throw new Error('Hermes project skills require a Git project root. Use user scope or initialize/review the project repository first.');
104
+ }
105
+ configRoot = path.join(base, definition.projectDir || '.agents');
106
+ } else if (agent === 'codex') {
107
+ if (env.CODEX_HOME) {
108
+ const codexHome = path.resolve(env.CODEX_HOME);
109
+ if (!fs.statSync(codexHome, { throwIfNoEntry: false })?.isDirectory()) {
110
+ throw new Error(`CODEX_HOME must name an existing directory: ${codexHome}`);
111
+ }
112
+ configRoot = codexHome;
113
+ } else configRoot = path.join(base, '.agents');
114
+ } else if (agent === 'claude') {
115
+ configRoot = path.resolve(env.CLAUDE_CONFIG_DIR || path.join(base, '.claude'));
116
+ } else if (agent === 'opencode') {
117
+ configRoot = path.resolve(env.OPENCODE_CONFIG_DIR || path.join(env.XDG_CONFIG_HOME || path.join(base, '.config'), 'opencode'));
118
+ } else if (agent === 'antigravity') {
119
+ configRoot = path.join(base, '.gemini', 'config');
120
+ } else if (agent === 'cursor' || agent === 'copilot') {
121
+ configRoot = path.join(base, agent === 'cursor' ? '.cursor' : '.copilot');
122
+ } else if (agent === 'gemini') {
123
+ configRoot = path.resolve(cwd, env.GEMINI_CLI_HOME || base, '.gemini');
124
+ } else if (agent === 'omp') {
125
+ if (!env.PI_CODING_AGENT_DIR && (env.OMP_PROFILE || env.PI_PROFILE || env.PI_CONFIG_DIR || (platform === 'linux' && env.XDG_DATA_HOME))) {
126
+ throw new Error('OMP uses a custom profile or data directory. Set PI_CODING_AGENT_DIR to the effective agent directory, or use --agent manual --destination <effective-agent-dir>/skills/polishup.');
127
+ }
128
+ configRoot = path.resolve(expandHome(env.PI_CODING_AGENT_DIR || path.join(base, '.omp', 'agent'), base));
129
+ } else {
130
+ const resolved = hermesTargetHome({ home: base, env, cwd, platform, profile });
131
+ configRoot = resolved.home;
132
+ effectiveProfile = resolved.profile;
133
+ }
134
+
135
+ const storageGroup = getStorageGroup(agent, scope);
136
+ const target = {
137
+ agent, scope, profile: effectiveProfile, projectRoot, configRoot,
138
+ skillDir: path.join(configRoot, 'skills', 'polishup'),
139
+ stateRoot: path.join(configRoot, '.polishup'),
140
+ storageGroup,
141
+ consumer: { agent, scope, profile: effectiveProfile },
142
+ invocation: definition.invocation,
143
+ discoveryNote: agent === 'hermes' && scope === 'project'
144
+ ? 'Hermes loads project skills only from trusted Git projects. This installer does not grant trust.'
145
+ : null,
146
+ commandFile: agent === 'opencode' ? path.join(configRoot, 'commands', 'polishup.md') : null,
147
+ };
148
+ return target;
149
+ }
150
+
151
+ export function getManualTarget({ destination, scope, cwd = process.cwd(), home = os.homedir(), platform = process.platform }) {
152
+ if (typeof destination !== 'string' || !destination.trim()) throw new Error('Manual installation requires --destination <path>.');
153
+ if (!['project', 'user'].includes(scope)) throw new Error('Manual destination requires --scope project or user.');
154
+ const skillDir = path.resolve(cwd, destination.trim());
155
+ const name = path.basename(skillDir);
156
+ if ((platform === 'win32' ? name.toLowerCase() : name) !== 'polishup') throw new Error('The manual destination must name the final `polishup` skill folder.');
157
+ const projectRoot = projectRootFor(cwd);
158
+ const stateBase = scope === 'project' ? projectRoot : path.resolve(home);
159
+ const key = createHash('sha256').update(platform === 'win32' ? skillDir.toLowerCase() : skillDir).digest('hex').slice(0, 24);
160
+ const profileKey = platform === 'win32' ? skillDir.toLowerCase() : skillDir;
161
+ return {
162
+ agent: 'manual', scope, profile: profileKey, projectRoot,
163
+ configRoot: path.dirname(skillDir), skillDir,
164
+ stateRoot: path.join(stateBase, '.polishup', 'manual', key),
165
+ storageGroup: `manual-${scope}`,
166
+ consumer: { agent: 'manual', scope, profile: profileKey },
167
+ invocation: HOSTS.manual.invocation,
168
+ discoveryNote: 'The skill is outside a harness-managed default location. Load the displayed SKILL.md path manually.',
169
+ commandFile: null,
170
+ };
171
+ }
package/cli/index.mjs ADDED
@@ -0,0 +1,256 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { parseArgs } from 'node:util';
7
+ import { createInterface } from 'node:readline/promises';
8
+ import { AGENTS, loadPayload, getManualTarget, getTarget, inspect, plan, apply } from './installations.mjs';
9
+ import { checkUpdate, forwardedTargetArgs, runNewVersion } from './update.mjs';
10
+
11
+ const packageRoot = fileURLToPath(new URL('../', import.meta.url));
12
+ const metadata = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
13
+ const helpCommand = metadata.private ? 'node "<path-to-polishup>/cli/index.mjs"' : `npx ${metadata.name}`;
14
+ const HELP = `PolishUp ${metadata.version}
15
+
16
+ Usage: ${helpCommand} [install|update|uninstall|color] [options]
17
+
18
+ install Guided setup (also used when no command is given)
19
+ update Update an existing installation
20
+ uninstall Remove an installation
21
+ color check|generate Check color pairs or generate palette candidates
22
+
23
+ Choose the harness and location in the menu. Flags are optional:
24
+ --agent <id[,id...]> Select one or more harnesses (for example codex,claude)
25
+ --scope project|user Select the installation scope
26
+ --profile <name> Select an existing Hermes user profile
27
+ --destination <path> Set a custom manual skill folder (must end in polishup)
28
+ --dry-run Show changes without writing files
29
+ --replace Back up and replace modified or unmanaged files
30
+ --help Show this help
31
+ --version Show the installer package version
32
+
33
+ Examples:
34
+ ${helpCommand}
35
+ ${helpCommand} update
36
+ ${helpCommand} uninstall
37
+ ${helpCommand} install --agent codex,claude --scope project
38
+ ${helpCommand} install --agent manual --destination ./custom/skills/polishup --scope project
39
+
40
+ ${metadata.private
41
+ ? 'Replace <path-to-polishup> with the absolute package directory. Run from the destination project.\nThis build is unpublished; registry updates are disabled.'
42
+ : 'Registry updates are enabled.'}
43
+ `;
44
+
45
+ function parseAgents(value) {
46
+ if (value === undefined) return [];
47
+ const agents = value.split(',').map(item => item.trim());
48
+ if (!agents.length || agents.some(agent => !agent)) throw new Error('Use comma-separated harness IDs without empty entries.');
49
+ const unknown = agents.filter(agent => !Object.hasOwn(AGENTS, agent));
50
+ if (unknown.length) throw new Error(`Unknown harness: ${unknown.join(', ')}. Choose --agent ${Object.keys(AGENTS).join(', ')}.`);
51
+ if (new Set(agents).size !== agents.length) throw new Error('List each harness only once in --agent.');
52
+ return agents;
53
+ }
54
+
55
+ function groupTargets(targets) {
56
+ const groups = new Map();
57
+ for (const target of targets) {
58
+ const key = path.resolve(target.skillDir);
59
+ if (!groups.has(key)) groups.set(key, []);
60
+ groups.get(key).push(target);
61
+ }
62
+ return [...groups.values()];
63
+ }
64
+
65
+ async function main() {
66
+ if (process.argv[2] === 'color') {
67
+ const { runCli } = await import('../skills/polishup/scripts/color.mjs');
68
+ process.exitCode = await runCli(process.argv.slice(3));
69
+ return;
70
+ }
71
+ const { values, positionals } = parseArgs({ allowPositionals: true, options: {
72
+ agent: { type: 'string' }, scope: { type: 'string' }, profile: { type: 'string' }, destination: { type: 'string' }, 'dry-run': { type: 'boolean' },
73
+ replace: { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
74
+ } });
75
+ const action = positionals[0] || 'install';
76
+ if (positionals.length > 1 || !['install', 'update', 'uninstall'].includes(action)) throw new Error(`Unknown command: ${positionals.join(' ')}. Run polishup --help.`);
77
+ if (values.help) { console.log(HELP); return; }
78
+ if (values.version) { console.log(metadata.version); return; }
79
+ let agents = parseAgents(values.agent);
80
+ if (values.profile && agents.length === 0) agents = ['hermes'];
81
+ if (values.scope && !['project', 'user'].includes(values.scope)) throw new Error('Choose --scope project or user.');
82
+ if (values.profile && agents.some(agent => agent !== 'hermes' && agent !== 'manual')) throw new Error('--profile only applies to Hermes targets.');
83
+ if (values.profile && values.scope && values.scope !== 'user') throw new Error('--profile requires --scope user.');
84
+ if (values.profile && !values.scope) values.scope = 'user';
85
+ if (values.destination && agents.length && !agents.includes('manual')) throw new Error('--destination requires --agent manual.');
86
+ if (agents.includes('manual') && !values.destination && !process.stdin.isTTY) throw new Error('--agent manual requires --destination <path>.');
87
+
88
+ let reader;
89
+ const ask = async question => {
90
+ if (!process.stdin.isTTY) throw new Error('An interactive terminal is required, or supply --agent and --scope.');
91
+ reader ??= createInterface({ input: process.stdin, output: process.stdout });
92
+ const controller = new AbortController();
93
+ const cancel = () => controller.abort();
94
+ reader.once('SIGINT', cancel);
95
+ try { return (await reader.question(question, { signal: controller.signal })).trim(); }
96
+ catch (error) { if (error.name === 'AbortError' || error.code === 'ERR_USE_AFTER_CLOSE') throw new Error('Cancelled.'); throw error; }
97
+ finally { reader.removeListener('SIGINT', cancel); }
98
+ };
99
+ const choose = async (label, choices) => {
100
+ console.log(label);
101
+ choices.forEach((item, i) => console.log(` ${i + 1}. ${item.label}`));
102
+ const answer = await ask('Choose a number: ');
103
+ const selected = choices[Number(answer) - 1];
104
+ if (!selected) throw new Error('No valid choice selected. Nothing was changed.');
105
+ return selected.value;
106
+ };
107
+
108
+ try {
109
+ let scope = values.scope;
110
+ if (action !== 'install' && agents.length === 0) {
111
+ const candidates = Object.keys(AGENTS).filter(agent => agent !== 'manual').flatMap(agent => ['project', 'user'].map(candidateScope => {
112
+ try { return getTarget({ agent, scope: candidateScope, profile: agent === 'hermes' && candidateScope === 'user' ? values.profile : undefined }); }
113
+ catch { return null; }
114
+ })).filter(target => target && (!values.profile || target.agent === 'hermes') && (!scope || target.scope === scope) && fs.existsSync(target.skillDir))
115
+ .filter(target => {
116
+ try { return inspect(target).hasTarget; }
117
+ // Explicit selection reports invalid receipts or ownership conflicts before any change.
118
+ catch { return false; }
119
+ });
120
+ if (candidates.length === 1) { agents = [candidates[0].agent]; scope ||= candidates[0].scope; }
121
+ else if (candidates.length > 1 && process.stdin.isTTY) {
122
+ const selected = await choose('Choose an existing installation:', candidates.map(target => ({
123
+ label: `${AGENTS[target.agent]} (${target.scope}): ${target.skillDir}`, value: target,
124
+ })));
125
+ agents = [selected.agent];
126
+ scope ||= selected.scope;
127
+ }
128
+ }
129
+ if (!agents.length || !scope) {
130
+ if (!process.stdin.isTTY) throw new Error('Supply --agent and --scope outside an interactive terminal.');
131
+ if (!agents.length) agents = [await choose('Choose a harness:', Object.entries(AGENTS).map(([value, label]) => ({ value, label })))];
132
+ scope ||= await choose('Where should PolishUp be available?', [
133
+ { value: 'project', label: `This project (${process.cwd()})` },
134
+ { value: 'user', label: `All my projects (${os.homedir()})` },
135
+ ]);
136
+ }
137
+ if (values.profile && !agents.includes('hermes')) throw new Error('--profile requires Hermes in the selected --agent list.');
138
+ if (values.destination && !agents.includes('manual')) throw new Error('--destination requires --agent manual.');
139
+ if (agents.includes('manual') && !values.destination) values.destination = await ask('Custom skill folder path (the final folder must be named polishup): ');
140
+ if (action === 'install' && !values.agent && process.stdin.isTTY) {
141
+ while (agents.length < Object.keys(AGENTS).length) {
142
+ const answer = await ask('Install for another harness too? [y/N] ');
143
+ if (!/^y(es)?$/i.test(answer)) break;
144
+ const remaining = Object.entries(AGENTS).filter(([agent]) => !agents.includes(agent));
145
+ agents.push(await choose('Choose another harness:', remaining.map(([value, label]) => ({ value, label }))));
146
+ }
147
+ }
148
+ const payload = loadPayload(packageRoot);
149
+ const entries = [];
150
+ for (const agent of agents) {
151
+ try { entries.push({ targets: [agent === 'manual'
152
+ ? getManualTarget({ destination: values.destination, scope })
153
+ : getTarget({ agent, scope, profile: agent === 'hermes' ? values.profile : undefined })] }); }
154
+ catch (error) { entries.push({ targets: [], label: `${AGENTS[agent]} (${scope})`, error }); }
155
+ }
156
+ for (const group of groupTargets(entries.flatMap(entry => entry.targets))) {
157
+ try {
158
+ const operation = plan(group[0], payload, action, { selectedConsumers: group.map(target => target.consumer) });
159
+ entries.push({ targets: group, operation });
160
+ } catch (error) { entries.push({ targets: group, error }); }
161
+ }
162
+ const prepared = entries.filter(entry => entry.operation || entry.error);
163
+ const valid = prepared.filter(entry => entry.operation);
164
+ const failedBeforeApply = prepared.filter(entry => entry.error);
165
+ console.log(`PolishUp ${metadata.version} | ${action} | ${scope}`);
166
+ for (const entry of failedBeforeApply) console.log(`${entry.label || entry.targets.map(target => AGENTS[target.agent]).join(' + ')}: failed to prepare: ${entry.error.message}`);
167
+ for (const entry of valid) {
168
+ const { operation, targets } = entry;
169
+ const names = targets.map(target => AGENTS[target.agent]).join(' + ');
170
+ const target = operation.target;
171
+ console.log(`${names} | ${operation.kind} | ${target.agent === 'hermes' && target.profile ? `profile ${target.profile} | ` : ''}${target.skillDir}`);
172
+ console.log(` Installed: ${operation.current.receipt?.version || (operation.current.exists ? 'unmanaged' : 'not installed')} | Available: ${payload.version} (${payload.revision.slice(0, 12)})`);
173
+ if (operation.conflicts.length) console.log(` Conflicts: ${operation.conflicts.join('; ')}`);
174
+ for (const noteTarget of targets.filter(item => item.discoveryNote)) console.log(` ${AGENTS[noteTarget.agent]}: ${noteTarget.discoveryNote}`);
175
+ for (const consumer of operation.current.consumers) {
176
+ if (!targets.some(item => item.agent === consumer.agent && item.scope === consumer.scope && item.profile === consumer.profile)) {
177
+ console.log(` Other registered consumer: ${AGENTS[consumer.agent]} (${consumer.scope}${consumer.profile ? `, ${consumer.profile}` : ''})`);
178
+ }
179
+ }
180
+ for (const targetWithCommand of targets.filter(item => item.commandFile)) {
181
+ console.log(` OpenCode command: ${targetWithCommand.commandFile}`);
182
+ const base = scope === 'project' ? process.cwd() : os.homedir();
183
+ for (const folder of ['.agents', '.claude']) {
184
+ const compatible = path.join(base, folder, 'skills', 'polishup');
185
+ if (fs.existsSync(compatible)) console.log(` Also present: ${compatible}. The selected OpenCode location takes precedence.`);
186
+ }
187
+ }
188
+ }
189
+
190
+ if (action === 'update') {
191
+ const release = await checkUpdate(metadata);
192
+ if (release.kind === 'local') console.log('Local build: checking bundled files. Public registry updates are disabled until publication.');
193
+ if (release.kind === 'newer') {
194
+ console.log(`Installer ${release.version} is available.`);
195
+ if (values['dry-run']) { console.log('Dry run: the newer package was not downloaded or executed.'); return; }
196
+ const forwarded = forwardedTargetArgs({ agents, scope, profile: values.profile, destination: values.destination, replace: values.replace });
197
+ reader?.close();
198
+ reader = null;
199
+ await runNewVersion(release.version, forwarded);
200
+ return;
201
+ }
202
+ }
203
+ if (values['dry-run']) {
204
+ for (const entry of valid) apply(entry.operation, { dryRun: true });
205
+ console.log('Dry run: no files were written.');
206
+ if (failedBeforeApply.length) process.exitCode = 1;
207
+ return;
208
+ }
209
+ let replace = values.replace || false;
210
+ if (!replace && valid.some(entry => entry.operation.conflicts.length) && process.stdin.isTTY) {
211
+ replace = /^y(es)?$/i.test(await ask('Back up and replace/remove only the conflicting targets? [y/N] '));
212
+ }
213
+ if (process.stdin.isTTY && !(values.agent && values.scope)) {
214
+ if (!/^y(es)?$/i.test(await ask(`Apply the prepared changes to ${valid.length} target location(s)? [y/N] `))) {
215
+ console.log('Cancelled. No files changed.'); return;
216
+ }
217
+ }
218
+ let failed = failedBeforeApply.length > 0;
219
+ for (const entry of valid) {
220
+ const { operation, targets } = entry;
221
+ const names = targets.map(target => AGENTS[target.agent]).join(' + ');
222
+ if (operation.kind === 'none') { console.log(`${names}: already up to date or not installed.`); continue; }
223
+ if (operation.conflicts.length && !replace) {
224
+ console.log(`${names}: skipped because conflicts were not approved for replacement.`);
225
+ failed = true;
226
+ continue;
227
+ }
228
+ try {
229
+ const result = apply(operation, { replace });
230
+ console.log(`${names}: ${action === 'uninstall' ? result.detached ? 'association removed; shared files retained' : 'removed' : 'installed and verified'}.`);
231
+ if (result.backup) console.log(` Previous files retained at: ${result.backup}`);
232
+ if (action !== 'uninstall') for (const target of targets) console.log(` In ${AGENTS[target.agent]}: ${target.invocation}`);
233
+ } catch (error) {
234
+ console.log(`${names}: failed: ${error.message}`);
235
+ failed = true;
236
+ }
237
+ }
238
+ if (valid.some(entry => entry.operation.kind !== 'none' && entry.operation.conflicts.length === 0) && action !== 'uninstall') {
239
+ console.log('Refresh skills or start a new session if a harness does not show the change. File verification does not prove activation.');
240
+ }
241
+ if (failed) process.exitCode = 1;
242
+ } finally { reader?.close(); }
243
+ }
244
+
245
+ main().catch(error => {
246
+ if (process.argv[2] === 'color') {
247
+ if (process.argv.includes('--json')) console.log(JSON.stringify({ schemaVersion: 1,
248
+ operation: `color.${process.argv[3] || 'unknown'}`, toolVersion: metadata.version,
249
+ status: 'error', message: error.message }));
250
+ else console.error(`PolishUp: ${error.message}`);
251
+ process.exitCode = 2;
252
+ return;
253
+ }
254
+ console.error(`PolishUp: ${error.message}`);
255
+ process.exitCode = error.message === 'Cancelled.' ? 130 : 1;
256
+ });