create-mdsn 0.2.2 → 0.3.1

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/README.md CHANGED
@@ -1,52 +1,29 @@
1
1
  # create-mdsn
2
2
 
3
- `create-mdsn` scaffolds a new MDSN site project.
3
+ `create-mdsn` scaffolds a minimal MDSN app.
4
4
 
5
- Use it when you want the shortest path to a runnable MDSN skills app or agent app.
5
+ Use it when you want the fastest path from a blank directory to a working MDSN app.
6
6
 
7
- ## What It Creates
8
-
9
- The starter generates a minimal runnable site with:
10
-
11
- - `pages/index.md`
12
- - `server/actions.cjs`
13
-
14
- That gives you one Markdown page and one action module to start from.
15
-
16
- ## Quick Start
7
+ ## Usage
17
8
 
18
9
  ```bash
19
- npm create mdsn@latest skills-app
20
- cd skills-app
10
+ npm create mdsn@latest agent-app
11
+ cd agent-app
21
12
  npm install
22
- npm run dev
13
+ npm start
23
14
  ```
24
15
 
25
- Open:
26
-
27
- ```text
28
- http://localhost:3000/
29
- ```
30
-
31
- ## What MDSN Is For
32
-
33
- MDSN is a Markdown-native interaction model for:
34
-
35
- - skills apps
36
- - agent apps
37
- - interactive documents
38
- - shared human-agent workflows
39
-
40
- In MDSN, page content is not just presentation. It is also shared prompt context for AI agents.
41
-
42
- That is what lets the same page source work as:
16
+ The generated app uses this small shape:
43
17
 
44
- - content for humans
45
- - interaction structure for hosts
46
- - prompt context for agents
18
+ - `app/index.md`
19
+ - `app/server.ts`
20
+ - `app/client.ts`
21
+ - `index.mjs`
47
22
 
48
23
  ## Docs
49
24
 
25
+ - [Docs](https://docs.mdsn.ai/docs)
50
26
  - [Getting Started](https://docs.mdsn.ai/docs/getting-started)
51
- - [Framework Development](https://docs.mdsn.ai/docs/site-development)
52
- - [HTTP Content Negotiation and Shared Interaction](https://docs.mdsn.ai/docs/shared-interaction)
27
+ - [Understanding MDSN](https://docs.mdsn.ai/docs/understanding-mdsn)
28
+ - [Examples](https://docs.mdsn.ai/docs/examples)
29
+ - [SDK Overview](https://docs.mdsn.ai/docs/sdk)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from "node:path";
3
+ import { readCreateMdsnVersion, scaffoldStarterProject } from "./index.js";
4
+ function printUsage() {
5
+ console.log("Usage: npm create mdsn@latest <project-name>");
6
+ }
7
+ async function main(argv) {
8
+ const [targetArg] = argv;
9
+ if (!targetArg || targetArg === "--help" || targetArg === "-h") {
10
+ printUsage();
11
+ return;
12
+ }
13
+ const targetDir = resolve(process.cwd(), targetArg);
14
+ const version = await readCreateMdsnVersion();
15
+ const projectDir = await scaffoldStarterProject({
16
+ targetDir,
17
+ sdkVersion: version,
18
+ ...(targetArg === "." ? {} : { projectName: targetArg })
19
+ });
20
+ console.log(`Created MDSN starter in ${projectDir}`);
21
+ console.log("");
22
+ console.log("Next steps:");
23
+ console.log(` cd ${targetArg}`);
24
+ console.log(" npm install");
25
+ console.log(" npm start");
26
+ }
27
+ main(process.argv.slice(2)).catch((error) => {
28
+ console.error(error instanceof Error ? error.message : String(error));
29
+ process.exitCode = 1;
30
+ });
31
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE3E,SAAS,UAAU;IACjB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;AAC9D,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,IAAc;IAChC,M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Dir: string;
3
+ projectName?: string;
4
+ sdkVersion: string;
5
+ }
6
+ export declare function scaffoldStarterProject(options: ScaffoldStarterProjectOptions, moduleUrl?: string): Promise<string>;
7
+ export declare function readCreateMdsnVersion(moduleUrl?: string): Promise<string>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,6BAA6B;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AA4DD,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,6BAA6B,EACtC,SAAS,SAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,wBAAsB,qBAAqB,CAAC,SAAS,SAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxF"}
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ import { cp, mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
2
+ import { basename, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const TEMPLATE_PLACEHOLDERS = {
5
+ __PROJECT_NAME__: "",
6
+ __SDK_VERSION__: ""
7
+ };
8
+ function packageRootFromModule(moduleUrl) {
9
+ return resolve(fileURLToPath(new URL("..", moduleUrl)));
10
+ }
11
+ function templateRootFromModule(moduleUrl) {
12
+ return resolve(fileURLToPath(new URL("../template/starter", moduleUrl)));
13
+ }
14
+ async function ensureEmptyTarget(targetDir) {
15
+ try {
16
+ const targetStat = await stat(targetDir);
17
+ if (!targetStat.isDirectory()) {
18
+ throw new Error(`Target path "${targetDir}" already exists and is not a directory.`);
19
+ }
20
+ const entries = await readdir(targetDir);
21
+ if (entries.length > 0) {
22
+ throw new Error(`Target directory "${targetDir}" must be empty.`);
23
+ }
24
+ }
25
+ catch (error) {
26
+ const code = error.code;
27
+ if (code === "ENOENT") {
28
+ await mkdir(targetDir, { recursive: true });
29
+ return;
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+ async function replaceInFile(filePath, replacements) {
35
+ const original = await readFile(filePath, "utf8");
36
+ let next = original;
37
+ for (const [pattern, value] of Object.entries(replacements)) {
38
+ next = next.replaceAll(pattern, value);
39
+ }
40
+ if (next !== original) {
41
+ await writeFile(filePath, next, "utf8");
42
+ }
43
+ }
44
+ async function walkFiles(root) {
45
+ const entries = await readdir(root, { withFileTypes: true });
46
+ const files = [];
47
+ for (const entry of entries) {
48
+ const filePath = join(root, entry.name);
49
+ if (entry.isDirectory()) {
50
+ files.push(...(await walkFiles(filePath)));
51
+ continue;
52
+ }
53
+ files.push(filePath);
54
+ }
55
+ return files;
56
+ }
57
+ export async function scaffoldStarterProject(options, moduleUrl = import.meta.url) {
58
+ const templateRoot = templateRootFromModule(moduleUrl);
59
+ const targetDir = resolve(options.targetDir);
60
+ const projectName = options.projectName?.trim() || basename(targetDir);
61
+ if (!projectName) {
62
+ throw new Error("Project name cannot be empty.");
63
+ }
64
+ await ensureEmptyTarget(targetDir);
65
+ await cp(templateRoot, targetDir, { recursive: true });
66
+ const replacements = {
67
+ __PROJECT_NAME__: projectName,
68
+ __SDK_VERSION__: options.sdkVersion
69
+ };
70
+ const files = await walkFiles(targetDir);
71
+ await Promise.all(files.map((filePath) => replaceInFile(filePath, replacements)));
72
+ return targetDir;
73
+ }
74
+ export async function readCreateMdsnVersion(moduleUrl = import.meta.url) {
75
+ const packageJsonPath = join(packageRootFromModule(moduleUrl), "package.json");
76
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
77
+ if (!packageJson.version) {
78
+ throw new Error("Unable to determine create-mdsn package version.");
79
+ }
80
+ return packageJson.version;
81
+ }
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,KA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,8 +1,8 @@
1
1
  {
2
2
  "name": "create-mdsn",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
- "description": "npm create entry for scaffolding a new MDSN site project.",
5
+ "description": "Create a minimal MDSN app with npm create.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://docs.mdsn.ai",
8
8
  "bugs": {
@@ -25,15 +25,26 @@
25
25
  "agent-app",
26
26
  "cli"
27
27
  ],
28
- "bin": {
29
- "create-mdsn": "./bin/create-mdsn.js"
28
+ "type": "module",
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "engines": {
32
+ "node": ">=20"
30
33
  },
31
34
  "files": [
32
- "bin",
33
- "README.md",
34
- "LICENSE"
35
+ "dist",
36
+ "template/starter"
35
37
  ],
38
+ "bin": {
39
+ "create-mdsn": "./dist/cli.js"
40
+ },
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/index.d.ts",
44
+ "default": "./dist/index.js"
45
+ }
46
+ },
36
47
  "dependencies": {
37
- "@mdsnai/sdk": "0.2.2"
48
+ "@mdsnai/sdk": "0.3.0"
38
49
  }
39
50
  }
@@ -0,0 +1,29 @@
1
+ # __PROJECT_NAME__
2
+
3
+ This is a minimal MDSN starter.
4
+
5
+ ## 30-Second Tour
6
+
7
+ - `app/index.md`
8
+ Defines the page source and interaction.
9
+ - `app/server.ts`
10
+ Owns state and action handlers.
11
+ - `app/client.ts`
12
+ Mounts the browser runtime.
13
+ - `index.mjs`
14
+ Starts the Node host.
15
+
16
+ ## Run It
17
+
18
+ ```bash
19
+ npm install
20
+ npm start
21
+ ```
22
+
23
+ Then open [http://127.0.0.1:3000/](http://127.0.0.1:3000/).
24
+
25
+ ## First Things To Change
26
+
27
+ 1. Edit `app/index.md`
28
+ 2. Edit `app/server.ts`
29
+ 3. Keep `app/client.ts` as-is, or replace it when you want to own the UI
@@ -0,0 +1,7 @@
1
+ import { mountMdsnElements } from "@mdsnai/sdk/elements";
2
+ import { createHeadlessHost } from "@mdsnai/sdk/web";
3
+
4
+ export function mountApp(root: HTMLElement, fetchImpl: typeof fetch): void {
5
+ const host = createHeadlessHost({ root, fetchImpl });
6
+ mountMdsnElements({ root, host }).mount();
7
+ }
@@ -0,0 +1,17 @@
1
+ ---
2
+ title: "Agent App"
3
+ ---
4
+
5
+ # Agent App
6
+
7
+ Use this starter as the smallest end-to-end MDSN app.
8
+
9
+ <!-- mdsn:block main -->
10
+
11
+ ```mdsn
12
+ BLOCK main {
13
+ INPUT text required -> message
14
+ GET "/list" -> refresh label:"Refresh"
15
+ POST "/post" (message) -> submit label:"Submit"
16
+ }
17
+ ```
@@ -0,0 +1,51 @@
1
+ import { composePage } from "@mdsnai/sdk/core";
2
+ import { createHostedApp } from "@mdsnai/sdk/server";
3
+
4
+ export interface CreateAppServerOptions {
5
+ source: string;
6
+ initialMessages?: string[];
7
+ }
8
+
9
+ export function createAppServer(options: CreateAppServerOptions) {
10
+ const messages = [...(options.initialMessages ?? ["Welcome to MDSN"])];
11
+
12
+ function renderMainBlock(): string {
13
+ const count = `${messages.length} live ${messages.length === 1 ? "message" : "messages"}`;
14
+ return `## ${count}\n\n${messages.map((message) => `- ${message}`).join("\n")}`;
15
+ }
16
+
17
+ function renderPage() {
18
+ return composePage(options.source, {
19
+ blocks: {
20
+ main: renderMainBlock()
21
+ }
22
+ });
23
+ }
24
+
25
+ return createHostedApp({
26
+ pages: {
27
+ "/": renderPage
28
+ },
29
+ actions: [
30
+ {
31
+ target: "/list",
32
+ methods: ["GET"],
33
+ routePath: "/",
34
+ blockName: "main",
35
+ handler: ({ block }) => block()
36
+ },
37
+ {
38
+ target: "/post",
39
+ methods: ["POST"],
40
+ routePath: "/",
41
+ blockName: "main",
42
+ handler: ({ inputs, block }) => {
43
+ if (inputs.message) {
44
+ messages.push(inputs.message);
45
+ }
46
+ return block();
47
+ }
48
+ }
49
+ ]
50
+ });
51
+ }
@@ -0,0 +1,62 @@
1
+ import http from "node:http";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ import { createNodeHost } from "@mdsnai/sdk/server";
7
+
8
+ import { createAppServer } from "./dist/server.js";
9
+
10
+ const port = Number(process.env.PORT || 3000);
11
+ const projectRoot = fileURLToPath(new URL("./", import.meta.url));
12
+ const sourcePath = join(projectRoot, "app", "index.md");
13
+ const assetVersion = Date.now().toString(36);
14
+
15
+ function withVersion(path) {
16
+ return `${path}?v=${assetVersion}`;
17
+ }
18
+
19
+ const importMap = {
20
+ imports: {
21
+ "@mdsnai/sdk/core": withVersion("/node_modules/@mdsnai/sdk/dist/core/index.js"),
22
+ "@mdsnai/sdk/web": withVersion("/node_modules/@mdsnai/sdk/dist/web/index.js"),
23
+ "@mdsnai/sdk/elements": withVersion("/node_modules/@mdsnai/sdk/dist/elements/index.js"),
24
+ "lit": withVersion("/node_modules/lit/index.js"),
25
+ "lit-html": withVersion("/node_modules/lit-html/lit-html.js"),
26
+ "lit-html/is-server.js": withVersion("/node_modules/lit-html/is-server.js"),
27
+ "lit-element/lit-element.js": withVersion("/node_modules/lit-element/lit-element.js"),
28
+ "@lit/reactive-element": withVersion("/node_modules/@lit/reactive-element/reactive-element.js")
29
+ }
30
+ };
31
+
32
+ function injectEnhancement(html) {
33
+ const enhancement = `
34
+ <script type="importmap">${JSON.stringify(importMap)}</script>
35
+ <script type="module">
36
+ import { mountApp } from "${withVersion("/app/client.js")}";
37
+ mountApp(document, window.fetch.bind(window));
38
+ </script>`;
39
+
40
+ return html.replace("</body>", `${enhancement}\n </body>`);
41
+ }
42
+
43
+ const source = await readFile(sourcePath, "utf8");
44
+ const mdsn = createAppServer({ source });
45
+ const server = http.createServer(
46
+ createNodeHost(mdsn, {
47
+ transformHtml: injectEnhancement,
48
+ staticFiles: {
49
+ "/app/client.js": join(projectRoot, "dist", "client.js")
50
+ },
51
+ staticMounts: [
52
+ {
53
+ urlPrefix: "/node_modules/",
54
+ directory: join(projectRoot, "node_modules")
55
+ }
56
+ ]
57
+ })
58
+ );
59
+
60
+ server.listen(port, "127.0.0.1", () => {
61
+ console.log(`MDSN starter running at http://127.0.0.1:${port}/`);
62
+ });
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "__PROJECT_NAME__",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsc -p tsconfig.json",
8
+ "start": "npm run build && node index.mjs"
9
+ },
10
+ "dependencies": {
11
+ "@mdsnai/sdk": "^__SDK_VERSION__"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^24.6.0",
15
+ "typescript": "^5.9.3"
16
+ }
17
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "sourceMap": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "exactOptionalPropertyTypes": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "resolveJsonModule": true,
15
+ "lib": ["ES2022", "DOM"],
16
+ "types": ["node"],
17
+ "rootDir": "./app",
18
+ "outDir": "./dist"
19
+ },
20
+ "include": ["app/**/*.ts"]
21
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 MDSN Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { runCli } = require("@mdsnai/sdk/cli");
4
-
5
- runCli(["create", ...process.argv.slice(2)]).catch((error) => {
6
- console.error(error);
7
- process.exitCode = 1;
8
- });