@polterware/polter 0.3.0 → 0.4.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/dist/mcp.js CHANGED
@@ -8,6 +8,8 @@ import {
8
8
  detectPkgManager,
9
9
  executePipeline,
10
10
  findPipelineByName,
11
+ findProcessesByCwd,
12
+ findRunningByCommand,
11
13
  generateProcessId,
12
14
  getAllPipelines,
13
15
  getCommandById,
@@ -23,8 +25,9 @@ import {
23
25
  runCommand,
24
26
  savePipeline,
25
27
  startProcess,
26
- stopProcess
27
- } from "./chunk-7MIUDIAI.js";
28
+ stopProcess,
29
+ translateCommand
30
+ } from "./chunk-YNOZDU75.js";
28
31
 
29
32
  // src/mcp.ts
30
33
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -14119,9 +14122,72 @@ function pkgRunHelper(base, extraArgs = []) {
14119
14122
  { quiet: true }
14120
14123
  ).promise;
14121
14124
  }
14125
+ server.tool(
14126
+ "polter_run_script_bg",
14127
+ "Start a package.json script as a tracked background process using the detected package manager (npm/pnpm/yarn/bun). The process output is captured and can be read with polter_logs. Use polter_ps to check status.",
14128
+ {
14129
+ script: external_exports.string().describe("Script name from package.json (e.g. 'dev', 'build', 'test')"),
14130
+ args: external_exports.array(external_exports.string()).optional().describe("Extra arguments to pass to the script"),
14131
+ cwd: external_exports.string().optional().describe("Working directory. Defaults to current directory.")
14132
+ },
14133
+ async ({ script, args: extraArgs, cwd: cwdArg }) => {
14134
+ const cwd = cwdArg ?? process.cwd();
14135
+ const pkgPath = join(cwd, "package.json");
14136
+ if (!existsSync(pkgPath)) {
14137
+ return {
14138
+ content: [{ type: "text", text: JSON.stringify({ error: "No package.json found in " + cwd }) }],
14139
+ isError: true
14140
+ };
14141
+ }
14142
+ const raw = JSON.parse(readFileSync(pkgPath, "utf-8"));
14143
+ const scripts = raw.scripts ?? {};
14144
+ if (!scripts[script]) {
14145
+ return {
14146
+ content: [{ type: "text", text: JSON.stringify({ error: `Script "${script}" not found. Available: ${Object.keys(scripts).join(", ")}` }) }],
14147
+ isError: true
14148
+ };
14149
+ }
14150
+ const mgr = detectPkgManager(cwd);
14151
+ try {
14152
+ const translated = translateCommand(["run", script, ...extraArgs ?? []], mgr.id);
14153
+ const existing = findRunningByCommand(cwd, mgr.command, translated.args);
14154
+ if (existing) {
14155
+ return {
14156
+ content: [{
14157
+ type: "text",
14158
+ text: JSON.stringify({
14159
+ alreadyRunning: true,
14160
+ process: existing,
14161
+ output: getProcessOutput(existing.id, 20)
14162
+ }, null, 2)
14163
+ }]
14164
+ };
14165
+ }
14166
+ const id = generateProcessId(mgr.command, translated.args);
14167
+ const info = startProcess(id, mgr.command, translated.args, cwd);
14168
+ await new Promise((r) => setTimeout(r, 500));
14169
+ return {
14170
+ content: [{
14171
+ type: "text",
14172
+ text: JSON.stringify({
14173
+ success: true,
14174
+ process: info,
14175
+ output: getProcessOutput(id, 20),
14176
+ packageManager: mgr.id
14177
+ }, null, 2)
14178
+ }]
14179
+ };
14180
+ } catch (err) {
14181
+ return {
14182
+ content: [{ type: "text", text: JSON.stringify({ error: err.message }) }],
14183
+ isError: true
14184
+ };
14185
+ }
14186
+ }
14187
+ );
14122
14188
  server.tool(
14123
14189
  "polter_pkg_build",
14124
- "Run the build script from package.json using the detected package manager.",
14190
+ "Run the build script from package.json using the detected package manager (npm/pnpm/yarn/bun).",
14125
14191
  {},
14126
14192
  async () => {
14127
14193
  const result = await pkgRunHelper(["run", "build"]);
@@ -14132,7 +14198,7 @@ server.tool(
14132
14198
  );
14133
14199
  server.tool(
14134
14200
  "polter_pkg_publish",
14135
- "Publish the package to the npm registry.",
14201
+ "Publish the package to the registry using the detected package manager (npm/pnpm/yarn/bun).",
14136
14202
  {
14137
14203
  tag: external_exports.string().optional().describe("Dist-tag (e.g. 'next', 'beta')"),
14138
14204
  dryRun: external_exports.boolean().optional().describe("Simulate publish without uploading")
@@ -14156,7 +14222,7 @@ server.tool(
14156
14222
  );
14157
14223
  server.tool(
14158
14224
  "polter_pkg_install",
14159
- "Install dependencies. Optionally install specific packages.",
14225
+ "Install dependencies using the detected package manager (npm/pnpm/yarn/bun). Optionally install specific packages.",
14160
14226
  {
14161
14227
  packages: external_exports.array(external_exports.string()).optional().describe("Specific packages to install"),
14162
14228
  dev: external_exports.boolean().optional().describe("Install as dev dependency")
@@ -14173,7 +14239,7 @@ server.tool(
14173
14239
  );
14174
14240
  server.tool(
14175
14241
  "polter_pkg_run_script",
14176
- "Run a script defined in package.json.",
14242
+ "Run a script defined in package.json using the detected package manager (npm/pnpm/yarn/bun).",
14177
14243
  {
14178
14244
  script: external_exports.string().describe("Script name to run"),
14179
14245
  args: external_exports.array(external_exports.string()).optional().describe("Extra arguments")
@@ -14187,7 +14253,7 @@ server.tool(
14187
14253
  );
14188
14254
  server.tool(
14189
14255
  "polter_pkg_version_bump",
14190
- "Bump the package version (semver).",
14256
+ "Bump the package version (semver) using the detected package manager (npm/pnpm/yarn/bun).",
14191
14257
  {
14192
14258
  type: external_exports.enum(["patch", "minor", "major"]).describe("Version bump type")
14193
14259
  },
@@ -14200,7 +14266,7 @@ server.tool(
14200
14266
  );
14201
14267
  server.tool(
14202
14268
  "polter_pkg_audit",
14203
- "Run a security audit on dependencies.",
14269
+ "Run a security audit on dependencies using the detected package manager (npm/pnpm/yarn/bun).",
14204
14270
  {
14205
14271
  fix: external_exports.boolean().optional().describe("Attempt to fix vulnerabilities")
14206
14272
  },
@@ -14221,7 +14287,7 @@ server.tool(
14221
14287
  );
14222
14288
  server.tool(
14223
14289
  "polter_pkg_info",
14224
- "Get information about a package from the registry.",
14290
+ "Get information about a package from the registry using the detected package manager (npm/pnpm/yarn/bun).",
14225
14291
  {
14226
14292
  package: external_exports.string().describe("Package name to look up")
14227
14293
  },
@@ -14318,6 +14384,100 @@ server.tool(
14318
14384
  }
14319
14385
  }
14320
14386
  );
14387
+ server.tool(
14388
+ "polter_smart_start",
14389
+ "Smart process starter: reads package.json, auto-detects package manager, starts a script as a background process. If script is omitted, lists available scripts. If already running, returns current info and recent logs instead of duplicating.",
14390
+ {
14391
+ script: external_exports.string().optional().describe("Script name from package.json (e.g. 'dev', 'build')"),
14392
+ cwd: external_exports.string().optional().describe("Repository directory. Defaults to current directory."),
14393
+ tail: external_exports.number().optional().default(20).describe("Number of initial log lines to return")
14394
+ },
14395
+ async ({ script, cwd: cwdArg, tail }) => {
14396
+ const cwd = cwdArg ?? process.cwd();
14397
+ const pkgPath = join(cwd, "package.json");
14398
+ if (!existsSync(pkgPath)) {
14399
+ return {
14400
+ content: [{ type: "text", text: JSON.stringify({ error: "No package.json found in " + cwd }) }],
14401
+ isError: true
14402
+ };
14403
+ }
14404
+ const raw = JSON.parse(readFileSync(pkgPath, "utf-8"));
14405
+ const scripts = raw.scripts ?? {};
14406
+ if (!script) {
14407
+ return {
14408
+ content: [{ type: "text", text: JSON.stringify({ scripts: Object.keys(scripts) }, null, 2) }]
14409
+ };
14410
+ }
14411
+ if (!scripts[script]) {
14412
+ return {
14413
+ content: [{ type: "text", text: JSON.stringify({ error: `Script "${script}" not found. Available: ${Object.keys(scripts).join(", ")}` }) }],
14414
+ isError: true
14415
+ };
14416
+ }
14417
+ const mgr = detectPkgManager(cwd);
14418
+ const runArgs = ["run", script];
14419
+ const existing = findRunningByCommand(cwd, mgr.command, runArgs);
14420
+ if (existing) {
14421
+ return {
14422
+ content: [{
14423
+ type: "text",
14424
+ text: JSON.stringify({
14425
+ alreadyRunning: true,
14426
+ process: existing,
14427
+ output: getProcessOutput(existing.id, tail)
14428
+ }, null, 2)
14429
+ }]
14430
+ };
14431
+ }
14432
+ try {
14433
+ const id = generateProcessId(mgr.command, runArgs);
14434
+ const info = startProcess(id, mgr.command, runArgs, cwd);
14435
+ await new Promise((r) => setTimeout(r, 500));
14436
+ return {
14437
+ content: [{
14438
+ type: "text",
14439
+ text: JSON.stringify({
14440
+ alreadyRunning: false,
14441
+ process: info,
14442
+ output: getProcessOutput(id, tail),
14443
+ packageManager: mgr.id
14444
+ }, null, 2)
14445
+ }]
14446
+ };
14447
+ } catch (err) {
14448
+ return {
14449
+ content: [{ type: "text", text: JSON.stringify({ error: err.message }) }],
14450
+ isError: true
14451
+ };
14452
+ }
14453
+ }
14454
+ );
14455
+ server.tool(
14456
+ "polter_find_process",
14457
+ "Find all tracked processes for a repository directory. Returns process info with recent logs embedded. No need to know process IDs \u2014 just point to the repo.",
14458
+ {
14459
+ cwd: external_exports.string().optional().describe("Repository directory. Defaults to current directory."),
14460
+ filter: external_exports.string().optional().describe("Filter by substring in command+args"),
14461
+ tail: external_exports.number().optional().default(20).describe("Number of log lines per process")
14462
+ },
14463
+ async ({ cwd: cwdArg, filter, tail }) => {
14464
+ const cwd = cwdArg ?? process.cwd();
14465
+ let processes = findProcessesByCwd(cwd);
14466
+ if (filter) {
14467
+ const f = filter.toLowerCase();
14468
+ processes = processes.filter(
14469
+ (proc) => (proc.command + " " + proc.args.join(" ")).toLowerCase().includes(f)
14470
+ );
14471
+ }
14472
+ const result = processes.map((proc) => ({
14473
+ process: proc,
14474
+ output: getProcessOutput(proc.id, tail)
14475
+ }));
14476
+ return {
14477
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
14478
+ };
14479
+ }
14480
+ );
14321
14481
  server.resource(
14322
14482
  "package-json",
14323
14483
  "polter://package-json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polterware/polter",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "An interactive CLI for managing Supabase CLI workflows.",
5
5
  "type": "module",
6
6
  "bin": {