create-mushin 0.3.0 → 0.4.0-next.20261127155650

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/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { VERSION, addSkills, createApp, detectPackageManager, install } from "./index.js";
1
+ import { VERSION, addAgentFiles, addSkills, createApp, detectPackageManager, install } from "./index.js";
2
2
  import { relative } from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  // src/cli.ts
@@ -9,12 +9,15 @@ Creates a Mushin.js app in a new folder (default: my-bot) and installs it.
9
9
  Options:
10
10
  --pm <npm|pnpm> Package manager to install with (default: the one that ran this)
11
11
  --no-install Only write the files
12
+ --agents <list> Guides for coding agents, without asking: agents, claude, gemini, copilot,
13
+ cursor, jetbrains (comma-separated), or none. Default: ask, or agents,claude
12
14
  -h, --help Show this help`;
13
15
  const { values, positionals } = parseArgs({
14
16
  allowPositionals: true,
15
17
  options: {
16
18
  pm: { type: "string" },
17
19
  "no-install": { type: "boolean" },
20
+ agents: { type: "string" },
18
21
  help: {
19
22
  type: "boolean",
20
23
  short: "h"
@@ -38,6 +41,7 @@ try {
38
41
  console.log(`Installing with ${pm}…`);
39
42
  await install(dir, pm);
40
43
  await addSkills(dir);
44
+ await addAgentFiles(dir, values.agents);
41
45
  }
42
46
  const cd = relative(process.cwd(), dir) || ".";
43
47
  const run = pm === "npm" ? "npm" : "pnpm";
@@ -49,7 +53,7 @@ try {
49
53
  ` ${run} start`,
50
54
  "",
51
55
  "Open the sign-in link it prints, then follow Quick setup in the dashboard.",
52
- "AGENTS.md explains the folder to you and to your AI."
56
+ values["no-install"] ? `After installing, "${pm === "npm" ? "npx" : "pnpm exec"} mushin agents" writes AGENTS.md and the like, which explain the folder to your coding agent.` : "AGENTS.md (or the file you picked for your coding agent) explains the folder to it."
53
57
  ].join("\n"));
54
58
  } catch (error) {
55
59
  console.error(error.message);
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { relative } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { addSkills, createApp, detectPackageManager, install, type PackageManager, VERSION } from './index'\n\nconst usage = `Usage: npm create mushin@latest [folder] [-- options]\n\nCreates a Mushin.js app in a new folder (default: my-bot) and installs it.\n\nOptions:\n --pm <npm|pnpm> Package manager to install with (default: the one that ran this)\n --no-install Only write the files\n -h, --help Show this help`\n\nconst { values, positionals } = parseArgs({\n allowPositionals: true,\n options: {\n pm: { type: 'string' },\n 'no-install': { type: 'boolean' },\n help: { type: 'boolean', short: 'h' },\n },\n})\n\nif (values.help) {\n console.log(usage)\n process.exit(0)\n}\n\nconst pm = (values.pm ?? detectPackageManager()) as PackageManager\nif (pm !== 'npm' && pm !== 'pnpm') {\n console.error(`--pm must be npm or pnpm, not ${pm}`)\n process.exit(1)\n}\n\nconst folder = positionals[0] ?? 'my-bot'\ntry {\n console.log(`Creating a Mushin.js ${VERSION} app in ${folder}`)\n const { dir } = await createApp(folder, { packageManager: pm })\n if (!values['no-install']) {\n console.log(`Installing with ${pm}…`)\n await install(dir, pm)\n await addSkills(dir)\n }\n const cd = relative(process.cwd(), dir) || '.'\n const run = pm === 'npm' ? 'npm' : 'pnpm'\n console.log([\n '',\n 'Done. Next:',\n ...(cd === '.' ? [] : [` cd ${cd.includes(' ') ? JSON.stringify(cd) : cd}`]),\n ...(values['no-install'] ? [` ${run} install`] : []),\n ` ${run} start`,\n '',\n 'Open the sign-in link it prints, then follow Quick setup in the dashboard.',\n 'AGENTS.md explains the folder to you and to your AI.',\n ].join('\\n'))\n} catch (error) {\n console.error((error as Error).message)\n process.exit(1)\n}\n"],"mappings":";;;;AAIA,MAAM,QAAQ;;;;;;;;AASd,MAAM,EAAE,QAAQ,gBAAgB,UAAU;CACxC,kBAAkB;CAClB,SAAS;EACP,IAAI,EAAE,MAAM,SAAS;EACrB,cAAc,EAAE,MAAM,UAAU;EAChC,MAAM;GAAE,MAAM;GAAW,OAAO;EAAI;CACtC;AACF,CAAC;AAED,IAAI,OAAO,MAAM;CACf,QAAQ,IAAI,KAAK;CACjB,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,KAAM,OAAO,MAAM,qBAAqB;AAC9C,IAAI,OAAO,SAAS,OAAO,QAAQ;CACjC,QAAQ,MAAM,iCAAiC,IAAI;CACnD,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,SAAS,YAAY,MAAM;AACjC,IAAI;CACF,QAAQ,IAAI,wBAAwB,QAAQ,UAAU,QAAQ;CAC9D,MAAM,EAAE,QAAQ,MAAM,UAAU,QAAQ,EAAE,gBAAgB,GAAG,CAAC;CAC9D,IAAI,CAAC,OAAO,eAAe;EACzB,QAAQ,IAAI,mBAAmB,GAAG,EAAE;EACpC,MAAM,QAAQ,KAAK,EAAE;EACrB,MAAM,UAAU,GAAG;CACrB;CACA,MAAM,KAAK,SAAS,QAAQ,IAAI,GAAG,GAAG,KAAK;CAC3C,MAAM,MAAM,OAAO,QAAQ,QAAQ;CACnC,QAAQ,IAAI;EACV;EACA;EACA,GAAI,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,SAAS,GAAG,IAAI,KAAK,UAAU,EAAE,IAAI,IAAI;EAC3E,GAAI,OAAO,gBAAgB,CAAC,KAAK,IAAI,SAAS,IAAI,CAAC;EACnD,KAAK,IAAI;EACT;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CAAC;AACd,SAAS,OAAO;CACd,QAAQ,MAAO,MAAgB,OAAO;CACtC,QAAQ,KAAK,CAAC;AAChB"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import { relative } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { addAgentFiles, addSkills, createApp, detectPackageManager, install, type PackageManager, VERSION } from './index'\n\nconst usage = `Usage: npm create mushin@latest [folder] [-- options]\n\nCreates a Mushin.js app in a new folder (default: my-bot) and installs it.\n\nOptions:\n --pm <npm|pnpm> Package manager to install with (default: the one that ran this)\n --no-install Only write the files\n --agents <list> Guides for coding agents, without asking: agents, claude, gemini, copilot,\n cursor, jetbrains (comma-separated), or none. Default: ask, or agents,claude\n -h, --help Show this help`\n\nconst { values, positionals } = parseArgs({\n allowPositionals: true,\n options: {\n pm: { type: 'string' },\n 'no-install': { type: 'boolean' },\n agents: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n },\n})\n\nif (values.help) {\n console.log(usage)\n process.exit(0)\n}\n\nconst pm = (values.pm ?? detectPackageManager()) as PackageManager\nif (pm !== 'npm' && pm !== 'pnpm') {\n console.error(`--pm must be npm or pnpm, not ${pm}`)\n process.exit(1)\n}\n\nconst folder = positionals[0] ?? 'my-bot'\ntry {\n console.log(`Creating a Mushin.js ${VERSION} app in ${folder}`)\n const { dir } = await createApp(folder, { packageManager: pm })\n if (!values['no-install']) {\n console.log(`Installing with ${pm}…`)\n await install(dir, pm)\n await addSkills(dir)\n await addAgentFiles(dir, values.agents)\n }\n const cd = relative(process.cwd(), dir) || '.'\n const run = pm === 'npm' ? 'npm' : 'pnpm'\n console.log([\n '',\n 'Done. Next:',\n ...(cd === '.' ? [] : [` cd ${cd.includes(' ') ? JSON.stringify(cd) : cd}`]),\n ...(values['no-install'] ? [` ${run} install`] : []),\n ` ${run} start`,\n '',\n 'Open the sign-in link it prints, then follow Quick setup in the dashboard.',\n values['no-install']\n ? `After installing, \"${pm === 'npm' ? 'npx' : 'pnpm exec'} mushin agents\" writes AGENTS.md and the like, which explain the folder to your coding agent.`\n : 'AGENTS.md (or the file you picked for your coding agent) explains the folder to it.',\n ].join('\\n'))\n} catch (error) {\n console.error((error as Error).message)\n process.exit(1)\n}\n"],"mappings":";;;;AAIA,MAAM,QAAQ;;;;;;;;;;AAWd,MAAM,EAAE,QAAQ,gBAAgB,UAAU;CACxC,kBAAkB;CAClB,SAAS;EACP,IAAI,EAAE,MAAM,SAAS;EACrB,cAAc,EAAE,MAAM,UAA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
20
- /** Puts the official skills into the app, with the CLI that was just installed. */
20
+ /** Puts the official skills into the app. */
21
21
  export declare function addSkills(dir: string): Promise<void>;
22
+ /**
23
+ * Writes the guide for coding agents (AGENTS.md, CLAUDE.md and the like). Without `files` the CLI asks which
24
+ * ones in a terminal, and picks AGENTS.md and CLAUDE.md otherwise.
25
+ */
26
+ export declare function addAgentFiles(dir: string, files?: string): Promise<void>;
22
27
  /** Runs the package manager's install in the app folder, with its output shown. */
23
28
  export declare function install(dir: string, packageManager: PackageManager): Promise<void>;
package/dist/index.js CHANGED
@@ -66,7 +66,6 @@ function appFiles(name, version = VERSION, packageManager = "npm") {
66
66
  "logs/",
67
67
  ""
68
68
  ].join("\n"),
69
- "AGENTS.md": agentsGuide(name),
70
69
  ".mcp.json": json({ mcpServers: { mushin: {
71
70
  type: "stdio",
72
71
  command: "node",
@@ -86,55 +85,6 @@ const PNPM_SETTINGS = `allowBuilds:
86
85
  cpu-features: false
87
86
  ssh2: false
88
87
  `;
89
- function agentsGuide(name) {
90
- return `# ${name}
91
-
92
- This folder is a [Mushin.js](https://github.com/mushinjs/mushin) app: a chatbot framework for QQ (through OneBot / NapCat) with LLM chat, conversation flows and an Agent. Read this before changing anything here.
93
-
94
- ## Commands
95
-
96
- - \`npm start\` starts Mushin.js and prints the dashboard sign-in link (\`pnpm start\` with pnpm).
97
- - \`npm run upgrade\` updates every \`@mushinjs/*\` package and moves the data to the new version's layout. Stop Mushin.js first.
98
- - \`npx mushin new plugin <name>\` creates a TypeScript plugin in \`plugins/<name>/\` and turns it on.
99
- - \`npm run typecheck\` checks the plugins in \`plugins/\`.
100
- - \`npx mushin token reset\` makes a new admin token for the dashboard.
101
-
102
- ## Managing Mushin.js from an AI tool
103
-
104
- \`.mcp.json\` connects the AI tool you open in this folder (Claude Code and others that read it) to the running Mushin.js through \`mushin mcp\`. Start Mushin.js first. The tools are Mushin.js actions: list bots, read logs, build and test flows, and more. Dangerous ones wait for approval in the dashboard. The admin token is read from \`.env\`; do not copy it anywhere.
105
-
106
- ## Skills
107
-
108
- \`.claude/skills/\` holds the official skills. Read the matching \`SKILL.md\` before you start one of these jobs, whichever AI tool you are:
109
-
110
- - \`mushin-plugin-dev\`: writing or changing a plugin in \`plugins/\`. It starts with the questions to ask the user first.
111
- - \`mushin-flows\`: building and testing conversation flows.
112
- - \`mushin-troubleshoot\`: finding out why a bot, command, flow or plugin does not work.
113
- - \`mushin-operations\`: upgrades, backups, restores, moving machines, the admin token.
114
-
115
- \`npm run upgrade\` replaces them with the new version's; put your own skills in other folders.
116
-
117
- ## Layout
118
-
119
- | Path | What it is | Who writes it |
120
- | --- | --- | --- |
121
- | \`mushin.config.json\` | Which plugins run, and their settings. Holds no secrets. | People, the dashboard, the Agent |
122
- | \`.mcp.json\` | Connects the AI tool opened here to Mushin.js. Holds no secrets. | create-mushin |
123
- | \`.claude/skills/\` | The official skills for AI tools | Mushin.js (on create and upgrade) |
124
- | \`.env\` | Secrets: the admin token, provider keys, bot tokens. Configuration refers to them as \`\${NAME}\`. | Mushin.js and people |
125
- | \`plugins/\` | Local plugins, run as TypeScript without a build step | People and AIs |
126
- | \`skills/\` | Your own skills, one folder each with a \`SKILL.md\` | People and AIs |
127
- | \`data/\` | Everything Mushin.js keeps: database, bots, providers, flows, message logs. Back up this folder. | Mushin.js only |
128
- | \`cache/\`, \`logs/\` | Safe to delete | Mushin.js only |
129
-
130
- ## Rules
131
-
132
- - Do not edit files under \`data/\` by hand while Mushin.js runs. Change things through the dashboard or its actions.
133
- - Never print, commit or copy the contents of \`.env\`. To use a secret in a setting, write \`\${NAME}\` and put \`NAME=value\` in \`.env\`.
134
- - A plugin is a package in \`plugins/<name>/\` with a \`mushin\` field in its \`package.json\`. It exports \`name\`, optionally \`inject\` and \`Config\` (a zod schema), and \`apply(ctx, config)\`. Import everything from \`@mushinjs/core\`.
135
- - After changing a plugin, reload it from the dashboard's Plugins page or restart Mushin.js.
136
- `;
137
- }
138
88
  /** Writes a new app into `dir`, which must be missing or empty. */
139
89
  async function createApp(dir, options = {}) {
140
90
  const target = resolve(dir);
@@ -150,13 +100,13 @@ async function createApp(dir, options = {}) {
150
100
  files: Object.keys(files)
151
101
  };
152
102
  }
153
- /** Puts the official skills into the app, with the CLI that was just installed. */
154
- function addSkills(dir) {
103
+ /** Runs the CLI that was just installed in the app. */
104
+ function mushin(dir, args) {
155
105
  return new Promise((done, reject) => {
156
106
  const bin = join(dir, "node_modules", "@mushinjs", "cli", "bin", "mushin.js");
157
107
  const child = spawn(process.execPath, [
158
108
  bin,
159
- "skills",
109
+ ...args,
160
110
  "--dir",
161
111
  dir
162
112
  ], {
@@ -164,9 +114,24 @@ function addSkills(dir) {
164
114
  stdio: "inherit"
165
115
  });
166
116
  child.on("error", reject);
167
- child.on("exit", (code) => code ? reject(/* @__PURE__ */ new Error(`mushin skills exited with ${code}`)) : done());
117
+ child.on("exit", (code) => code ? reject(/* @__PURE__ */ new Error(`mushin ${args[0]} exited with ${code}`)) : done());
168
118
  });
169
119
  }
120
+ /** Puts the official skills into the app. */
121
+ function addSkills(dir) {
122
+ return mushin(dir, ["skills"]);
123
+ }
124
+ /**
125
+ * Writes the guide for coding agents (AGENTS.md, CLAUDE.md and the like). Without `files` the CLI asks which
126
+ * ones in a terminal, and picks AGENTS.md and CLAUDE.md otherwise.
127
+ */
128
+ function addAgentFiles(dir, files) {
129
+ return mushin(dir, files === void 0 ? ["agents"] : [
130
+ "agents",
131
+ "--files",
132
+ files
133
+ ]);
134
+ }
170
135
  /** Runs the package manager's install in the app folder, with its output shown. */
171
136
  function install(dir, packageManager) {
172
137
  return new Promise((done, reject) => {
@@ -179,6 +144,6 @@ function install(dir, packageManager) {
179
144
  child.on("exit", (code) => code ? reject(/* @__PURE__ */ new Error(`${packageManager} install exited with ${code}`)) : done());
180
145
  });
181
146
  }
182
- export { VERSION, addSkills, appFiles, createApp, dependencyRange, detectPackageManager, install, packageName };
147
+ export { VERSION, addAgentFiles, addSkills, appFiles, createApp, dependencyRange, detectPackageManager, install, packageName };
183
148
 
184
149
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\nimport { readFileSync } from 'node:fs'\nimport { mkdir, readdir, writeFile } from 'node:fs/promises'\nimport { basename, join, resolve } from 'node:path'\n\n/** The version of this package, which every `@mushinjs/*` package shares. */\nexport const VERSION: string = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version\n\nexport type PackageManager = 'npm' | 'pnpm'\n\n/** The package manager that ran `npm create` / `pnpm create`, from the user agent it sets. */\nexport function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? ''): PackageManager {\n return userAgent.startsWith('pnpm') ? 'pnpm' : 'npm'\n}\n\n/** The version range the app depends on: a preview is pinned exactly, a release takes compatible updates. */\nexport function dependencyRange(version = VERSION) {\n return version.includes('-') ? version : `^${version}`\n}\n\n/** A package name made from a folder name: `My Bot` gives `my-bot`. */\nexport function packageName(dir: string) {\n const name = basename(resolve(dir)).toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^[._-]+|-+$/g, '')\n return name || 'mushin-app'\n}\n\n/** The files of a new app, by path relative to its folder. */\nexport function appFiles(name: string, version = VERSION, packageManager: PackageManager = 'npm'): Record<string, string> {\n const range = dependencyRange(version)\n const json = (value: unknown) => JSON.stringify(value, null, 2) + '\\n'\n return {\n 'package.json': json({\n name,\n private: true,\n type: 'module',\n scripts: {\n start: 'mushin start',\n upgrade: 'mushin upgrade',\n typecheck: 'tsc',\n },\n dependencies: {\n '@mushinjs/cli': range,\n // Local plugins in plugins/ import it; with pnpm they only see the app's own dependencies.\n '@mushinjs/core': range,\n },\n devDependencies: {\n '@types/node': '^22.13.0',\n typescript: '^6.0.3',\n },\n engines: { node: '>=22.13' },\n }),\n 'tsconfig.json': json({\n compilerOptions: {\n target: 'es2023',\n lib: ['es2023'],\n module: 'preserve',\n moduleResolution: 'bundler',\n types: ['node'],\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n isolatedModules: true,\n verbatimModuleSyntax: true,\n },\n include: ['plugins/*/src'],\n }),\n '.gitignore': [\n 'node_modules/',\n '# Secrets: keys, tokens. Never commit or share this file.',\n '.env',\n '# Written by Mushin.js. Back up data/; cache/ and logs/ can be deleted.',\n 'data/',\n 'cache/',\n 'logs/',\n '',\n ].join('\\n'),\n 'AGENTS.md': agentsGuide(name),\n // Connects the AI tool opened in this folder to the running Mushin.js; the token stays in .env.\n '.mcp.json': json({\n mcpServers: {\n mushin: { type: 'stdio', command: 'node', args: ['node_modules/@mushinjs/cli/bin/mushin.js', 'mcp'] },\n },\n }),\n 'plugins/.gitkeep': '',\n 'skills/.gitkeep': '',\n ...(packageManager === 'pnpm' ? { 'pnpm-workspace.yaml': PNPM_SETTINGS } : {}),\n }\n}\n\n/**\n * pnpm runs no install scripts it was not told about, and stops the install over them. esbuild (through tsx,\n * for TypeScript plugins) needs its script; ssh2 (the terminal plugin) works without its optional native parts.\n */\nconst PNPM_SETTINGS = `allowBuilds:\n esbuild: true\n cpu-features: false\n ssh2: false\n`\n\nfunction agentsGuide(name: string) {\n return `# ${name}\n\nThis folder is a [Mushin.js](https://github.com/mushinjs/mushin) app: a chatbot framework for QQ (through OneBot / NapCat) with LLM chat, conversation flows and an Agent. Read this before changing anything here.\n\n## Commands\n\n- \\`npm start\\` starts Mushin.js and prints the dashboard sign-in link (\\`pnpm start\\` with pnpm).\n- \\`npm run upgrade\\` updates every \\`@mushinjs/*\\` package and moves the data to the new version's layout. Stop Mushin.js first.\n- \\`npx mushin new plugin <name>\\` creates a TypeScript plugin in \\`plugins/<name>/\\` and turns it on.\n- \\`npm run typecheck\\` checks the plugins in \\`plugins/\\`.\n- \\`npx mushin token reset\\` makes a new admin token for the dashboard.\n\n## Managing Mushin.js from an AI tool\n\n\\`.mcp.json\\` connects the AI tool you open in this folder (Claude Code and others that read it) to the running Mushin.js through \\`mushin mcp\\`. Start Mushin.js first. The tools are Mushin.js actions: list bots, read logs, build and test flows, and more. Dangerous ones wait for approval in the dashboard. The admin token is read from \\`.env\\`; do not copy it anywhere.\n\n## Skills\n\n\\`.claude/skills/\\` holds the official skills. Read the matching \\`SKILL.md\\` before you start one of these jobs, whichever AI tool you are:\n\n- \\`mushin-plugin-dev\\`: writing or changing a plugin in \\`plugins/\\`. It starts with the questions to ask the user first.\n- \\`mushin-flows\\`: building and testing conversation flows.\n- \\`mushin-troubleshoot\\`: finding out why a bot, command, flow or plugin does not work.\n- \\`mushin-operations\\`: upgrades, backups, restores, moving machines, the admin token.\n\n\\`npm run upgrade\\` replaces them with the new version's; put your own skills in other folders.\n\n## Layout\n\n| Path | What it is | Who writes it |\n| --- | --- | --- |\n| \\`mushin.config.json\\` | Which plugins run, and their settings. Holds no secrets. | People, the dashboard, the Agent |\n| \\`.mcp.json\\` | Connects the AI tool opened here to Mushin.js. Holds no secrets. | create-mushin |\n| \\`.claude/skills/\\` | The official skills for AI tools | Mushin.js (on create and upgrade) |\n| \\`.env\\` | Secrets: the admin token, provider keys, bot tokens. Configuration refers to them as \\`\\${NAME}\\`. | Mushin.js and people |\n| \\`plugins/\\` | Local plugins, run as TypeScript without a build step | People and AIs |\n| \\`skills/\\` | Your own skills, one folder each with a \\`SKILL.md\\` | People and AIs |\n| \\`data/\\` | Everything Mushin.js keeps: database, bots, providers, flows, message logs. Back up this folder. | Mushin.js only |\n| \\`cache/\\`, \\`logs/\\` | Safe to delete | Mushin.js only |\n\n## Rules\n\n- Do not edit files under \\`data/\\` by hand while Mushin.js runs. Change things through the dashboard or its actions.\n- Never print, commit or copy the contents of \\`.env\\`. To use a secret in a setting, write \\`\\${NAME}\\` and put \\`NAME=value\\` in \\`.env\\`.\n- A plugin is a package in \\`plugins/<name>/\\` with a \\`mushin\\` field in its \\`package.json\\`. It exports \\`name\\`, optionally \\`inject\\` and \\`Config\\` (a zod schema), and \\`apply(ctx, config)\\`. Import everything from \\`@mushinjs/core\\`.\n- After changing a plugin, reload it from the dashboard's Plugins page or restart Mushin.js.\n`\n}\n\n/** Writes a new app into `dir`, which must be missing or empty. */\nexport async function createApp(dir: string, options: { version?: string; packageManager?: PackageManager } = {}) {\n const target = resolve(dir)\n const existing = await readdir(target).catch(() => [] as string[])\n if (existing.length) throw new Error(`${target} is not empty. Choose a new folder name.`)\n const files = appFiles(packageName(target), options.version, options.packageManager)\n for (const [path, content] of Object.entries(files)) {\n const file = join(target, path)\n await mkdir(join(file, '..'), { recursive: true })\n await writeFile(file, content)\n }\n return { dir: target, files: Object.keys(files) }\n}\n\n/** Puts the official skills into the app, with the CLI that was just installed. */\nexport function addSkills(dir: string) {\n return new Promise<void>((done, reject) => {\n const bin = join(dir, 'node_modules', '@mushinjs', 'cli', 'bin', 'mushin.js')\n const child = spawn(process.execPath, [bin, 'skills', '--dir', dir], { cwd: dir, stdio: 'inherit' })\n child.on('error', reject)\n child.on('exit', (code) => (code ? reject(new Error(`mushin skills exited with ${code}`)) : done()))\n })\n}\n\n/** Runs the package manager's install in the app folder, with its output shown. */\nexport function install(dir: string, packageManager: PackageManager) {\n return new Promise<void>((done, reject) => {\n // npm and pnpm are .cmd files on Windows, which only start through a shell.\n const child = spawn(packageManager, ['install'], { cwd: dir, stdio: 'inherit', shell: process.platform === 'win32' })\n child.on('error', reject)\n child.on('exit', (code) => (code ? reject(new Error(`${packageManager} install exited with ${code}`)) : done()))\n })\n}\n"],"mappings":";;;;;;AAMA,MAAa,UAAkB,KAAK,MAAM,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC;;AAK7G,SAAgB,qBAAqB,YAAY,QAAQ,IAAI,yBAAyB,IAAoB;CACxG,OAAO,UAAU,WAAW,MAAM,IAAI,SAAS;AACjD;;AAGA,SAAgB,gBAAgB,UAAU,SAAS;CACjD,OAAO,QAAQ,SAAS,GAAG,IAAI,UAAU,IAAI;AAC/C;;AAGA,SAAgB,YAAY,KAAa;CAE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"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\nimport { readFileSync } from 'node:fs'\nimport { mkdir, readdir, writeFile } from 'node:fs/promises'\nimport { basename, join, resolve } from 'node:path'\n\n/** The version of this package, which every `@mushinjs/*` package shares. */\nexport const VERSION: string = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version\n\nexport type PackageManager = 'npm' | 'pnpm'\n\n/** The package manager that ran `npm create` / `pnpm create`, from the user agent it sets. */\nexport function detectPackageManager(userAgent = process.env.npm_config_user_agent ?? ''): PackageManager {\n return userAgent.startsWith('pnpm') ? 'pnpm' : 'npm'\n}\n\n/** The version range the app depends on: a preview is pinned exactly, a release takes compatible updates. */\nexport function dependencyRange(version = VERSION) {\n return version.includes('-') ? version : `^${version}`\n}\n\n/** A package name made from a folder name: `My Bot` gives `my-bot`. */\nexport function packageName(dir: string) {\n const name = basename(resolve(dir)).toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^[._-]+|-+$/g, '')\n return name || 'mushin-app'\n}\n\n/** The files of a new app, by path relative to its folder. */\nexport function appFiles(name: string, version = VERSION, packageManager: PackageManager = 'npm'): Record<string, string> {\n const range = dependencyRange(version)\n const json = (value: unknown) => JSON.stringify(value, null, 2) + '\\n'\n return {\n 'package.json': json({\n name,\n private: true,\n type: 'module',\n scripts: {\n start: 'mushin start',\n upgrade: 'mushin upgrade',\n typecheck: 'tsc',\n },\n dependencies: {\n '@mushinjs/cli': range,\n // Local plugins in plugins/ import it; with pnpm they only see the app's own dependencies.\n '@mushinjs/core': range,\n },\n devDependencies: {\n '@types/node': '^22.13.0',\n typescript: '^6.0.3',\n },\n engines: { node: '>=22.13' },\n }),\n 'tsconfig.json': json({\n compilerOptions: {\n target: 'es2023',\n lib: ['es2023'],\n module: 'preserve',\n moduleResolution: 'bundler',\n types: ['node'],\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n isolatedModules: true,\n verbatimModuleSyntax: true,\n },\n include: ['plugins/*/src'],\n }),\n '.gitignore': [\n 'node_modules/',\n '# Secrets: keys, tokens. Never commit or share this file.',\n '.env',\n '# Written by Mushin.js. Back up data/; cache/ and logs/ can be deleted.',\n 'data/',\n 'cache/',\n 'logs/',\n '',\n ].join('\\n'),\n // Connects the AI tool opened in this folder to the running Mushin.js; the token stays in .env.\n '.mcp.json': json({\n mcpServers: {\n mushin: { type: 'stdio', command: 'node', args: ['node_modules/@mushinjs/cli/bin/mushin.js', 'mcp'] },\n },\n }),\n 'plugins/.gitkeep': '',\n 'skills/.gitkeep': '',\n ...(packageManager === 'pnpm' ? { 'pnpm-workspace.yaml': PNPM_SETTINGS } : {}),\n }\n}\n\n/**\n * pnpm runs no install scripts it was not told about, and stops the install over them. esbuild (through tsx,\n * for TypeScript plugins) needs its script; ssh2 (the terminal plugin) works without its optional native parts.\n */\nconst PNPM_SETTINGS = `allowBuilds:\n esbuild: true\n cpu-features: false\n ssh2: false\n`\n\n/** Writes a new app into `dir`, which must be missing or empty. */\nexport async function createApp(dir: string, options: { version?: string; packageManager?: PackageManager } = {}) {\n const target = resolve(dir)\n const existing = await readdir(target).catch(() => [] as string[])\n if (existing.length) throw new Error(`${target} is not empty. Choose a new folder name.`)\n const files = appFiles(packageName(target), options.version, options.packageManager)\n for (const [path, content] of Object.entries(files)) {\n const file = join(target, path)\n await mkdir(join(file, '..'), { recursive: true })\n await writeFile(file, content)\n }\n return { dir: target, files: Object.keys(files) }\n}\n\n/** Runs the CLI that was just installed in the app. */\nfunction mushin(dir: string, args: string[]) {\n return new Promise<void>((done, reject) => {\n const bin = join(dir, 'node_modules', '@mushinjs', 'cli', 'bin', 'mushin.js')\n const child = spawn(process.execPath, [bin, ...args, '--dir', dir], { cwd: dir, stdio: 'inherit' })\n child.on('error', reject)\n child.on('exit', (code) => (code ? reject(new Error(`mushin ${args[0]} exited with ${code}`)) : done()))\n })\n}\n\n/** Puts the official skills into the app. */\nexport function addSkills(dir: string) {\n return mushin(dir, ['skills'])\n}\n\n/**\n * Writes the guide for coding agents (AGENTS.md, CLAUDE.md and the like). Without `files` the CLI asks which\n * ones in a terminal, and picks AGENTS.md and CLAUDE.md otherwise.\n */\nexport function addAgentFiles(dir: string, files?: string) {\n return mushin(dir, files === undefined ? ['agents'] : ['agents', '--files', files])\n}\n\n/** Runs the package manager's install in the app folder, with its output shown. */\nexport function install(dir: string, packageManager: PackageManager) {\n return new Promise<void>((done, reject) => {\n // npm and pnpm are .cmd files on Windows, which only start through a shell.\n const child = spawn(packageManager, ['install'], { cwd: dir, stdio: 'inherit', shell: process.platform === 'win32' })\n child.on('error', reject)\n child.on('exit', (code) => (code ? reject(new Error(`${packageManager} install exited with ${code}`)) : done()))\n })\n}\n"],"mappings":";;;;;;AAMA,MAAa,UAAkB,KAAK,MAAM,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC;;AAK7G,SAAgB,qBAAqB,YAAY,QAAQ,IAAI,yBAAyB,IAAoB;CACxG,OAAO,UAAU,WAAW,MAAM,IAAI,SAAS;AACjD;;AAGA,SAAgB,gBAAgB,UAAU,SAAS;CACjD,OAAO,QAAQ,SAAS,GAAG,IAAI,UAAU,IAAI;AAC/C;;AAGA,SAAgB,YAAY,KAAa;CAEvC,OADa,SAAS,QAAQ,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,kBAAkB,GAAG,CAAC,CAAC,QAAQ,gBAAgB,EAC/F,KAAK;AACjB;;AAGA,SAAgB,SAAS,MAAc,UAAU,SAAS,iBAAiC,OAA+B;CACxH,MAAM,QAAQ,gBAAgB,OAAO;CACrC,MAAM,QAAQ,UAAmB,KAAK,UAAU,OAAO,MAAM,CAAC,IAAI;CAClE,OAAO;EACL,gBAAgB,KAAK;GACnB;GACA,SAAS;GACT,MAAM;GACN,SAAS;IACP,OAAO;IACP,SAAS;IACT,WAAW;GACb;GACA,cAAc;IACZ,iBAAiB;IAEjB,kBAA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AI,SAAe,MAAM,WAAW;EACzC,MAAM,MAAM,KAAK,KAAK,gBAAgB,aAAa,OAAO,OAAO,WAAW;EAC5E,MAAM,QAAQ,MAAM,QAAQ,UAAU;GAAC;GAAK,GAAG;GAAM;GAAS;EAAG,GAAG;GAAE,KAAK;GAAK,OAAO;EAAU,CAAC;EAClG,MAAM,GAAG,SAAS,MAAM;EACxB,MAAM,GAAG,SAAS,SAAU,OAAO,uBAAO,IAAI,MAAM,UAAU,KAAK,GAAG,eAAe,MAAM,CAAC,IAAI,KAAK,CAAE;CACzG,CAAC;AACH;;AAGA,SAAgB,UAAU,KAAa;CACrC,OAAO,OAAO,KAAK,CAAC,QAAQ,CAAC;AAC/B;;;;;AAMA,SAAgB,cAAc,KAAa,OAAgB;CACzD,OAAO,OAAO,KAAK,UAAU,KAAA,IAAY,CAAC,QAAQ,IAAI;EAAC;EAAU;EAAW;CAAK,CAAC;AACpF;;AAGA,SAAgB,QAAQ,KAAa,gBAAgC;CACnE,OAAO,IAAI,SAAe,MAAM,WAAW;EAEzC,MAAM,QAAQ,MAAM,gBAAgB,CAAC,SAAS,GAAG;GAAE,KAAK;GAAK,OAAO;GAAW,OAAO,QAAQ,aAAa;EAAQ,CAAC;EACpH,MAAM,GAAG,SAAS,MAAM;EACxB,MAAM,GAAG,SAAS,SAAU,OAAO,uBAAO,IAAI,MAAM,GAAG,eAAe,uBAAuB,MAAM,CAAC,IAAI,KAAK,CAAE;CACjH,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mushin",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-next.20261127155650",
4
4
  "description": "Create a Mushin.js app: npm create mushin@latest my-bot",
5
5
  "type": "module",
6
6
  "license": "MIT",