scaffold-sesi 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Misterscan
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.
package/README.md CHANGED
@@ -1,3 +1,216 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Sesi Project Scaffolder
2
+
3
+ A project generator that creates a structured Sesi application with starter scripts, environment configuration, linting and testing utilities, documentation, and a license.
4
+
5
+ # IMPORTANT:
6
+ - **Before proceeding, inspect your environment and ensure `sesi` is installed.**
7
+ - **Check with `sesi version` to verify sesi is available.**
8
+ - **Inspect this README and repository for usage details.**
9
+ - **After scaffolding, check the created files and structure. Work from there.**
10
+
11
+ ## Features
12
+
13
+ - Creates a project directory with `src/`, `lib/`, `tests/`, and `docs/`.
14
+ - Generates an editable entry point and a central module interface.
15
+ - Copies and adapts an existing linting script.
16
+ - Includes a testing utility. Use these imports in your tests, no need to create them manually.
17
+ - Generates a README and license using local helper functions.
18
+ - Copies selected environment settings into a project-local `.env` file. If missing, defaults are used.
19
+ - Supports a standard projects directory or a sandbox-oriented directory.
20
+ - Rejects project names containing path separators and prevents overwriting an existing project directory.
21
+
22
+ ## Prerequisites
23
+
24
+ The generator expects:
25
+
26
+ - The `sesi` command to be available.
27
+
28
+ ## npm CLI
29
+
30
+ ```sh
31
+ npm install -g @misterscan/sesi
32
+ npx scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
33
+ # If working locally
34
+ npm link # If this is a local development setup, may return an error if already linked. This is expected behavior.
35
+ scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
36
+ ```
37
+
38
+ Run `scaffold-sesi` without arguments for the existing interactive setup. A project name starts generation directly; `--run` is also supported. Use `--template` to select a starter; omitting it preserves the generic starter and existing prompts and destination choices.
39
+
40
+ ## Project Templates
41
+
42
+ ```sh
43
+ scaffold-sesi "my-web" "A web app" Misterscan MIT 2026 sandbox --template web
44
+ scaffold-sesi --template cli "my-cli" "A CLI app" Misterscan MIT 2026 sandbox
45
+ sesi -l main.sesi --run "my-api" "An API" Misterscan MIT 2026 sandbox --template api
46
+ ```
47
+
48
+ | Template | Generated application |
49
+ |---|---|
50
+ | `basic` (default) | Generic editable Sesi entry point and shared project utilities |
51
+ | `web` | Sesi HTTP server, editable HTML/CSS, form handling, and a Base64 JSON theme cookie |
52
+ | `cli` | Greeting command with `greet [name]`, `--help`, and `--version` |
53
+ | `api` | `std/api` application with `/health`, `/hello`, `/docs`, and `/openapi.json` |
54
+
55
+ The `--template basic|web|cli|api` option works before or after positional arguments. Missing values, unknown template names, and duplicate options fail before prompting or creating a project.
56
+
57
+ The web starter follows the Margin client pattern: Sesi renders standard HTML forms and handles browser preferences on the server, without application JavaScript. `std/base64` encodes JSON in an `HttpOnly; SameSite=Lax` cookie. Invalid cookie state defaults to the light theme. HTML and CSS remain readable files under `src/`.
58
+
59
+ Web and API projects start with `npm start` or `sesi -l main.sesi`; native HTTP serving requires `-l`. Both default to port 8080, configurable through `PORT` or `config.sesi`. CLI projects support `npm start -- greet Alice` or `sesi main.sesi greet Alice`.
60
+
61
+ Templates live under `templates/`. Each template module exports `build(context)` and returns `directories`, a `files` map, package `scripts` overrides, and `readme` content. Readable assets live in the corresponding template directory. Configuration, licensing, linting, test utilities, and output generation are shared.
62
+
63
+ ## Scaffolder Verification
64
+
65
+ Run `npm test` to run the Sesi suites in `tests/` using the existing `src/test.sesi` utilities.
66
+
67
+ ## Usage
68
+
69
+ ### Display Help
70
+
71
+ ```sh
72
+ sesi main.sesi --help
73
+ ```
74
+
75
+ Running the generator without arguments also displays help.
76
+
77
+ ### Create a Project
78
+
79
+ ```sh
80
+ sesi -l main.sesi --run "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox" --template basic
81
+ ```
82
+
83
+ Missing values are requested interactively.
84
+
85
+ | Setting | Default |
86
+ |---|---|
87
+ | Project name | `my-sesi-app` |
88
+ | Description | `An app built with Sesi.` |
89
+ | Author | `Unknown` |
90
+ | License | `MIT` |
91
+ | Year | `2026` |
92
+ | Sandbox selection | `agent-sandbox` |
93
+
94
+ The project-name expression includes lowercasing, whitespace trimming, and replacement of spaces with hyphens.
95
+
96
+
97
+ ## Project Location
98
+
99
+ Selecting `n` places the project under:
100
+
101
+ ```text
102
+ $HOME/Documents/Projects/<project-name>/
103
+ ```
104
+
105
+ Recognized sandbox selections include `y`, `agent-sandbox`, `agent`, `sandbox`, `ai-agent`, `ai`, and `ai-sandbox`. These place the project under:
106
+
107
+ ```text
108
+ <working-directory>/Sandbox/Projects/<project-name>/
109
+ ```
110
+
111
+ > The sandbox option changes the destination directory only. This script does not establish process isolation, filesystem restrictions, or an AI-agent security boundary.
112
+
113
+ ## Generated Structure
114
+
115
+ ```text
116
+ my-app/
117
+ ├── src/
118
+ ├── lib/
119
+ ├── tests/
120
+ ├── docs/
121
+ ├── .env
122
+ ├── .gitignore
123
+ ├── main.sesi
124
+ ├── config.sesi
125
+ ├── check.sesi
126
+ ├── test.sesi
127
+ ├── README.md
128
+ ├── LICENSE
129
+ └── package.json
130
+ ```
131
+
132
+ ### Key Files
133
+
134
+ | File | Purpose |
135
+ |---|---|
136
+ | `main.sesi` | Project entry point with configuration, functions, and execution sections |
137
+ | `config.sesi` | Shared configuration, including the server port |
138
+ | `check.sesi` | Checks Sesi files directly inside `.`, `lib/`, `src/`, and `tests/` |
139
+ | `test.sesi` | Test discovery and execution |
140
+ | `lib/lint.sesi` | Adapted linting script |
141
+ | `lib/test.sesi` | Copied testing utility |
142
+ | `.env` | Generated environment settings |
143
+ | `README.md` | Project documentation |
144
+ | `LICENSE` | Generated license text |
145
+ | `package.json` | Project metadata and command shortcuts |
146
+
147
+ ### Starter Entry Point
148
+
149
+ ```sesi
150
+ /**
151
+ Project entry point.
152
+
153
+ Run: `sesi main.sesi`
154
+ */
155
+
156
+ allow "src/" in as *
157
+ allow "config" in with {global}
158
+
159
+ // Functions
160
+ // Define named functions here (if applicable).
161
+
162
+ // Execution
163
+ try {
164
+ // Write top-level project logic here.
165
+ // ...
166
+ } catch (e) { show e }
167
+ ```
168
+
169
+ ## Environment Configuration
170
+
171
+ The generator reads the current environment and writes these settings to `.env`:
172
+
173
+ | Variable | Fallback |
174
+ |---|---|
175
+ | `GEMINI_API_KEY` | Empty string |
176
+ | `OPENAI_API_KEY` | Empty string |
177
+ | `SESI_PASSWORD` | Empty string |
178
+ | `SESI_SAFE_MODE` | `true` |
179
+ | `SESI_LOCAL_FS` | `false` |
180
+
181
+ Values are serialized with `to_json()` before being written.
182
+
183
+ **Security:** API keys and passwords are copied into a plaintext file. Although the generated `.gitignore` excludes `.env`, avoid sharing it or including it in public artifacts. This generator writes the configuration file; it does not explicitly load it into the generated application.
184
+
185
+ ## Development Commands
186
+
187
+ Run these commands from the generated project directory:
188
+
189
+ ```sh
190
+ # Run the application
191
+ npm start
192
+
193
+ # Quick scaffold
194
+ npm run scaffold
195
+
196
+ # Run sandbox
197
+ npm run sandbox
198
+
199
+ # Check sesi files
200
+ npm run check
201
+
202
+ # Run the generated linter
203
+ npm run lint
204
+ ```
205
+
206
+ The generated `package.json` also defines `eval`, `help`, `encrypt`, and `decrypt` scripts.
207
+
208
+ ## Linter Adaptations
209
+
210
+ The generator modifies the existing lint template to:
211
+
212
+ - Target `.`, `src`, `lib`, and `tests`.
213
+ - Discover exported names from top-level local wildcard imports without executing imported modules.
214
+ - Recognize those imported names during scope auditing.
215
+
216
+ These modifications use exact string replacements, so changes to the source lint template may require corresponding updates to the generator.
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { existsSync } = require('node:fs');
5
+ const path = require('node:path');
6
+ const { spawnSync } = require('node:child_process');
7
+
8
+ function findNpmSesi() {
9
+ for (const entry of (process.env.PATH ?? '').split(path.delimiter).filter(Boolean)) {
10
+ const directory = entry.replace(/^"|"$/g, '');
11
+ const modules = path.basename(directory) === '.bin'
12
+ ? path.dirname(directory)
13
+ : path.join(directory, 'node_modules');
14
+ const script = path.join(modules, '@misterscan', 'sesi', 'bin', 'sesi.js');
15
+ if (existsSync(script)) return script;
16
+ }
17
+ }
18
+
19
+ // Keep all prompting and project generation in the existing Sesi script.
20
+ const args = process.argv.slice(2);
21
+ const version = require('../package.json').version;
22
+ if (args.includes('--version') || args.includes('-v')) {
23
+ console.log(version);
24
+ process.exit(0);
25
+ }
26
+ if (args.length === 0 || !args[0].startsWith('-') || args[0] === '--template') args.unshift('--run');
27
+ const sesiArgs = [
28
+ '-l', path.resolve(__dirname, '../main.sesi'), ...args
29
+ ];
30
+ const options = {
31
+ cwd: path.resolve(__dirname, '..'),
32
+ env: { ...process.env, PWD: process.cwd() },
33
+ stdio: 'inherit'
34
+ };
35
+ const isWindows = process.platform === 'win32';
36
+ let result = spawnSync(isWindows ? 'sesi.exe' : 'sesi', sesiArgs, options);
37
+ if (isWindows && result.error?.code === 'ENOENT') {
38
+ // Run npm's JavaScript entry point directly so arguments never pass through cmd.exe.
39
+ const script = findNpmSesi();
40
+ if (script) result = spawnSync(process.execPath, [script, ...sesiArgs], options);
41
+ }
42
+
43
+ if (result.error) {
44
+ console.error(result.error.code === 'ENOENT'
45
+ ? 'scaffold-sesi requires Sesi on PATH. Install it with: npm install -g @misterscan/sesi'
46
+ : result.error.message);
47
+ }
48
+ process.exitCode = result.status ?? 1;
package/lib/local.sesi ADDED
@@ -0,0 +1,53 @@
1
+ export fn generateLicense(name: string, year: string, license: string) -> string {
2
+ let licensePlaceholder = ""
3
+ if license == "MIT" { licensePlaceholder = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" }
4
+ if license == "Apache-2.0" { licensePlaceholder = "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n" }
5
+ if license == "GPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
6
+ if license == "BSD-3-Clause" { licensePlaceholder = "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n" }
7
+ if license == "MPL-2.0" { licensePlaceholder = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. \n" }
8
+ if license == "AGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
9
+ if license == "LGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
10
+ if license == "EPL-2.0" { licensePlaceholder = "This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/. \n"
11
+ } else if license == "Unlicense" { licensePlaceholder = "This is free and unencumbered software released into the public domain.\n"
12
+ } else if license == "CC0-1.0" { licensePlaceholder = "The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.\n"
13
+ } else if license == "Proprietary" { licensePlaceholder = "All rights reserved. This software is proprietary and confidential. Unauthorized copying of this file, via any medium is strictly prohibited.\n"
14
+ } else if license == "" { licensePlaceholder = "No license specified. All rights reserved.\n" }
15
+ prompt licenseText {"# "license" License
16
+
17
+ Copyright (c) " year " " name "
18
+
19
+ "licensePlaceholder"
20
+ (if applicable, include the full text of the license here)
21
+ "}
22
+ return licenseText
23
+ }
24
+
25
+ fn generateReadMe(title: string, description: string, body: string, installation: string, usage: string) -> string {
26
+ prompt contents {"# "title"
27
+ "description"
28
+ ----
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ " installation "
34
+ ```
35
+
36
+ " body "
37
+ ----
38
+
39
+ ## Usage
40
+
41
+ ```bash
42
+ " usage "
43
+ ```
44
+ ----
45
+ "}
46
+ return contents
47
+ }
48
+
49
+ export fn generateReadMeWithLicense(title: string, description: string, body: string, installation: string, usage: string, license: string, name: string, year: string) -> string {
50
+ let licenseText = generateLicense(name, year, license)
51
+ let readme = generateReadMe(title, description, body, installation, usage + "\n" + licenseText + "----")
52
+ return readme
53
+ }
package/lib/term.sesi ADDED
@@ -0,0 +1,5 @@
1
+ allow "std/terminal" in as Term
2
+ export fn info(msg: string) { let text = "ℹ️ " + msg; show text | Term.color("cyan") | Term.style("bold") }
3
+ export fn success(msg: string) { let text = "✔ " + msg; show text | Term.color("green") | Term.style("bold") }
4
+ export fn warning(msg: string) { let text = "⚠️ " + msg; show text | Term.color("yellow") | Term.style("bold") }
5
+ export fn error(msg: string) { let text = "✖ " + msg; show text | Term.color("red") | Term.style("bold") }
package/lib/utils.sesi ADDED
@@ -0,0 +1,27 @@
1
+ /** Create a fresh test directory using Sesi filesystem functions. */
2
+ export fn temporary_directory() {
3
+ let base = $TMPDIR || $TEMP || $TMP || "/tmp"
4
+ fn create_directory() {
5
+ let path = base + "/scaffold-sesi-" + str(floor(random() * 1000000000)) + "-" + str(floor(random() * 1000000000))
6
+ if exists(path) { raise_error("TestSetupError", "Temporary path already exists.") }
7
+ if !make_dir(path) { raise_error("TestSetupError", "Unable to create temporary directory.") }
8
+ return path
9
+ }
10
+ return retry(create_directory, {max_retries: 9, initial_delay: 25, backoff_factor: 1})
11
+ }
12
+
13
+ /** Quote a test argument for the shell used by Sesi's run builtin. */
14
+ export fn quote(value) {
15
+ if $OS == "Windows_NT" { return "\"" + str(value) + "\"" }
16
+ return "'" + swap(str(value), "'", "'\"'\"'") + "'"
17
+ }
18
+
19
+ /** Read a test artifact, retrying transient filesystem failures. */
20
+ export fn read_artifact(path) {
21
+ fn read_once() {
22
+ let content = read_file(path)
23
+ if content == null { raise_error("TestError", "Cannot read artifact: " + path) }
24
+ return content
25
+ }
26
+ return retry(read_once, {max_retries: 2, initial_delay: 50, backoff_factor: 1})
27
+ }