@adityaaria/spark 6.0.4 → 6.0.5

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/bin/spark.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { run } from '../src/cli/index.js';
3
+ import { formatError } from '../src/cli/output.js';
3
4
 
4
5
  run(process.argv.slice(2), process.env).catch((error) => {
5
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
6
+ process.stderr.write(`${formatError(error instanceof Error ? error.message : String(error))}\n`);
6
7
  process.exitCode = 1;
7
8
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adityaaria/spark",
3
- "version": "6.0.4",
3
+ "version": "6.0.5",
4
4
  "description": "SPARK skills and runtime bootstrap for coding agents",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,10 +1,22 @@
1
- import { printLine } from './output.js';
1
+ import {
2
+ bullet,
3
+ commandText,
4
+ labelValue,
5
+ pathText,
6
+ printCommandHeader,
7
+ printLine,
8
+ printSection,
9
+ printSummary,
10
+ statusText,
11
+ step,
12
+ } from './output.js';
2
13
  import { askQuestion } from './prompt.js';
3
14
  import { chooseHarness } from '../installer/detect.js';
4
15
  import { InstallerError } from '../installer/errors.js';
5
16
  import fs from 'node:fs';
6
17
 
7
18
  export async function runInstall(options, env) {
19
+ printCommandHeader('Install');
8
20
  const selection = await chooseHarness({
9
21
  forcedHarness: normalizeHarness(options.harness),
10
22
  env,
@@ -15,11 +27,13 @@ export async function runInstall(options, env) {
15
27
  const plan = adapter.planInstall();
16
28
 
17
29
  if (options.dryRun) {
18
- printLine(`dry-run: selected adapter ${adapter.label} (${adapter.id})`);
19
- printLine(`dry-run: selection source ${source}`);
20
- printLine(`dry-run: would install SPARK for ${adapter.label}`);
21
- printLine(`dry-run: bootstrap ${plan.bootstrap}`);
22
- printLine('dry-run: no filesystem changes made');
30
+ printSection('Preview');
31
+ printLine(labelValue('Mode', 'dry-run'));
32
+ printLine(labelValue('Harness', `${adapter.label} (${adapter.id})`));
33
+ printLine(labelValue('Selection', source));
34
+ printLine(labelValue('Bootstrap', plan.bootstrap));
35
+ printPlanDetails(plan, {});
36
+ printSummary('Nothing changed', [bullet('No filesystem changes were made.')], 'info');
23
37
  return;
24
38
  }
25
39
 
@@ -27,21 +41,100 @@ export async function runInstall(options, env) {
27
41
  throw new InstallerError(`Install flow for ${adapter.label} is not implemented yet.`);
28
42
  }
29
43
 
30
- if (!plan.command) {
31
- printLine(`No fully automated install command is available for ${adapter.label}.`);
32
- printLine(`Install hint: ${plan.installHint}`);
33
- printLine(`Verify hint: ${plan.verifyHint}`);
44
+ if (!plan.automated) {
45
+ printSection('Install');
46
+ printLine(labelValue('Harness', adapter.label));
47
+ printLine(statusText(`Interactive install is required for ${adapter.label}.`, 'warning'));
48
+ printPlanDetails(plan, {});
49
+ printSummary(
50
+ 'Next step',
51
+ [bullet(`Complete the steps above inside ${adapter.label} and then start a fresh session.`)],
52
+ 'warning'
53
+ );
34
54
  return;
35
55
  }
36
56
 
37
- await adapter.install({ options, env });
57
+ const installResult = await adapter.install({ options, env });
38
58
  if (typeof adapter.verify === 'function') {
39
59
  await adapter.verify({ options, env });
40
60
  }
41
- printLine(`Installed SPARK for ${adapter.label}.`);
61
+ const resolvedPlan = installResult?.plan ?? plan;
62
+ const metadata = installResult?.metadata ?? {};
63
+
64
+ printSection('Install');
65
+ printLine(labelValue('Harness', adapter.label));
66
+ printLine(statusText(resolvedPlan.successMessage ?? plan.successMessage, 'success'));
67
+ printPlanDetails(resolvedPlan, metadata);
68
+ printSummary(
69
+ 'Ready',
70
+ buildReadyLines(adapter, resolvedPlan, metadata),
71
+ 'success'
72
+ );
42
73
  }
43
74
 
44
75
  function normalizeHarness(harness) {
45
76
  if (!harness) return null;
46
77
  return String(harness).trim().toLowerCase();
47
78
  }
79
+
80
+ function printPlanDetails(plan, metadata) {
81
+ if (plan.automated && plan.commands?.length) {
82
+ printLine('');
83
+ printSection('Commands');
84
+ for (const [index, command] of plan.commands.entries()) {
85
+ printLine(step(index + 1, plan.commands.length, commandText(formatCommand(command))));
86
+ }
87
+ }
88
+
89
+ if (plan.automated && plan.automatedSteps?.length) {
90
+ printLine('');
91
+ printSection('Steps');
92
+ for (const [index, automatedStep] of plan.automatedSteps.entries()) {
93
+ printLine(step(index + 1, plan.automatedSteps.length, interpolatePlanText(automatedStep, metadata)));
94
+ }
95
+ }
96
+
97
+ if (!plan.automated && plan.manualSteps?.length) {
98
+ printLine('');
99
+ printSection('Steps');
100
+ for (const [index, manualStep] of plan.manualSteps.entries()) {
101
+ printLine(step(index + 1, plan.manualSteps.length, manualStep));
102
+ }
103
+ }
104
+
105
+ printLine('');
106
+ printSection('Notes');
107
+ printLine(labelValue('Install hint', plan.installHint));
108
+ printLine(labelValue('Verify hint', plan.verifyHint));
109
+ if (metadata.relativeTargetRoot) {
110
+ printLine(labelValue('Bundle path', pathText(metadata.relativeTargetRoot)));
111
+ }
112
+ }
113
+
114
+ function formatCommand(command) {
115
+ return [command.file, ...(command.args ?? [])].join(' ');
116
+ }
117
+
118
+ function interpolatePlanText(text, metadata) {
119
+ return String(text).replaceAll('{targetRoot}', metadata.targetRoot ?? '').replaceAll(
120
+ '{relativeTargetRoot}',
121
+ metadata.relativeTargetRoot ?? ''
122
+ );
123
+ }
124
+
125
+ function buildReadyLines(adapter, plan, metadata) {
126
+ const lines = [];
127
+
128
+ if (metadata.relativeTargetRoot) {
129
+ lines.push(bullet(`Plugin bundle staged at ${pathText(metadata.relativeTargetRoot)}.`));
130
+ }
131
+
132
+ if (adapter.id === 'codex') {
133
+ lines.push(bullet(`In Codex, install or import the local plugin from ${pathText(metadata.relativeTargetRoot ?? '.spark/codex-plugin')}.`));
134
+ lines.push(bullet('Start a fresh Codex session to confirm using-spark loads before coding.'));
135
+ return lines;
136
+ }
137
+
138
+ lines.push(bullet('Start a fresh session in the selected harness to confirm using-spark loads before coding.'));
139
+ return lines;
140
+ }
package/src/cli/output.js CHANGED
@@ -1,13 +1,117 @@
1
+ const COLORS = {
2
+ reset: '\x1b[0m',
3
+ bold: '\x1b[1m',
4
+ dim: '\x1b[2m',
5
+ white: '\x1b[38;2;245;245;245m',
6
+ spark: '\x1b[38;2;255;107;53m',
7
+ accent: '\x1b[38;2;0;245;255m',
8
+ success: '\x1b[38;2;46;204;113m',
9
+ warning: '\x1b[38;2;255;215;0m',
10
+ error: '\x1b[38;2;255;71;87m',
11
+ pink: '\x1b[38;2;255;27;107m',
12
+ dimGray: '\x1b[38;2;107;114;128m',
13
+ };
14
+
15
+ const useColor = process.stdout.isTTY && process.env.NO_COLOR !== '1';
16
+
1
17
  export function printLine(text = '') {
2
18
  process.stdout.write(`${text}\n`);
3
19
  }
4
20
 
5
21
  export function printHelp() {
6
- printLine('SPARK npm installer');
22
+ printCommandHeader('Install');
23
+ printLine(labelValue('Usage', 'npx @adityaaria/spark install [--harness <name>] [--dry-run] [--yes] [--verbose]'));
24
+ printLine('');
25
+ printMuted('Without --harness, the installer will ask which AI assistance to target.');
7
26
  printLine('');
8
- printLine('Usage: npx @adityaaria/spark install [--harness <name>] [--dry-run] [--yes] [--verbose]');
27
+ printLine(labelValue('Supported', 'Codex, Cursor, Antigravity, Copilot, OpenCode, Gemini, Pi'));
28
+ }
29
+
30
+ export function printCommandHeader(title) {
31
+ printLine(styled('⚡', 'warning') + ' ' + styled('SPARK', 'spark', true) + ' ' + styled('›', 'dimGray') + ' ' + styled(title, 'white', true));
32
+ printLine(styled('Skills installer for coding agents', 'dimGray'));
9
33
  printLine('');
10
- printLine('Without --harness, the installer will ask which AI assistance to target.');
34
+ }
35
+
36
+ export function printSection(title) {
37
+ printLine(styled(title, 'accent', true));
38
+ }
39
+
40
+ export function printSummary(title, lines = [], tone = 'info') {
41
+ const toneLabel = {
42
+ info: styled('ℹ', 'accent'),
43
+ success: styled('✓', 'success'),
44
+ warning: styled('•', 'warning'),
45
+ error: styled('✕', 'error'),
46
+ }[tone];
47
+
11
48
  printLine('');
12
- printLine('Supported harnesses: Codex, Cursor, Antigravity, Copilot, OpenCode, Gemini, Pi');
49
+ printLine(`${toneLabel} ${styled(title, tone === 'error' ? 'error' : tone === 'success' ? 'success' : tone === 'warning' ? 'warning' : 'accent', true)}`);
50
+ for (const line of lines) {
51
+ printLine(` ${line}`);
52
+ }
53
+ }
54
+
55
+ export function labelValue(label, value) {
56
+ return `${styled(`${label}:`, 'dimGray')}${value ? ` ${styled(value, 'white')}` : ''}`;
57
+ }
58
+
59
+ export function bullet(text, tone = 'dimGray') {
60
+ return `${styled('•', tone)} ${styled(text, 'white')}`;
61
+ }
62
+
63
+ export function step(index, total, text) {
64
+ return `${styled(`[${index}/${total}]`, 'spark', true)} ${styled(text, 'white')}`;
65
+ }
66
+
67
+ export function commandText(text) {
68
+ return styled(text, 'warning');
69
+ }
70
+
71
+ export function pathText(text) {
72
+ return styled(text, 'accent');
73
+ }
74
+
75
+ export function statusText(text, tone = 'white') {
76
+ return styled(text, tone);
77
+ }
78
+
79
+ export function printMuted(text) {
80
+ printLine(styled(text, 'dimGray'));
81
+ }
82
+
83
+ export function formatError(message) {
84
+ return `${styled('✕', 'error')} ${styled(message, 'error', true)}`;
85
+ }
86
+
87
+ export function formatPromptBlock(title, lines = [], footer = null) {
88
+ const output = [];
89
+ output.push(styled(title, 'accent', true));
90
+ output.push(styled('Choose the AI assistance you want SPARK to prepare.', 'dimGray'));
91
+ output.push('');
92
+ output.push(...lines);
93
+ if (footer) {
94
+ output.push('');
95
+ output.push(styled(footer, 'dimGray'));
96
+ }
97
+ return output.join('\n');
98
+ }
99
+
100
+ export function formatPromptPrefix() {
101
+ return `${styled('◆', 'spark')} ${styled('Select', 'pink', true)} ${styled('›', 'dimGray')} `;
102
+ }
103
+
104
+ export function promptOption(index, label, id, hint = null) {
105
+ const base = `${styled(`${index}.`, 'spark', true)} ${styled(label, 'white', true)} ${styled(`(${id})`, 'dimGray')}`;
106
+ return hint ? `${base} ${styled(hint, 'warning')}` : base;
107
+ }
108
+
109
+ function styled(text, tone, bold = false) {
110
+ if (!useColor) {
111
+ return text;
112
+ }
113
+
114
+ const color = COLORS[tone] ?? '';
115
+ const weight = bold ? COLORS.bold : '';
116
+ return `${weight}${color}${text}${COLORS.reset}`;
13
117
  }
package/src/cli/prompt.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import readline from 'node:readline/promises';
2
+ import { formatPromptPrefix } from './output.js';
2
3
 
3
4
  export async function askQuestion(question, { input = process.stdin, output = process.stdout } = {}) {
4
5
  const rl = readline.createInterface({ input, output });
5
6
  try {
6
- return await rl.question(`${question}\n> `);
7
+ return await rl.question(`${question}\n${formatPromptPrefix()}`);
7
8
  } finally {
8
9
  rl.close();
9
10
  }
@@ -0,0 +1,38 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const CODEX_STAGE_DIR = path.join('.spark', 'codex-plugin');
5
+ const COPY_PATHS = [
6
+ '.codex-plugin',
7
+ 'assets',
8
+ path.join('hooks', 'hooks-codex.json'),
9
+ path.join('hooks', 'run-hook.cmd'),
10
+ path.join('hooks', 'session-start-codex'),
11
+ 'skills',
12
+ ];
13
+
14
+ export function stageCodexPlugin({ cwd = process.cwd(), packageRoot }) {
15
+ const targetRoot = path.join(cwd, CODEX_STAGE_DIR);
16
+
17
+ fs.mkdirSync(targetRoot, { recursive: true });
18
+
19
+ for (const relativePath of COPY_PATHS) {
20
+ const sourcePath = path.join(packageRoot, relativePath);
21
+ const targetPath = path.join(targetRoot, relativePath);
22
+ const stat = fs.statSync(sourcePath);
23
+
24
+ if (stat.isDirectory()) {
25
+ fs.cpSync(sourcePath, targetPath, { recursive: true });
26
+ continue;
27
+ }
28
+
29
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
30
+ fs.copyFileSync(sourcePath, targetPath);
31
+ fs.chmodSync(targetPath, stat.mode);
32
+ }
33
+
34
+ return {
35
+ targetRoot,
36
+ relativeTargetRoot: CODEX_STAGE_DIR,
37
+ };
38
+ }
@@ -8,52 +8,86 @@ export function createAdapter({
8
8
  bootstrap,
9
9
  installHint,
10
10
  verifyHint,
11
+ successMessage = `Installed SPARK for ${label}.`,
11
12
  command = null,
13
+ commands = [],
14
+ customInstall = null,
15
+ manualSteps = [],
16
+ automatedSteps = [],
12
17
  envKeys = [],
13
18
  binaryNames = [],
14
19
  configPaths = [],
15
20
  }) {
21
+ const commandList = normalizeCommandList(commands, command);
22
+ const automated = commandList.length > 0 || typeof customInstall === 'function';
23
+
16
24
  return {
17
25
  id,
18
26
  label,
19
27
  envKeys,
20
28
  binaryNames,
21
29
  configPaths,
22
- command,
30
+ command: commandList[0] ?? null,
31
+ commands: commandList,
32
+ manualSteps,
23
33
  planInstall() {
24
34
  return {
25
35
  kind,
26
36
  bootstrap,
27
37
  installHint,
28
38
  verifyHint,
29
- command,
39
+ successMessage,
40
+ command: commandList[0] ?? null,
41
+ commands: commandList,
42
+ manualSteps,
43
+ automatedSteps,
44
+ automated,
30
45
  };
31
46
  },
32
- async install({ runner = spawnSync, dryRun = false } = {}) {
47
+ async install({ runner = spawnSync, dryRun = false, cwd = process.cwd(), env = process.env, fs = null } = {}) {
33
48
  if (dryRun) {
34
- return this.planInstall();
49
+ return { plan: this.planInstall(), metadata: {} };
35
50
  }
36
51
 
37
- if (!command) {
52
+ if (!automated) {
38
53
  throw new InstallerError(`${label} install is not fully automatable yet.`);
39
54
  }
40
55
 
41
- const result = runner(command.file, command.args ?? [], {
42
- cwd: command.cwd ?? process.cwd(),
43
- env: command.env ?? process.env,
44
- encoding: 'utf8',
45
- });
56
+ if (typeof customInstall === 'function') {
57
+ const metadata = await customInstall({ cwd, env, fs });
58
+ return { plan: this.planInstall(), metadata: metadata ?? {} };
59
+ }
60
+
61
+ for (const entry of commandList) {
62
+ const result = runner(entry.file, entry.args ?? [], {
63
+ cwd: entry.cwd ?? cwd,
64
+ env: entry.env ?? env,
65
+ encoding: 'utf8',
66
+ });
46
67
 
47
- if (result.status !== 0) {
48
- throw new InstallerError(
49
- `${label} install failed: ${result.stderr || result.stdout || 'unknown error'}`
50
- );
68
+ if (result.status !== 0) {
69
+ throw new InstallerError(
70
+ `${label} install failed: ${result.stderr || result.stdout || 'unknown error'}`
71
+ );
72
+ }
51
73
  }
52
74
 
53
- return this.planInstall();
75
+ return { plan: this.planInstall(), metadata: {} };
54
76
  },
55
77
  async verify() {
56
78
  return verifyHint;
57
79
  },
58
80
  };
59
81
  }
82
+
83
+ function normalizeCommandList(commands, command) {
84
+ if (Array.isArray(commands) && commands.length > 0) {
85
+ return commands;
86
+ }
87
+
88
+ if (command) {
89
+ return [command];
90
+ }
91
+
92
+ return [];
93
+ }
@@ -11,6 +11,10 @@ export function createOpenCodeAdapter() {
11
11
  bootstrap: 'using-spark -> .opencode/plugins/spark.js -> message transform bootstrap',
12
12
  installHint: '.opencode/plugins/spark.js + .opencode/INSTALL.md',
13
13
  verifyHint: 'Run opencode logs or a fresh OpenCode session and confirm bootstrap injection.',
14
+ manualSteps: [
15
+ 'Add `spark@git+https://github.com/adityaaria/SPARK.git` to the `plugin` array in `opencode.json`.',
16
+ 'Restart OpenCode.',
17
+ ],
14
18
  });
15
19
  }
16
20
 
@@ -1,4 +1,9 @@
1
1
  import { createAdapter } from './common.js';
2
+ import { stageCodexPlugin } from './codex-staging.js';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
2
7
 
3
8
  export function createClaudeCodeAdapter() {
4
9
  return createAdapter({
@@ -10,6 +15,9 @@ export function createClaudeCodeAdapter() {
10
15
  bootstrap: 'shell hook -> hooks/session-start -> using-spark',
11
16
  installHint: '.claude-plugin/plugin.json + hooks/hooks.json + hooks/session-start',
12
17
  verifyHint: 'Run a fresh Claude Code session and confirm using-spark loads before coding.',
18
+ manualSteps: [
19
+ '/plugin install spark@claude-plugins-official',
20
+ ],
13
21
  });
14
22
  }
15
23
 
@@ -22,7 +30,15 @@ export function createCodexAdapter() {
22
30
  binaryNames: ['codex'],
23
31
  bootstrap: 'shell hook -> hooks/session-start-codex -> using-spark',
24
32
  installHint: '.codex-plugin/plugin.json + hooks/hooks-codex.json + hooks/session-start-codex',
25
- verifyHint: 'Run a fresh Codex session and confirm using-spark loads before coding.',
33
+ verifyHint: 'Open Codex plugin install, point it at .spark/codex-plugin, then confirm using-spark loads in a fresh session.',
34
+ successMessage: 'Staged SPARK for Codex in .spark/codex-plugin.',
35
+ automatedSteps: [
36
+ 'Stage a project-local Codex plugin bundle at .spark/codex-plugin.',
37
+ 'Open Codex plugin install and point it at .spark/codex-plugin.',
38
+ ],
39
+ customInstall({ cwd }) {
40
+ return stageCodexPlugin({ cwd, packageRoot });
41
+ },
26
42
  });
27
43
  }
28
44
 
@@ -36,6 +52,9 @@ export function createCursorAdapter() {
36
52
  bootstrap: 'shell hook -> hooks/session-start -> using-spark',
37
53
  installHint: '.cursor-plugin/plugin.json + hooks/hooks-cursor.json + hooks/session-start',
38
54
  verifyHint: 'Run a fresh Cursor Agent session and confirm using-spark loads before coding.',
55
+ manualSteps: [
56
+ '/add-plugin spark',
57
+ ],
39
58
  });
40
59
  }
41
60
 
@@ -49,9 +68,15 @@ export function createCopilotAdapter() {
49
68
  bootstrap: 'shell hook -> hooks/session-start -> using-spark',
50
69
  installHint: 'skills/using-spark/references/copilot-tools.md + hooks/session-start',
51
70
  verifyHint: 'Run a fresh Copilot CLI session and confirm using-spark loads before coding.',
52
- command: {
53
- file: 'copilot',
54
- args: ['plugin', 'install', 'spark@spark-marketplace'],
55
- },
71
+ commands: [
72
+ {
73
+ file: 'copilot',
74
+ args: ['plugin', 'marketplace', 'add', 'adityaaria/SPARK-marketplace'],
75
+ },
76
+ {
77
+ file: 'copilot',
78
+ args: ['plugin', 'install', 'spark@spark-marketplace'],
79
+ },
80
+ ],
56
81
  });
57
82
  }
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ import { formatPromptBlock, promptOption } from '../cli/output.js';
4
5
  import { getAdapterById, listAdapters } from './registry.js';
5
6
  import { InstallerError } from './errors.js';
6
7
 
@@ -146,12 +147,31 @@ function buildPromptCandidates(detectedCandidates) {
146
147
  }
147
148
 
148
149
  function renderPrompt(candidates, validationMessage = null) {
149
- return [
150
- ...(validationMessage ? [validationMessage] : []),
151
- 'Install SPARK for which AI assistance?',
152
- ...candidates.map((candidate, index) => `${index + 1}. ${candidate.label} (${candidate.id})`),
153
- 'Enter a number or harness name:',
154
- ].join('\n');
150
+ const lines = [];
151
+
152
+ if (validationMessage) {
153
+ lines.push(validationMessage);
154
+ lines.push('');
155
+ }
156
+
157
+ const detectedCount = candidates.filter((candidate) => candidate.score > 0).length;
158
+ const recommendedIds = new Set(candidates.filter((candidate) => candidate.score > 0).map((candidate) => candidate.id));
159
+
160
+ if (detectedCount > 0) {
161
+ lines.push('Recommended from your current environment:');
162
+ lines.push('');
163
+ }
164
+
165
+ for (const [index, candidate] of candidates.entries()) {
166
+ const hint = recommendedIds.has(candidate.id) ? 'recommended' : null;
167
+ lines.push(promptOption(index + 1, candidate.label, candidate.id, hint));
168
+ }
169
+
170
+ return formatPromptBlock(
171
+ 'Install SPARK',
172
+ lines,
173
+ 'Enter a number or harness name.'
174
+ );
155
175
  }
156
176
 
157
177
  function resolvePromptAnswer(answer, candidates) {