polishup-cli 0.1.0 → 0.3.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.
- package/.agents/plugins/marketplace.json +20 -0
- package/.antigravity-plugin/plugin.json +12 -0
- package/.claude-plugin/marketplace.json +13 -0
- package/.claude-plugin/plugin.json +12 -0
- package/.codex-plugin/plugin.json +25 -0
- package/.opencode/commands/polishup.md +1 -1
- package/README.md +103 -111
- package/cli/detection.mjs +75 -0
- package/cli/hosts.mjs +11 -1
- package/cli/index.mjs +192 -146
- package/cli/installations.mjs +2 -0
- package/cli/menu.mjs +124 -0
- package/cli/plugins.mjs +61 -0
- package/cli/prompts.mjs +166 -0
- package/cli/update.mjs +3 -2
- package/package.json +68 -53
- package/plugin.json +29 -0
- package/skills/polishup/SKILL.md +1 -1
- package/skills/polishup/agents/openai.yaml +4 -0
- package/skills/polishup/references/colors.md +1 -1
- package/skills/polishup/scripts/color.mjs +1 -1
package/cli/index.mjs
CHANGED
|
@@ -4,9 +4,11 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { parseArgs } from 'node:util';
|
|
7
|
-
import {
|
|
8
|
-
import { AGENTS, loadPayload, getManualTarget, getTarget, inspect, plan, apply } from './installations.mjs';
|
|
7
|
+
import { AGENTS, loadPayload, getManualTarget, getTarget, plan, apply } from './installations.mjs';
|
|
9
8
|
import { checkUpdate, forwardedTargetArgs, runNewVersion } from './update.mjs';
|
|
9
|
+
import { BACK, createPrompts } from './prompts.mjs';
|
|
10
|
+
import { selectSetup } from './menu.mjs';
|
|
11
|
+
import { PLUGIN_HOSTS, pluginCommands, pluginInvocation, runPlugin } from './plugins.mjs';
|
|
10
12
|
|
|
11
13
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
12
14
|
const metadata = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
@@ -15,7 +17,7 @@ const HELP = `PolishUp ${metadata.version}
|
|
|
15
17
|
|
|
16
18
|
Usage: ${helpCommand} [install|update|uninstall|color] [options]
|
|
17
19
|
|
|
18
|
-
install Guided setup (
|
|
20
|
+
install Guided setup (the default for a new installation)
|
|
19
21
|
update Update an existing installation
|
|
20
22
|
uninstall Remove an installation
|
|
21
23
|
color check|generate Check color pairs or generate palette candidates
|
|
@@ -23,10 +25,13 @@ Usage: ${helpCommand} [install|update|uninstall|color] [options]
|
|
|
23
25
|
Choose the harness and location in the menu. Flags are optional:
|
|
24
26
|
--agent <id[,id...]> Select one or more harnesses (for example codex,claude)
|
|
25
27
|
--scope project|user Select the installation scope
|
|
28
|
+
--plugin Use the native Codex or Claude Code plugin manager
|
|
26
29
|
--profile <name> Select an existing Hermes user profile
|
|
27
30
|
--destination <path> Set a custom manual skill folder (must end in polishup)
|
|
28
31
|
--dry-run Show changes without writing files
|
|
29
32
|
--replace Back up and replace modified or unmanaged files
|
|
33
|
+
--plain Use numbered text menus without styling
|
|
34
|
+
--no-input Disable prompts; supply explicit target options
|
|
30
35
|
--help Show this help
|
|
31
36
|
--version Show the installer package version
|
|
32
37
|
|
|
@@ -34,6 +39,7 @@ Examples:
|
|
|
34
39
|
${helpCommand}
|
|
35
40
|
${helpCommand} update
|
|
36
41
|
${helpCommand} uninstall
|
|
42
|
+
${helpCommand} install --plugin --agent codex
|
|
37
43
|
${helpCommand} install --agent codex,claude --scope project
|
|
38
44
|
${helpCommand} install --agent manual --destination ./custom/skills/polishup --scope project
|
|
39
45
|
|
|
@@ -71,175 +77,205 @@ async function main() {
|
|
|
71
77
|
const { values, positionals } = parseArgs({ allowPositionals: true, options: {
|
|
72
78
|
agent: { type: 'string' }, scope: { type: 'string' }, profile: { type: 'string' }, destination: { type: 'string' }, 'dry-run': { type: 'boolean' },
|
|
73
79
|
replace: { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
|
|
80
|
+
plain: { type: 'boolean' }, 'no-input': { type: 'boolean' }, plugin: { type: 'boolean' },
|
|
74
81
|
} });
|
|
75
|
-
|
|
82
|
+
let action = positionals[0] || 'install';
|
|
76
83
|
if (positionals.length > 1 || !['install', 'update', 'uninstall'].includes(action)) throw new Error(`Unknown command: ${positionals.join(' ')}. Run polishup --help.`);
|
|
77
84
|
if (values.help) { console.log(HELP); return; }
|
|
78
85
|
if (values.version) { console.log(metadata.version); return; }
|
|
79
86
|
let agents = parseAgents(values.agent);
|
|
80
87
|
if (values.profile && agents.length === 0) agents = ['hermes'];
|
|
88
|
+
if (values.destination && agents.length === 0) agents = ['manual'];
|
|
81
89
|
if (values.scope && !['project', 'user'].includes(values.scope)) throw new Error('Choose --scope project or user.');
|
|
82
|
-
if (values.profile && agents.
|
|
90
|
+
if (values.profile && !agents.includes('hermes')) throw new Error('--profile only applies to Hermes targets.');
|
|
83
91
|
if (values.profile && values.scope && values.scope !== 'user') throw new Error('--profile requires --scope user.');
|
|
84
92
|
if (values.profile && !values.scope) values.scope = 'user';
|
|
85
93
|
if (values.destination && agents.length && !agents.includes('manual')) throw new Error('--destination requires --agent manual.');
|
|
86
|
-
|
|
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
|
-
};
|
|
94
|
+
const ui = await createPrompts({ plain: values.plain, noInput: values['no-input'] });
|
|
107
95
|
|
|
108
96
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
agents = [selected.agent];
|
|
126
|
-
scope ||= selected.scope;
|
|
97
|
+
ui.intro(`PolishUp ${metadata.version}`);
|
|
98
|
+
const nativePlugins = async (selected, scope) => {
|
|
99
|
+
if (values.profile || values.destination || values.replace) throw new Error('--profile, --destination, and --replace do not apply to native plugins. The host manages plugin locations and conflicts.');
|
|
100
|
+
const operations = selected.map(agent => ({ agent, commands: pluginCommands(agent, action, scope) }));
|
|
101
|
+
console.log(`PolishUp ${metadata.version} | native plugin | ${action} | ${scope}`);
|
|
102
|
+
for (const { agent, commands } of operations) for (const args of commands) console.log(` ${agent} ${args.join(' ')}`);
|
|
103
|
+
if (values['dry-run']) { console.log('Dry run: no native commands were executed.'); return; }
|
|
104
|
+
const invocations = operations.map(({ agent }) => pluginInvocation(agent));
|
|
105
|
+
ui.close();
|
|
106
|
+
for (const [index, { agent }] of operations.entries()) {
|
|
107
|
+
await runPlugin({ agent, action, scope }, { invocation: invocations[index], env: values.plain ? { ...process.env, NO_COLOR: '1' } : process.env });
|
|
108
|
+
console.log(`${PLUGIN_HOSTS[agent]}: native plugin ${action} completed.`);
|
|
109
|
+
if (action !== 'uninstall') {
|
|
110
|
+
const standalone = getTarget({ agent, scope }).skillDir;
|
|
111
|
+
if (fs.existsSync(standalone)) console.log(` Standalone skill also present: ${standalone}. To use only the plugin, remove that copy with ${helpCommand} uninstall --agent ${agent} --scope ${scope}.`);
|
|
112
|
+
}
|
|
127
113
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (!agents.length)
|
|
132
|
-
|
|
133
|
-
|
|
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 }))));
|
|
114
|
+
console.log('Refresh plugins or start a new session in the host. Other plugins and standalone skill copies were not removed.');
|
|
115
|
+
};
|
|
116
|
+
if (values.plugin) {
|
|
117
|
+
if (!agents.length) {
|
|
118
|
+
if (!ui.interactive) throw new Error('Supply --agent codex or --agent claude for native plugin installation outside an interactive terminal.');
|
|
119
|
+
agents = [await ui.choose('Choose a plugin host', Object.entries(PLUGIN_HOSTS).map(([value, label]) => ({ value, label })))];
|
|
146
120
|
}
|
|
121
|
+
await nativePlugins(agents, values.scope || 'user');
|
|
122
|
+
return;
|
|
147
123
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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}` : ''})`);
|
|
124
|
+
const request = { action, explicitAction: positionals.length > 0, agents: [...agents], values: { ...values } };
|
|
125
|
+
let draft;
|
|
126
|
+
while (true) {
|
|
127
|
+
const selection = await selectSetup({ ...request, ui, resume: draft });
|
|
128
|
+
for (const issue of selection.issues || []) console.error(`Needs attention: ${issue.target.skillDir}: ${issue.error.message}`);
|
|
129
|
+
if (selection.action === 'exit') return;
|
|
130
|
+
if (selection.action === 'details') {
|
|
131
|
+
for (const { target, state } of selection.installations) {
|
|
132
|
+
const changed = state.changed.length + state.extra.length + Number(state.commandChanged ||
|
|
133
|
+
(target.commandFile && state.consumer?.commandHash && !state.commandHash));
|
|
134
|
+
console.log(`${AGENTS[target.agent]} | ${target.scope}${target.profile ? ` | profile ${target.profile}` : ''} | ${state.receipt.version}`);
|
|
135
|
+
console.log(` ${target.skillDir}`);
|
|
136
|
+
console.log(` ${changed ? 'Local changes found; replacement requires approval.' : 'Managed files match their installation record.'}`);
|
|
178
137
|
}
|
|
138
|
+
console.log('Local file inspection only; harness activation and registry updates were not checked.');
|
|
139
|
+
const next = await ui.choose('Installation details', [{ value: 'exit', label: 'Exit' }], { back: true });
|
|
140
|
+
if (next === BACK) { draft = undefined; continue; }
|
|
141
|
+
if (selection.issues.length) process.exitCode = 1;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
action = selection.action;
|
|
145
|
+
agents = selection.agents;
|
|
146
|
+
const scope = selection.scope;
|
|
147
|
+
values.profile = selection.profile;
|
|
148
|
+
values.destination = selection.destination;
|
|
149
|
+
if (ui.interactive && selection.canGoBack && action === 'install' && agents.every(agent => Object.hasOwn(PLUGIN_HOSTS, agent)) &&
|
|
150
|
+
(scope === 'user' || !agents.includes('codex'))) {
|
|
151
|
+
const format = await ui.choose('Installation type', [
|
|
152
|
+
{ value: 'skill', label: 'Standalone skill' },
|
|
153
|
+
{ value: 'plugin', label: 'Native plugin', hint: 'Managed by the selected host; Codex plugins also support ChatGPT desktop' },
|
|
154
|
+
], { back: true });
|
|
155
|
+
if (format === BACK) { draft = selection; continue; }
|
|
156
|
+
if (format === 'plugin') { await nativePlugins(agents, scope); return; }
|
|
157
|
+
}
|
|
158
|
+
if (values.profile && !agents.includes('hermes')) throw new Error('--profile requires Hermes in the selected --agent list.');
|
|
159
|
+
if (values.destination && !agents.includes('manual')) throw new Error('--destination requires --agent manual.');
|
|
160
|
+
const payload = loadPayload(packageRoot);
|
|
161
|
+
const entries = [];
|
|
162
|
+
for (const agent of agents) {
|
|
163
|
+
try { entries.push({ targets: [agent === 'manual'
|
|
164
|
+
? getManualTarget({ destination: values.destination, scope })
|
|
165
|
+
: getTarget({ agent, scope, profile: agent === 'hermes' ? values.profile : undefined })] }); }
|
|
166
|
+
catch (error) { entries.push({ targets: [], label: `${AGENTS[agent]} (${scope})`, error }); }
|
|
167
|
+
}
|
|
168
|
+
for (const group of groupTargets(entries.flatMap(entry => entry.targets))) {
|
|
169
|
+
try {
|
|
170
|
+
const operation = plan(group[0], payload, action, { selectedConsumers: group.map(target => target.consumer) });
|
|
171
|
+
entries.push({ targets: group, operation });
|
|
172
|
+
} catch (error) { entries.push({ targets: group, error }); }
|
|
179
173
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
174
|
+
const prepared = entries.filter(entry => entry.operation || entry.error);
|
|
175
|
+
const valid = prepared.filter(entry => entry.operation);
|
|
176
|
+
const failedBeforeApply = prepared.filter(entry => entry.error);
|
|
177
|
+
console.log(`PolishUp ${metadata.version} | ${action} | ${scope}`);
|
|
178
|
+
for (const entry of failedBeforeApply) console.log(`${entry.label || entry.targets.map(target => AGENTS[target.agent]).join(' + ')}: failed to prepare: ${entry.error.message}`);
|
|
179
|
+
for (const entry of valid) {
|
|
180
|
+
const { operation, targets } = entry;
|
|
181
|
+
const names = targets.map(target => AGENTS[target.agent]).join(' + ');
|
|
182
|
+
const target = operation.target;
|
|
183
|
+
console.log(`${names} | ${operation.kind} | ${target.agent === 'hermes' && target.profile ? `profile ${target.profile} | ` : ''}${target.skillDir}`);
|
|
184
|
+
console.log(` Installed: ${operation.current.receipt?.version || (operation.current.exists ? 'unmanaged' : 'not installed')} | Available: ${payload.version} (${payload.revision.slice(0, 12)})`);
|
|
185
|
+
if (operation.conflicts.length) console.log(` Conflicts: ${operation.conflicts.join('; ')}`);
|
|
186
|
+
for (const noteTarget of targets.filter(item => item.discoveryNote)) console.log(` ${AGENTS[noteTarget.agent]}: ${noteTarget.discoveryNote}`);
|
|
187
|
+
for (const consumer of operation.current.consumers) {
|
|
188
|
+
if (!targets.some(item => item.agent === consumer.agent && item.scope === consumer.scope && item.profile === consumer.profile)) {
|
|
189
|
+
console.log(` Other registered consumer: ${AGENTS[consumer.agent]} (${consumer.scope}${consumer.profile ? `, ${consumer.profile}` : ''})`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const targetWithCommand of targets.filter(item => item.commandFile)) {
|
|
193
|
+
console.log(` OpenCode command: ${targetWithCommand.commandFile}`);
|
|
194
|
+
const base = scope === 'project' ? target.projectRoot : os.homedir();
|
|
195
|
+
for (const folder of ['.agents', '.claude']) {
|
|
196
|
+
const compatible = path.join(base, folder, 'skills', 'polishup');
|
|
197
|
+
if (fs.existsSync(compatible)) console.log(` Also present: ${compatible}. The selected OpenCode location takes precedence.`);
|
|
198
|
+
}
|
|
186
199
|
}
|
|
187
200
|
}
|
|
188
|
-
}
|
|
189
201
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
if (action === 'update') {
|
|
203
|
+
const release = await checkUpdate(metadata);
|
|
204
|
+
if (release.kind === 'local') console.log('Local build: checking bundled files. Public registry updates are disabled until publication.');
|
|
205
|
+
if (release.kind === 'newer') {
|
|
206
|
+
console.log(`Installer ${release.version} is available.`);
|
|
207
|
+
if (values['dry-run']) { console.log('Dry run: the newer package was not downloaded or executed.'); return; }
|
|
208
|
+
const forwarded = forwardedTargetArgs({ agents, scope, profile: values.profile, destination: values.destination,
|
|
209
|
+
replace: values.replace, plain: values.plain, noInput: values['no-input'] });
|
|
210
|
+
ui.close();
|
|
211
|
+
await runNewVersion(release.version, forwarded);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (values['dry-run']) {
|
|
216
|
+
for (const entry of valid) apply(entry.operation, { dryRun: true });
|
|
217
|
+
console.log('Dry run: no files were written.');
|
|
218
|
+
if (failedBeforeApply.length) process.exitCode = 1;
|
|
200
219
|
return;
|
|
201
220
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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;
|
|
221
|
+
let replace = values.replace || false;
|
|
222
|
+
if (!replace && valid.some(entry => entry.operation.conflicts.length) && ui.interactive) {
|
|
223
|
+
const choice = await ui.choose('Local changes require a decision', [
|
|
224
|
+
{ value: 'replace', label: 'Back up and replace/remove conflicting targets' },
|
|
225
|
+
{ value: 'skip', label: 'Skip conflicting targets' },
|
|
226
|
+
{ value: 'cancel', label: 'Cancel' },
|
|
227
|
+
], { back: selection.canGoBack });
|
|
228
|
+
if (choice === BACK) { draft = selection; continue; }
|
|
229
|
+
if (choice === 'cancel') { console.log('Cancelled. No files changed.'); return; }
|
|
230
|
+
replace = choice === 'replace';
|
|
216
231
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
232
|
+
const pending = valid.filter(entry => entry.operation.kind !== 'none' && (!entry.operation.conflicts.length || replace));
|
|
233
|
+
if (ui.interactive && selection.canGoBack && (pending.length || failedBeforeApply.length)) {
|
|
234
|
+
const choice = await ui.choose('Review changes', [
|
|
235
|
+
...(pending.length ? [{ value: 'apply', label: `${action === 'uninstall' ? 'Remove' : action === 'update' ? 'Update' : 'Install'} ${pending.length} target location(s)` }] : []),
|
|
236
|
+
{ value: 'cancel', label: 'Cancel' },
|
|
237
|
+
], { back: true });
|
|
238
|
+
if (choice === BACK) { draft = selection; continue; }
|
|
239
|
+
if (choice === 'cancel') {
|
|
240
|
+
console.log('Cancelled. No files changed.'); return;
|
|
241
|
+
}
|
|
227
242
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
243
|
+
let failed = failedBeforeApply.length > 0;
|
|
244
|
+
let changed = 0, unchanged = 0, skipped = 0, failedCount = failedBeforeApply.length;
|
|
245
|
+
for (const entry of valid) {
|
|
246
|
+
const { operation, targets } = entry;
|
|
247
|
+
const names = targets.map(target => AGENTS[target.agent]).join(' + ');
|
|
248
|
+
if (operation.kind === 'none') {
|
|
249
|
+
unchanged++;
|
|
250
|
+
console.log(`${names}: ${action === 'uninstall' ? 'not installed' : 'unchanged; already up to date'}.`);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (operation.conflicts.length && !replace) {
|
|
254
|
+
console.log(`${names}: skipped because conflicts were not approved for replacement.`);
|
|
255
|
+
failed = true;
|
|
256
|
+
skipped++;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
const result = apply(operation, { replace });
|
|
261
|
+
changed++;
|
|
262
|
+
console.log(`${names}: ${action === 'uninstall' ? result.detached ? 'association removed; shared files retained' : 'removed' : operation.current.exists ? 'updated and verified' : 'installed and verified'}.`);
|
|
263
|
+
if (result.backup) console.log(` Previous files retained at: ${result.backup}`);
|
|
264
|
+
if (action !== 'uninstall') for (const target of targets) console.log(` In ${AGENTS[target.agent]}: ${target.invocation}`);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.log(`${names}: failed: ${error.message}`);
|
|
267
|
+
failed = true;
|
|
268
|
+
failedCount++;
|
|
269
|
+
}
|
|
236
270
|
}
|
|
271
|
+
console.log(`Result: ${changed} changed, ${unchanged} unchanged, ${skipped} skipped, ${failedCount} failed.`);
|
|
272
|
+
if (changed && action !== 'uninstall') {
|
|
273
|
+
console.log('Refresh skills or start a new session if a harness does not show the change. File verification does not prove activation.');
|
|
274
|
+
}
|
|
275
|
+
if (failed) process.exitCode = 1;
|
|
276
|
+
return;
|
|
237
277
|
}
|
|
238
|
-
|
|
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(); }
|
|
278
|
+
} finally { ui.close(); }
|
|
243
279
|
}
|
|
244
280
|
|
|
245
281
|
main().catch(error => {
|
|
@@ -253,4 +289,14 @@ main().catch(error => {
|
|
|
253
289
|
}
|
|
254
290
|
console.error(`PolishUp: ${error.message}`);
|
|
255
291
|
process.exitCode = error.message === 'Cancelled.' ? 130 : 1;
|
|
292
|
+
}).finally(async () => {
|
|
293
|
+
// Windows console reads can survive readline cleanup after revisiting prompts.
|
|
294
|
+
// Finish only after the command and its output are complete, including updater children.
|
|
295
|
+
if (process.platform === 'win32' && process.stdin.isTTY) {
|
|
296
|
+
await Promise.all([process.stdout, process.stderr].map(stream => new Promise(resolve => {
|
|
297
|
+
if (stream.destroyed || !stream.writable) resolve();
|
|
298
|
+
else stream.write('', resolve);
|
|
299
|
+
})));
|
|
300
|
+
process.exit(process.exitCode ?? 0);
|
|
301
|
+
}
|
|
256
302
|
});
|
package/cli/installations.mjs
CHANGED
|
@@ -53,6 +53,8 @@ export function loadPayload(packageRoot) {
|
|
|
53
53
|
const license = path.join(skillRoot, 'LICENSE.txt');
|
|
54
54
|
if (fs.existsSync(license)) files['LICENSE.txt'] = fs.readFileSync(assertSafePath(license));
|
|
55
55
|
Object.assign(files, filesIn(path.join(skillRoot, 'references'), 'references/'));
|
|
56
|
+
const agents = path.join(skillRoot, 'agents');
|
|
57
|
+
if (fs.existsSync(agents)) Object.assign(files, filesIn(agents, 'agents/'));
|
|
56
58
|
const scripts = path.join(skillRoot, 'scripts');
|
|
57
59
|
if (fs.existsSync(scripts)) Object.assign(files, filesIn(scripts, 'scripts/'));
|
|
58
60
|
const hashes = Object.fromEntries(Object.keys(files).sort().map(file => [file, hash(files[file])]));
|
package/cli/menu.mjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { AGENTS, getTarget, getManualTarget, inspect } from './installations.mjs';
|
|
5
|
+
import { projectRootFor, hermesProfiles } from './hosts.mjs';
|
|
6
|
+
import { BACK } from './prompts.mjs';
|
|
7
|
+
import { detectHarnesses } from './detection.mjs';
|
|
8
|
+
|
|
9
|
+
const contextFor = context => ({ cwd: process.cwd(), home: os.homedir(), env: process.env, platform: process.platform, ...context });
|
|
10
|
+
|
|
11
|
+
export function findInstallations(context = {}) {
|
|
12
|
+
const options = contextFor(context);
|
|
13
|
+
const installations = [], issues = [], seen = new Set(), failedPaths = new Set();
|
|
14
|
+
for (const agent of Object.keys(AGENTS).filter(agent => agent !== 'manual')) {
|
|
15
|
+
for (const scope of options.scope ? [options.scope] : ['project', 'user']) {
|
|
16
|
+
let profiles = [undefined];
|
|
17
|
+
if (agent === 'hermes' && scope === 'user') {
|
|
18
|
+
try { profiles = options.profile ? [options.profile] : [undefined, ...hermesProfiles(options)]; }
|
|
19
|
+
catch { /* Explicit Hermes selection reports profile-resolution errors. */ }
|
|
20
|
+
}
|
|
21
|
+
for (const profile of profiles) {
|
|
22
|
+
let target;
|
|
23
|
+
try { target = getTarget({ ...options, agent, scope, profile }); }
|
|
24
|
+
catch { continue; }
|
|
25
|
+
if (!fs.existsSync(target.skillDir)) continue;
|
|
26
|
+
const directory = options.platform === 'win32' ? target.skillDir.toLowerCase() : target.skillDir;
|
|
27
|
+
const key = `${agent}:${scope}:${directory}`;
|
|
28
|
+
if (seen.has(key)) continue;
|
|
29
|
+
seen.add(key);
|
|
30
|
+
try {
|
|
31
|
+
const state = inspect(target);
|
|
32
|
+
if (state.hasTarget) installations.push({ target, state, profile });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (!failedPaths.has(directory)) { issues.push({ target, error }); failedPaths.add(directory); }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { installations, issues };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function harnessChoices(context = {}, found = { installations: [] }) {
|
|
43
|
+
context = contextFor(context);
|
|
44
|
+
const detected = detectHarnesses({ ...context, cwd: projectRootFor(context.cwd) });
|
|
45
|
+
const choices = Object.entries(AGENTS).map(([value, label]) => {
|
|
46
|
+
const scopes = [...new Set(found.installations.filter(entry => entry.target.agent === value).map(entry => entry.target.scope))];
|
|
47
|
+
return { value, label: `${label}${detected[value]?.status === 'detected' ? ' (Detected)' : ''}`,
|
|
48
|
+
...(scopes.length ? { hint: `PolishUp installed: ${scopes.join(', ')}` } : {}) };
|
|
49
|
+
});
|
|
50
|
+
const rank = choice => choice.value === 'manual' ? 2 : detected[choice.value]?.status === 'detected' ? 0 : 1;
|
|
51
|
+
return choices.sort((left, right) => rank(left) - rank(right));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function selectSetup({ action = 'install', explicitAction = false, agents = [], values = {}, ui, context = {}, resume }) {
|
|
55
|
+
context = contextFor(context);
|
|
56
|
+
const found = (!agents.length || ui.interactive) ? findInstallations({ ...context, scope: values.scope, profile: values.profile }) : { installations: [], issues: [] };
|
|
57
|
+
const state = { action, agents: [...agents], scope: values.scope, profile: values.profile, destination: values.destination, ...resume };
|
|
58
|
+
const existingMode = () => state.action !== 'install' && !agents.length && found.installations.length > 0;
|
|
59
|
+
const selectExisting = entry => { state.agents = [entry.target.agent]; state.scope = entry.target.scope; state.profile = entry.profile; };
|
|
60
|
+
const selection = () => ({ action: state.action, agents: state.agents, scope: state.scope,
|
|
61
|
+
profile: state.scope === 'user' && state.agents.includes('hermes') ? state.profile : undefined,
|
|
62
|
+
destination: state.agents.includes('manual') ? state.destination : undefined, issues: found.issues });
|
|
63
|
+
if (!ui.interactive) {
|
|
64
|
+
if (existingMode() && found.installations.length === 1 && !found.issues.length) selectExisting(found.installations[0]);
|
|
65
|
+
if (!state.agents.length || !state.scope) throw new Error('Supply --agent and --scope outside an interactive terminal.');
|
|
66
|
+
if (state.agents.includes('manual') && !state.destination) throw new Error('--agent manual requires --destination <path> when input is disabled.');
|
|
67
|
+
return selection();
|
|
68
|
+
}
|
|
69
|
+
const rootMenu = !explicitAction && !agents.length && !values.destination && !values.profile && Boolean(found.installations.length || found.issues.length);
|
|
70
|
+
const profileStep = () => state.agents.includes('hermes') && state.scope === 'user' && !values.profile && !existingMode();
|
|
71
|
+
const profilesAvailable = () => {
|
|
72
|
+
if (!profileStep()) return false;
|
|
73
|
+
try { return hermesProfiles(context).length > 0; }
|
|
74
|
+
catch { return true; }
|
|
75
|
+
};
|
|
76
|
+
const steps = [
|
|
77
|
+
{ enabled: () => rootMenu, run: opts => ui.choose('What would you like to do?', [
|
|
78
|
+
{ value: 'install', label: 'Install' }, { value: 'update', label: 'Update' },
|
|
79
|
+
{ value: 'uninstall', label: 'Uninstall' }, { value: 'details', label: 'View installation details' }, { value: 'exit', label: 'Exit' },
|
|
80
|
+
], { ...opts, initialValue: state.action }), save: value => { state.action = value; } },
|
|
81
|
+
{ enabled: existingMode, run: opts => ui.choose('Choose an existing installation', found.installations.map(entry => ({
|
|
82
|
+
value: entry, label: `${AGENTS[entry.target.agent]} (${entry.target.scope}${entry.target.profile ? `, ${entry.target.profile}` : ''})`, hint: entry.target.skillDir,
|
|
83
|
+
})), { ...opts, initialValue: found.installations.find(entry => entry.target.agent === state.agents[0] && entry.target.scope === state.scope && entry.profile === state.profile) }), save: selectExisting },
|
|
84
|
+
{ enabled: () => !agents.length && !existingMode(), run: opts => ui.multi('Select harnesses', harnessChoices(context, found),
|
|
85
|
+
{ ...opts, initialValues: state.agents }), save: value => { state.agents = value; } },
|
|
86
|
+
{ enabled: () => !values.scope && !existingMode(), run: opts => ui.choose('Where should PolishUp be available?', [
|
|
87
|
+
{ value: 'project', label: 'This project', hint: projectRootFor(context.cwd) },
|
|
88
|
+
{ value: 'user', label: 'Personal installation', hint: context.home },
|
|
89
|
+
], { ...opts, initialValue: state.scope }), save: value => { state.scope = value; } },
|
|
90
|
+
{ enabled: () => state.agents.includes('manual') && !values.destination,
|
|
91
|
+
run: opts => ui.text('Custom skill folder path (must end in polishup)', { ...opts, initialValue: state.destination, validate(value) {
|
|
92
|
+
try { getManualTarget({ ...context, destination: value, scope: state.scope }); }
|
|
93
|
+
catch (error) { return error.message; }
|
|
94
|
+
} }), save: value => { state.destination = value; } },
|
|
95
|
+
{ enabled: profilesAvailable, run: opts => {
|
|
96
|
+
const configured = getTarget({ ...context, agent: 'hermes', scope: 'user' });
|
|
97
|
+
return ui.choose('Choose a Hermes profile', [{ value: '', label: 'Current location', hint: configured.configRoot },
|
|
98
|
+
...hermesProfiles(context).map(value => ({ value, label: value }))], { ...opts, initialValue: state.profile || '' });
|
|
99
|
+
}, save: value => { state.profile = value || undefined; } },
|
|
100
|
+
];
|
|
101
|
+
const available = () => steps.flatMap((step, index) => step.enabled() ? [index] : []);
|
|
102
|
+
let index = resume ? available().at(-1) : available()[0];
|
|
103
|
+
while (index !== undefined && index < steps.length) {
|
|
104
|
+
if (!steps[index].enabled()) { index++; continue; }
|
|
105
|
+
const previous = available().filter(value => value < index).at(-1);
|
|
106
|
+
let value;
|
|
107
|
+
try { value = await steps[index].run({ back: previous !== undefined }); }
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (error.message === 'Cancelled.') throw error;
|
|
110
|
+
if (!['EACCES', 'EPERM', 'ENOENT', 'ENOTDIR', 'ELOOP'].includes(error.code) && !/^HERMES_HOME|^Hermes profile|^Invalid Hermes/.test(error.message)) throw error;
|
|
111
|
+
value = await ui.choose(`Cannot continue: ${error.message}`, [{ value: 'retry', label: 'Retry' }], { back: true });
|
|
112
|
+
if (value === 'retry') continue;
|
|
113
|
+
}
|
|
114
|
+
if (value === BACK) {
|
|
115
|
+
if (previous === undefined) throw new Error('Cancelled.');
|
|
116
|
+
index = previous;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
steps[index].save(value);
|
|
120
|
+
if (state.action === 'exit' || state.action === 'details') return { action: state.action, ...found };
|
|
121
|
+
index++;
|
|
122
|
+
}
|
|
123
|
+
return { ...selection(), canGoBack: available().length > 0 };
|
|
124
|
+
}
|
package/cli/plugins.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { detectHarnesses } from './detection.mjs';
|
|
5
|
+
|
|
6
|
+
export const PLUGIN_HOSTS = { codex: 'Codex / ChatGPT desktop', claude: 'Claude Code' };
|
|
7
|
+
const selector = 'polishup@polishup-local';
|
|
8
|
+
const repository = 'fachriaziz/polishup';
|
|
9
|
+
|
|
10
|
+
export function pluginCommands(agent, action, scope = 'user') {
|
|
11
|
+
if (!Object.hasOwn(PLUGIN_HOSTS, agent)) throw new Error('Native plugin installation supports Codex and Claude Code. Use the skill installer for other agents.');
|
|
12
|
+
if (!['install', 'update', 'uninstall'].includes(action)) throw new Error('Invalid plugin action.');
|
|
13
|
+
if (!['user', 'project'].includes(scope)) throw new Error('Invalid plugin scope.');
|
|
14
|
+
if (agent === 'codex' && scope !== 'user') throw new Error('The native Codex CLI manages personal plugins. Use --scope user, or install a project-scoped skill without --plugin.');
|
|
15
|
+
if (agent === 'codex') {
|
|
16
|
+
if (action === 'uninstall') return [['plugin', 'remove', selector]];
|
|
17
|
+
return [action === 'install' ? ['plugin', 'marketplace', 'add', repository]
|
|
18
|
+
: ['plugin', 'marketplace', 'upgrade', 'polishup-local'], ['plugin', 'add', selector]];
|
|
19
|
+
}
|
|
20
|
+
if (action === 'uninstall') return [['plugin', 'uninstall', selector, '--scope', scope]];
|
|
21
|
+
return [action === 'install' ? ['plugin', 'marketplace', 'add', repository]
|
|
22
|
+
: ['plugin', 'marketplace', 'update', 'polishup-local'], ['plugin', action, selector, '--scope', scope]];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function pluginInvocation(agent, { env = process.env, platform = process.platform, launcher } = {}) {
|
|
26
|
+
if (!Object.hasOwn(PLUGIN_HOSTS, agent)) throw new Error('Unsupported plugin host.');
|
|
27
|
+
const detected = launcher ? undefined : detectHarnesses({ env, platform })[agent];
|
|
28
|
+
const executable = launcher || (detected?.status === 'detected' ? detected.evidence : undefined);
|
|
29
|
+
if (!executable) throw new Error(`${PLUGIN_HOSTS[agent]} CLI was not found. Install or update the host CLI, or use its native plugin manager. No host software was installed.`);
|
|
30
|
+
if (platform !== 'win32' || !/\.(cmd|bat)$/i.test(executable)) return { executable, prefix: [] };
|
|
31
|
+
// npm's Windows shims cannot be spawned directly. Resolve the declared Node entry instead.
|
|
32
|
+
const packageName = agent === 'codex' ? '@openai/codex' : '@anthropic-ai/claude-code';
|
|
33
|
+
for (const root of [path.join(path.dirname(executable), 'node_modules', packageName), path.join(path.dirname(executable), '..', packageName)]) {
|
|
34
|
+
const manifest = path.join(root, 'package.json');
|
|
35
|
+
if (!fs.existsSync(manifest)) continue;
|
|
36
|
+
const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'));
|
|
37
|
+
const relative = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.[agent];
|
|
38
|
+
if (pkg.name !== packageName || typeof relative !== 'string') continue;
|
|
39
|
+
const entry = path.resolve(root, relative);
|
|
40
|
+
const contained = path.relative(path.resolve(root), entry);
|
|
41
|
+
if (!contained || contained.startsWith('..') || path.isAbsolute(contained)) throw new Error('Native CLI entry is outside its package.');
|
|
42
|
+
if (fs.statSync(entry, { throwIfNoEntry: false })?.isFile()) return { executable: process.execPath, prefix: [entry] };
|
|
43
|
+
}
|
|
44
|
+
throw new Error('This Windows CLI launcher could not be resolved safely. Use the native plugin commands directly, or install the host native executable.');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const runNative = (executable, args, { cwd = process.cwd(), env = process.env } = {}) => new Promise((resolve, reject) => {
|
|
48
|
+
const child = spawn(executable, args, { cwd, env, stdio: 'inherit', shell: false, windowsHide: true });
|
|
49
|
+
child.once('error', error => reject(new Error(`Cannot run native plugin manager: ${error.message}`)));
|
|
50
|
+
child.once('close', (code, signal) => {
|
|
51
|
+
if (code === 0) resolve();
|
|
52
|
+
else if (code === 130 || signal === 'SIGINT') reject(new Error('Cancelled.'));
|
|
53
|
+
else reject(new Error(`Native plugin manager failed (${signal || `exit ${code}`}). Check its output and host CLI version before retrying.`));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export async function runPlugin({ agent, action, scope = 'user' }, { invocation, run = runNative, cwd, env = process.env, platform } = {}) {
|
|
58
|
+
const commands = pluginCommands(agent, action, scope);
|
|
59
|
+
const resolved = invocation || pluginInvocation(agent, { env, platform });
|
|
60
|
+
for (const args of commands) await run(resolved.executable, [...resolved.prefix, ...args], { cwd, env });
|
|
61
|
+
}
|