agentic-scaffold 0.0.0-stage → 0.1.2

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 Pooria Arab
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,74 @@
1
- # Temporary Holding Version
1
+ # agentic-scaffold
2
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.
3
+ [![npm version](https://img.shields.io/npm/v/agentic-scaffold)](https://www.npmjs.com/package/agentic-scaffold)
4
+ [![Monthly downloads](https://img.shields.io/npm/dm/agentic-scaffold)](https://www.npmjs.com/package/agentic-scaffold)
5
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue)](https://opensource.org/license/mit)
6
+
7
+ [Package](https://www.npmjs.com/package/agentic-scaffold) · [Source](https://github.com/pooriaarab/agentic-scaffold) · [Support](https://github.com/pooriaarab/agentic-scaffold/issues)
8
+
9
+ agentic-scaffold is an open-source TypeScript starter for developers who need a Node.js library, command-line interface, and Model Context Protocol (MCP) server.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install agentic-scaffold
15
+ ```
16
+
17
+ Requires Node.js 18 or later. Includes TypeScript declarations and two direct dependencies: the MCP SDK and Zod.
18
+
19
+ ## Run your first summary
20
+
21
+ No credentials, environment variables, or `.env` loader are required.
22
+
23
+ ```sh
24
+ npx agentic-scaffold summary --text "hello world hello"
25
+ ```
26
+
27
+ Success prints JSON with `chars: 17`, `words: 3`, `lines: 1`, and `hello` counted twice.
28
+
29
+ ```js
30
+ import { summarizeText, getCostReport } from "agentic-scaffold";
31
+ console.log(summarizeText("hello world hello"));
32
+ console.log(getCostReport()); // { entries: [], dispatches: 0, units: 0 }
33
+ ```
34
+
35
+ ## Features and runtime surfaces
36
+
37
+ - **Text statistics:** Character, word, line, and top-word counts; no semantic summarization.
38
+ - **Routing:** Two generic adapters: local receipts and HTTP POST with `{ text }`.
39
+ - **Guards:** Optional dispatch caps, UTC quiet hours, and text blocklists.
40
+ - **Utilities:** Brand configuration, stderr logging, dry-run results, and in-memory cost units.
41
+ - **CLI:** `summary`, `dispatch`, `costs`, `mcp`; help via `--help` and version via `--version`.
42
+ - **MCP:** Three tools: `summarize_text`, `dispatch_text`, `get_cost_report`.
43
+ - **Worker scaffold:** Source handler for `GET /health` and `POST /summarize`; users deploy it themselves.
44
+
45
+ Start MCP with `npx agentic-scaffold mcp`. Preview routing with `npx agentic-scaffold dispatch --text hello --dry-run`.
46
+
47
+ ## Limits
48
+
49
+ This starter has zero vendor-specific integrations. Local dispatch creates a receipt without external delivery.
50
+ CLI and MCP dispatch use the local adapter by default; SDK callers can supply the HTTP adapter.
51
+ HTTP delivery defaults to a ten-second timeout, with no retries. Cost units count text length rather than billing charges.
52
+ Reports reset when the process exits. CLI help and MCP identity still use the starter name `agentic-pack`.
53
+
54
+ ## Customize a cloned starter
55
+
56
+ ```sh
57
+ git clone https://github.com/pooriaarab/agentic-scaffold.git my-pack
58
+ cd my-pack
59
+ npm ci
60
+ npm run build && npm run typecheck && npm test
61
+ node dist/cli.js summary --text "hello world hello"
62
+ ```
63
+
64
+ Replace `__PACK_NAME__`, `__NPM_NAME__`, `__PACK_COMMAND__`, `__PACK_DESCRIPTION__`, `__PACK_KEYWORDS__`, and `__GITHUB_USER__` wherever they appear.
65
+ Check `AGENTS.md`, `SKILL.md`, `RULES.md`, `llms.txt`, `server.json`, `.mcp.json`, and `wrangler.jsonc`.
66
+ Update package identity, bin commands, `mcpName`, and `DEFAULT_BRAND` in `src/index.ts`.
67
+ Set the MCP manifest version and repository ID before publishing your own package.
68
+
69
+ The repository includes a shared core contract and a publish workflow. Inspect that workflow before adopting its release process.
70
+ Version 0.1.1 is an early starter release; interfaces can change.
71
+
72
+ ## License
73
+
74
+ MIT.
@@ -0,0 +1,91 @@
1
+ import {
2
+ DEFAULT_BRAND
3
+ } from "./chunk-QWFNPAA4.js";
4
+ import {
5
+ GuardError,
6
+ LocalRouterAdapter,
7
+ VendorError,
8
+ createLogger,
9
+ dispatchText,
10
+ getCostReport,
11
+ summarizeText
12
+ } from "./chunk-USJ2R2T2.js";
13
+
14
+ // src/mcp.ts
15
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
16
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
+ import { z } from "zod";
18
+ var textShape = {
19
+ text: z.string().describe("The text to handle.")
20
+ };
21
+ function errorResult(error) {
22
+ const message = error instanceof Error ? error.message : String(error);
23
+ return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
24
+ }
25
+ function okResult(value) {
26
+ return { content: [{ type: "text", text: JSON.stringify(value) }] };
27
+ }
28
+ function createMcpServer(deps = {}) {
29
+ const router = deps.router ?? new LocalRouterAdapter();
30
+ const guards = deps.guards;
31
+ const logger = deps.logger ?? createLogger({ quiet: true });
32
+ const server = new McpServer({
33
+ name: DEFAULT_BRAND.command,
34
+ version: DEFAULT_BRAND.version
35
+ });
36
+ server.registerTool(
37
+ "summarize_text",
38
+ {
39
+ description: "Count chars, words, and lines in a text, with top words.",
40
+ inputSchema: textShape,
41
+ annotations: { readOnlyHint: true }
42
+ },
43
+ async ({ text }) => okResult(summarizeText(text))
44
+ );
45
+ server.registerTool(
46
+ "dispatch_text",
47
+ {
48
+ description: "Route one text through the pack router. Pass dryRun to preview only.",
49
+ inputSchema: {
50
+ ...textShape,
51
+ dryRun: z.boolean().optional().describe("Preview the route without delivery.")
52
+ },
53
+ annotations: {
54
+ readOnlyHint: false,
55
+ destructiveHint: false,
56
+ idempotentHint: false,
57
+ openWorldHint: false
58
+ }
59
+ },
60
+ async ({ text, dryRun }) => {
61
+ try {
62
+ return okResult(await dispatchText(text, { adapter: router, guards, logger, dryRun: dryRun ?? false }));
63
+ } catch (error) {
64
+ if (error instanceof GuardError || error instanceof VendorError) {
65
+ return errorResult(error);
66
+ }
67
+ throw error;
68
+ }
69
+ }
70
+ );
71
+ server.registerTool(
72
+ "get_cost_report",
73
+ {
74
+ description: "Read the cost report for this session.",
75
+ inputSchema: {},
76
+ annotations: { readOnlyHint: true }
77
+ },
78
+ async () => okResult(getCostReport())
79
+ );
80
+ return server;
81
+ }
82
+ async function startMcp(deps = {}) {
83
+ const server = createMcpServer(deps);
84
+ const transport = new StdioServerTransport();
85
+ await server.connect(transport);
86
+ }
87
+
88
+ export {
89
+ createMcpServer,
90
+ startMcp
91
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ VERSION,
3
+ defineBrand
4
+ } from "./chunk-USJ2R2T2.js";
5
+
6
+ // src/index.ts
7
+ var DEFAULT_BRAND = defineBrand({
8
+ name: "Agentic pack",
9
+ command: "agentic-pack",
10
+ description: "Canonical scaffold for a CLI plus library plus MCP server pack.",
11
+ keywords: ["cli", "mcp", "scaffold", "starter", "typescript"],
12
+ version: VERSION
13
+ });
14
+
15
+ export {
16
+ DEFAULT_BRAND
17
+ };
@@ -0,0 +1,226 @@
1
+ // src/core.ts
2
+ import { randomUUID } from "crypto";
3
+ function defineBrand(config) {
4
+ for (const key of ["name", "command", "version"]) {
5
+ if (config[key].trim().length === 0) {
6
+ throw new Error(`brand ${key} must not be empty`);
7
+ }
8
+ }
9
+ return Object.freeze({ ...config, keywords: [...config.keywords] });
10
+ }
11
+ var LEVEL_ORDER = {
12
+ debug: 0,
13
+ info: 1,
14
+ warn: 2,
15
+ error: 3
16
+ };
17
+ function createLogger(options = {}) {
18
+ const level = options.level ?? "info";
19
+ const quiet = options.quiet ?? false;
20
+ const sink = options.sink ?? ((line) => process.stderr.write(`${line}
21
+ `));
22
+ const emit = (at, message) => {
23
+ if (quiet) return;
24
+ if (LEVEL_ORDER[at] < LEVEL_ORDER[level]) return;
25
+ sink(`[${at}] ${message}`);
26
+ };
27
+ return {
28
+ debug: (message) => emit("debug", message),
29
+ info: (message) => emit("info", message),
30
+ warn: (message) => emit("warn", message),
31
+ error: (message) => emit("error", message)
32
+ };
33
+ }
34
+ var GuardError = class extends Error {
35
+ code = "GUARD_DENIED";
36
+ constructor(message) {
37
+ super(message);
38
+ this.name = "GuardError";
39
+ }
40
+ };
41
+ var VendorError = class extends Error {
42
+ code = "VENDOR_FAILED";
43
+ status;
44
+ constructor(message, options = {}) {
45
+ super(message, { cause: options.cause });
46
+ this.name = "VendorError";
47
+ this.status = options.status;
48
+ }
49
+ };
50
+ function assertHour(value, label) {
51
+ if (value === void 0) return;
52
+ if (!Number.isInteger(value) || value < 0 || value > 24) {
53
+ throw new Error(`${label} must be an integer from 0 to 24`);
54
+ }
55
+ }
56
+ function createGuards(config = {}) {
57
+ const maxDispatches = config.caps?.maxDispatches;
58
+ if (maxDispatches !== void 0 && (!Number.isInteger(maxDispatches) || maxDispatches < 0)) {
59
+ throw new Error("caps.maxDispatches must be an integer of 0 or more");
60
+ }
61
+ const startHour = config.quietHours?.startHour;
62
+ const endHour = config.quietHours?.endHour;
63
+ assertHour(startHour, "quietHours.startHour");
64
+ assertHour(endHour, "quietHours.endHour");
65
+ const blocklist = (config.blocklist ?? []).map((term) => term.toLowerCase());
66
+ const now = config.now ?? (() => /* @__PURE__ */ new Date());
67
+ let count = 0;
68
+ const inQuietHours = (date) => {
69
+ if (startHour === void 0 || endHour === void 0) return false;
70
+ const hour = date.getUTCHours();
71
+ if (startHour <= endHour) {
72
+ return hour >= startHour && hour < endHour;
73
+ }
74
+ return hour >= startHour || hour < endHour;
75
+ };
76
+ return {
77
+ get dispatchCount() {
78
+ return count;
79
+ },
80
+ checkDispatch(text) {
81
+ if (maxDispatches !== void 0 && count >= maxDispatches) {
82
+ throw new GuardError(
83
+ `dispatch cap reached (${maxDispatches} of ${maxDispatches})`
84
+ );
85
+ }
86
+ if (inQuietHours(now())) {
87
+ throw new GuardError(
88
+ `quiet hours block dispatches from ${startHour}:00 to ${endHour}:00 UTC`
89
+ );
90
+ }
91
+ const lowered = text.toLowerCase();
92
+ for (const term of blocklist) {
93
+ if (term.length > 0 && lowered.includes(term)) {
94
+ throw new GuardError(`text matches blocklisted term "${term}"`);
95
+ }
96
+ }
97
+ },
98
+ recordDispatch() {
99
+ count += 1;
100
+ }
101
+ };
102
+ }
103
+ var LocalRouterAdapter = class {
104
+ name = "local";
105
+ async dispatch(text) {
106
+ if (typeof text !== "string") {
107
+ throw new VendorError("local adapter needs a string");
108
+ }
109
+ return {
110
+ adapter: this.name,
111
+ id: randomUUID(),
112
+ chars: text.length,
113
+ at: (/* @__PURE__ */ new Date()).toISOString()
114
+ };
115
+ }
116
+ };
117
+ var HttpRouterAdapter = class {
118
+ name = "http";
119
+ endpoint;
120
+ timeoutMs;
121
+ fetchFn;
122
+ constructor(endpoint, options = {}) {
123
+ if (endpoint.trim().length === 0) {
124
+ throw new Error("http adapter needs an endpoint URL");
125
+ }
126
+ this.endpoint = endpoint;
127
+ this.timeoutMs = options.timeoutMs ?? 1e4;
128
+ this.fetchFn = options.fetchFn ?? fetch;
129
+ }
130
+ async dispatch(text) {
131
+ let response;
132
+ try {
133
+ response = await this.fetchFn(this.endpoint, {
134
+ method: "POST",
135
+ headers: { "content-type": "application/json" },
136
+ body: JSON.stringify({ text }),
137
+ signal: AbortSignal.timeout(this.timeoutMs)
138
+ });
139
+ } catch (error) {
140
+ throw new VendorError(`http adapter request failed: ${String(error)}`, {
141
+ cause: error
142
+ });
143
+ }
144
+ if (!response.ok) {
145
+ throw new VendorError(
146
+ `http adapter got status ${response.status} from ${this.endpoint}`,
147
+ { status: response.status }
148
+ );
149
+ }
150
+ return {
151
+ adapter: this.name,
152
+ id: randomUUID(),
153
+ chars: text.length,
154
+ at: (/* @__PURE__ */ new Date()).toISOString()
155
+ };
156
+ }
157
+ };
158
+ var costEntries = [];
159
+ function recordCost(entry) {
160
+ costEntries.push({ ...entry, at: (/* @__PURE__ */ new Date()).toISOString() });
161
+ }
162
+ function getCostReport() {
163
+ const entries = costEntries.map((entry) => ({ ...entry }));
164
+ return {
165
+ entries,
166
+ dispatches: entries.filter((entry) => entry.kind === "dispatch").length,
167
+ units: entries.reduce((sum, entry) => sum + entry.units, 0)
168
+ };
169
+ }
170
+ function resetCosts() {
171
+ costEntries.length = 0;
172
+ }
173
+ function createDryRunResult(text, adapterName) {
174
+ return { dryRun: true, adapter: adapterName, chars: text.length };
175
+ }
176
+ async function dispatchText(text, options = {}) {
177
+ const adapter = options.adapter ?? new LocalRouterAdapter();
178
+ options.guards?.checkDispatch(text);
179
+ if (options.dryRun === true) {
180
+ options.logger?.info(`dry run: would dispatch ${text.length} chars`);
181
+ return createDryRunResult(text, adapter.name);
182
+ }
183
+ const receipt = await adapter.dispatch(text);
184
+ options.guards?.recordDispatch();
185
+ recordCost({ kind: "dispatch", adapter: adapter.name, units: text.length });
186
+ options.logger?.info(`dispatched ${text.length} chars via ${adapter.name}`);
187
+ return { dryRun: false, adapter: adapter.name, chars: text.length, receipt };
188
+ }
189
+ function summarizeText(text, options = {}) {
190
+ const topN = options.topN ?? 5;
191
+ const tokens = text.split(/\s+/).filter((token) => token.length > 0);
192
+ const counts = /* @__PURE__ */ new Map();
193
+ for (const token of tokens) {
194
+ const word = token.toLowerCase().replace(/[^a-z0-9]+/g, "");
195
+ if (word.length === 0) continue;
196
+ counts.set(word, (counts.get(word) ?? 0) + 1);
197
+ }
198
+ const topWords = [...counts.entries()].map(([word, count]) => ({ word, count })).sort((a, b) => b.count - a.count || a.word.localeCompare(b.word)).slice(0, Math.max(0, topN));
199
+ return {
200
+ chars: text.length,
201
+ words: tokens.length,
202
+ lines: text.length === 0 ? 0 : text.split("\n").length,
203
+ topWords
204
+ };
205
+ }
206
+
207
+ // src/version.ts
208
+ import { createRequire } from "module";
209
+ var VERSION = true ? "0.1.2" : readPackageVersion();
210
+
211
+ export {
212
+ defineBrand,
213
+ createLogger,
214
+ GuardError,
215
+ VendorError,
216
+ createGuards,
217
+ LocalRouterAdapter,
218
+ HttpRouterAdapter,
219
+ recordCost,
220
+ getCostReport,
221
+ resetCosts,
222
+ createDryRunResult,
223
+ dispatchText,
224
+ summarizeText,
225
+ VERSION
226
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { R as RouterAdapter } from './core-gVNKa11w.js';
3
+
4
+ declare class UsageError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ type CliCommand = "summary" | "dispatch" | "costs" | "mcp" | "help" | "version";
8
+ interface CliRequest {
9
+ command: CliCommand;
10
+ text?: string;
11
+ file?: string;
12
+ dryRun: boolean;
13
+ topN?: number;
14
+ }
15
+ declare function parseArgs(argv: string[]): CliRequest;
16
+ interface CliIo {
17
+ out(line: string): void;
18
+ err(line: string): void;
19
+ readFile(path: string): string;
20
+ router: RouterAdapter;
21
+ }
22
+ declare function runCli(argv: string[], io?: CliIo): Promise<number>;
23
+
24
+ export { type CliCommand, type CliIo, type CliRequest, UsageError, parseArgs, runCli };
package/dist/cli.js ADDED
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_BRAND
4
+ } from "./chunk-QWFNPAA4.js";
5
+ import {
6
+ GuardError,
7
+ LocalRouterAdapter,
8
+ VERSION,
9
+ VendorError,
10
+ dispatchText,
11
+ getCostReport,
12
+ summarizeText
13
+ } from "./chunk-USJ2R2T2.js";
14
+
15
+ // src/cli.ts
16
+ import { readFileSync, realpathSync } from "fs";
17
+ import { pathToFileURL } from "url";
18
+ var UsageError = class extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "UsageError";
22
+ }
23
+ };
24
+ function parseArgs(argv) {
25
+ const request = { command: "help", dryRun: false };
26
+ const args = [...argv];
27
+ const first = args.shift();
28
+ if (first === void 0 || first === "--help" || first === "-h") {
29
+ return request;
30
+ }
31
+ if (first === "--version" || first === "-V") {
32
+ request.command = "version";
33
+ return request;
34
+ }
35
+ if (first !== "summary" && first !== "dispatch" && first !== "costs" && first !== "mcp") {
36
+ throw new UsageError(`unknown command "${first}"`);
37
+ }
38
+ request.command = first;
39
+ while (args.length > 0) {
40
+ const flag = args.shift();
41
+ if (flag === "--dry-run" && request.command === "dispatch") {
42
+ request.dryRun = true;
43
+ continue;
44
+ }
45
+ if ((flag === "--text" || flag === "--file" || flag === "--top") && args.length > 0) {
46
+ const value = args.shift();
47
+ if (flag === "--text") request.text = value;
48
+ if (flag === "--file") request.file = value;
49
+ if (flag === "--top") {
50
+ const topN = Number.parseInt(value, 10);
51
+ if (!Number.isInteger(topN) || topN < 0) {
52
+ throw new UsageError(`--top needs an integer of 0 or more, got "${value}"`);
53
+ }
54
+ request.topN = topN;
55
+ }
56
+ continue;
57
+ }
58
+ throw new UsageError(`unknown flag "${flag}" for "${request.command}"`);
59
+ }
60
+ if ((request.command === "summary" || request.command === "dispatch") && request.text === void 0 && request.file === void 0) {
61
+ throw new UsageError(`${request.command} needs --text or --file`);
62
+ }
63
+ return request;
64
+ }
65
+ function defaultIo() {
66
+ return {
67
+ out: (line) => console.log(line),
68
+ err: (line) => console.error(line),
69
+ readFile: (path) => readFileSync(path, "utf8"),
70
+ router: new LocalRouterAdapter()
71
+ };
72
+ }
73
+ function helpText() {
74
+ const command = DEFAULT_BRAND.command;
75
+ return [
76
+ `${DEFAULT_BRAND.name} ${VERSION}`,
77
+ `${DEFAULT_BRAND.description}`,
78
+ "",
79
+ `Usage: ${command} <command> [flags]`,
80
+ "",
81
+ "Commands:",
82
+ " summary --text <t> [--file <p>] [--top <n>] Print text stats as JSON.",
83
+ " dispatch --text <t> [--file <p>] [--dry-run] Route one text, print the receipt.",
84
+ " costs Print the cost report as JSON.",
85
+ " mcp Start the MCP server on stdio.",
86
+ "",
87
+ "Flags:",
88
+ " --help, -h Print this help.",
89
+ " --version, -V Print the version."
90
+ ].join("\n");
91
+ }
92
+ function readInput(request, io) {
93
+ if (request.file !== void 0) {
94
+ return io.readFile(request.file);
95
+ }
96
+ return request.text ?? "";
97
+ }
98
+ async function runCli(argv, io = defaultIo()) {
99
+ let request;
100
+ try {
101
+ request = parseArgs(argv);
102
+ } catch (error) {
103
+ io.err(error instanceof Error ? error.message : String(error));
104
+ io.err(`Run "${DEFAULT_BRAND.command} --help" for usage.`);
105
+ return 2;
106
+ }
107
+ try {
108
+ switch (request.command) {
109
+ case "help":
110
+ io.out(helpText());
111
+ return 0;
112
+ case "version":
113
+ io.out(VERSION);
114
+ return 0;
115
+ case "summary": {
116
+ const summary = summarizeText(readInput(request, io), { topN: request.topN });
117
+ io.out(JSON.stringify(summary));
118
+ return 0;
119
+ }
120
+ case "dispatch": {
121
+ const result = await dispatchText(readInput(request, io), {
122
+ adapter: io.router,
123
+ dryRun: request.dryRun
124
+ });
125
+ io.out(JSON.stringify(result));
126
+ return 0;
127
+ }
128
+ case "costs":
129
+ io.out(JSON.stringify(getCostReport()));
130
+ return 0;
131
+ case "mcp": {
132
+ const { startMcp } = await import("./mcp.js");
133
+ await startMcp();
134
+ return 0;
135
+ }
136
+ }
137
+ } catch (error) {
138
+ if (error instanceof GuardError || error instanceof VendorError || error instanceof UsageError) {
139
+ io.err(`${error.name}: ${error.message}`);
140
+ return 1;
141
+ }
142
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
143
+ io.err(`file not found: ${request.file ?? ""}`);
144
+ return 1;
145
+ }
146
+ throw error;
147
+ }
148
+ }
149
+ function isMainModule() {
150
+ const invoked = process.argv[1];
151
+ if (typeof invoked !== "string") return false;
152
+ try {
153
+ return import.meta.url === pathToFileURL(realpathSync(invoked)).href;
154
+ } catch {
155
+ return false;
156
+ }
157
+ }
158
+ if (isMainModule()) {
159
+ runCli(process.argv.slice(2)).then(
160
+ (code) => {
161
+ if (code !== 0) process.exit(code);
162
+ },
163
+ (error) => {
164
+ console.error(error instanceof Error ? error.message : String(error));
165
+ process.exit(1);
166
+ }
167
+ );
168
+ }
169
+ export {
170
+ UsageError,
171
+ parseArgs,
172
+ runCli
173
+ };
@@ -0,0 +1,126 @@
1
+ interface BrandConfig {
2
+ name: string;
3
+ command: string;
4
+ description: string;
5
+ keywords: string[];
6
+ version: string;
7
+ }
8
+ declare function defineBrand(config: BrandConfig): BrandConfig;
9
+ type LogLevel = "debug" | "info" | "warn" | "error";
10
+ interface Logger {
11
+ debug(message: string): void;
12
+ info(message: string): void;
13
+ warn(message: string): void;
14
+ error(message: string): void;
15
+ }
16
+ interface LoggerOptions {
17
+ level?: LogLevel;
18
+ quiet?: boolean;
19
+ sink?: (line: string) => void;
20
+ }
21
+ declare function createLogger(options?: LoggerOptions): Logger;
22
+ declare class GuardError extends Error {
23
+ readonly code = "GUARD_DENIED";
24
+ constructor(message: string);
25
+ }
26
+ declare class VendorError extends Error {
27
+ readonly code = "VENDOR_FAILED";
28
+ readonly status?: number;
29
+ constructor(message: string, options?: {
30
+ status?: number;
31
+ cause?: unknown;
32
+ });
33
+ }
34
+ interface CapsConfig {
35
+ maxDispatches?: number;
36
+ }
37
+ interface QuietHoursConfig {
38
+ startHour?: number;
39
+ endHour?: number;
40
+ }
41
+ interface GuardsConfig {
42
+ caps?: CapsConfig;
43
+ quietHours?: QuietHoursConfig;
44
+ blocklist?: string[];
45
+ now?: () => Date;
46
+ }
47
+ interface Guards {
48
+ readonly dispatchCount: number;
49
+ checkDispatch(text: string): void;
50
+ recordDispatch(): void;
51
+ }
52
+ declare function createGuards(config?: GuardsConfig): Guards;
53
+ interface DispatchReceipt {
54
+ adapter: string;
55
+ id: string;
56
+ chars: number;
57
+ at: string;
58
+ }
59
+ interface RouterAdapter {
60
+ readonly name: string;
61
+ dispatch(text: string): Promise<DispatchReceipt>;
62
+ }
63
+ declare class LocalRouterAdapter implements RouterAdapter {
64
+ readonly name = "local";
65
+ dispatch(text: string): Promise<DispatchReceipt>;
66
+ }
67
+ interface HttpRouterOptions {
68
+ timeoutMs?: number;
69
+ fetchFn?: typeof fetch;
70
+ }
71
+ declare class HttpRouterAdapter implements RouterAdapter {
72
+ readonly name = "http";
73
+ private readonly endpoint;
74
+ private readonly timeoutMs;
75
+ private readonly fetchFn;
76
+ constructor(endpoint: string, options?: HttpRouterOptions);
77
+ dispatch(text: string): Promise<DispatchReceipt>;
78
+ }
79
+ interface CostEntry {
80
+ kind: string;
81
+ adapter: string;
82
+ units: number;
83
+ at: string;
84
+ }
85
+ interface CostReport {
86
+ entries: CostEntry[];
87
+ dispatches: number;
88
+ units: number;
89
+ }
90
+ declare function recordCost(entry: {
91
+ kind: string;
92
+ adapter: string;
93
+ units: number;
94
+ }): void;
95
+ declare function getCostReport(): CostReport;
96
+ declare function resetCosts(): void;
97
+ interface DispatchOptions {
98
+ adapter?: RouterAdapter;
99
+ guards?: Guards;
100
+ logger?: Logger;
101
+ dryRun?: boolean;
102
+ }
103
+ interface DispatchResult {
104
+ dryRun: boolean;
105
+ adapter: string;
106
+ chars: number;
107
+ receipt?: DispatchReceipt;
108
+ }
109
+ declare function createDryRunResult(text: string, adapterName: string): DispatchResult;
110
+ declare function dispatchText(text: string, options?: DispatchOptions): Promise<DispatchResult>;
111
+ interface TopWord {
112
+ word: string;
113
+ count: number;
114
+ }
115
+ interface TextSummary {
116
+ chars: number;
117
+ words: number;
118
+ lines: number;
119
+ topWords: TopWord[];
120
+ }
121
+ interface SummarizeOptions {
122
+ topN?: number;
123
+ }
124
+ declare function summarizeText(text: string, options?: SummarizeOptions): TextSummary;
125
+
126
+ export { type BrandConfig as B, type CapsConfig as C, type DispatchOptions as D, type Guards as G, HttpRouterAdapter as H, type Logger as L, type QuietHoursConfig as Q, type RouterAdapter as R, type SummarizeOptions as S, type TextSummary as T, VendorError as V, type CostEntry as a, type CostReport as b, type DispatchReceipt as c, type DispatchResult as d, GuardError as e, type GuardsConfig as f, type HttpRouterOptions as g, LocalRouterAdapter as h, type LogLevel as i, type LoggerOptions as j, type TopWord as k, createDryRunResult as l, createGuards as m, createLogger as n, defineBrand as o, dispatchText as p, getCostReport as q, recordCost as r, resetCosts as s, summarizeText as t };
@@ -0,0 +1,8 @@
1
+ import { B as BrandConfig } from './core-gVNKa11w.js';
2
+ export { C as CapsConfig, a as CostEntry, b as CostReport, D as DispatchOptions, c as DispatchReceipt, d as DispatchResult, e as GuardError, G as Guards, f as GuardsConfig, H as HttpRouterAdapter, g as HttpRouterOptions, h as LocalRouterAdapter, i as LogLevel, L as Logger, j as LoggerOptions, Q as QuietHoursConfig, R as RouterAdapter, S as SummarizeOptions, T as TextSummary, k as TopWord, V as VendorError, l as createDryRunResult, m as createGuards, n as createLogger, o as defineBrand, p as dispatchText, q as getCostReport, r as recordCost, s as resetCosts, t as summarizeText } from './core-gVNKa11w.js';
3
+
4
+ declare const VERSION: string;
5
+
6
+ declare const DEFAULT_BRAND: BrandConfig;
7
+
8
+ export { BrandConfig, DEFAULT_BRAND, VERSION };
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import {
2
+ DEFAULT_BRAND
3
+ } from "./chunk-QWFNPAA4.js";
4
+ import {
5
+ GuardError,
6
+ HttpRouterAdapter,
7
+ LocalRouterAdapter,
8
+ VERSION,
9
+ VendorError,
10
+ createDryRunResult,
11
+ createGuards,
12
+ createLogger,
13
+ defineBrand,
14
+ dispatchText,
15
+ getCostReport,
16
+ recordCost,
17
+ resetCosts,
18
+ summarizeText
19
+ } from "./chunk-USJ2R2T2.js";
20
+ export {
21
+ DEFAULT_BRAND,
22
+ GuardError,
23
+ HttpRouterAdapter,
24
+ LocalRouterAdapter,
25
+ VERSION,
26
+ VendorError,
27
+ createDryRunResult,
28
+ createGuards,
29
+ createLogger,
30
+ defineBrand,
31
+ dispatchText,
32
+ getCostReport,
33
+ recordCost,
34
+ resetCosts,
35
+ summarizeText
36
+ };
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ startMcp
4
+ } from "./chunk-FYTHYRXT.js";
5
+ import "./chunk-QWFNPAA4.js";
6
+ import "./chunk-USJ2R2T2.js";
7
+
8
+ // src/mcp-bin.ts
9
+ startMcp().catch((error) => {
10
+ console.error(error instanceof Error ? error.message : String(error));
11
+ process.exit(1);
12
+ });
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { R as RouterAdapter, G as Guards, L as Logger } from './core-gVNKa11w.js';
3
+
4
+ interface McpDeps {
5
+ router?: RouterAdapter;
6
+ guards?: Guards;
7
+ logger?: Logger;
8
+ }
9
+ declare function createMcpServer(deps?: McpDeps): McpServer;
10
+ declare function startMcp(deps?: McpDeps): Promise<void>;
11
+
12
+ export { type McpDeps, createMcpServer, startMcp };
package/dist/mcp.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ createMcpServer,
3
+ startMcp
4
+ } from "./chunk-FYTHYRXT.js";
5
+ import "./chunk-QWFNPAA4.js";
6
+ import "./chunk-USJ2R2T2.js";
7
+ export {
8
+ createMcpServer,
9
+ startMcp
10
+ };
@@ -0,0 +1,8 @@
1
+ interface WorkerEnv {
2
+ PACK_NAME?: string;
3
+ }
4
+ declare const _default: {
5
+ fetch(request: Request, env: WorkerEnv): Promise<Response>;
6
+ };
7
+
8
+ export { type WorkerEnv, _default as default };
package/dist/worker.js ADDED
@@ -0,0 +1,40 @@
1
+ import {
2
+ VERSION,
3
+ summarizeText
4
+ } from "./chunk-USJ2R2T2.js";
5
+
6
+ // src/worker.ts
7
+ function json(value, status = 200) {
8
+ return new Response(JSON.stringify(value), {
9
+ status,
10
+ headers: { "content-type": "application/json" }
11
+ });
12
+ }
13
+ var worker_default = {
14
+ async fetch(request, env) {
15
+ const url = new URL(request.url);
16
+ if (request.method === "GET" && url.pathname === "/health") {
17
+ return json({ ok: true, pack: env.PACK_NAME ?? "agentic-pack", version: VERSION });
18
+ }
19
+ if (request.method === "POST" && url.pathname === "/summarize") {
20
+ let body;
21
+ try {
22
+ body = await request.json();
23
+ } catch {
24
+ return json({ error: "body must be JSON" }, 400);
25
+ }
26
+ if (typeof body !== "object" || body === null || !("text" in body)) {
27
+ return json({ error: "body needs a text string" }, 400);
28
+ }
29
+ const { text } = body;
30
+ if (typeof text !== "string") {
31
+ return json({ error: "body needs a text string" }, 400);
32
+ }
33
+ return json(summarizeText(text));
34
+ }
35
+ return json({ error: "not found" }, 404);
36
+ }
37
+ };
38
+ export {
39
+ worker_default as default
40
+ };
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "agentic-scaffold",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "TypeScript scaffold for a Node.js library, CLI, and MCP server with Zod schemas, text statistics, routing adapters, and dispatch guards.",
5
+ "keywords": [
6
+ "typescript",
7
+ "Node.js",
8
+ "cli",
9
+ "mcp",
10
+ "Model Context Protocol",
11
+ "Zod",
12
+ "scaffold",
13
+ "starter",
14
+ "sdk",
15
+ "text-statistics",
16
+ "http",
17
+ "dispatch",
18
+ "guards"
19
+ ],
20
+ "license": "MIT",
21
+ "author": "Pooria Arab",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/pooriaarab/agentic-scaffold.git"
25
+ },
26
+ "type": "module",
27
+ "private": false,
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "mcpName": "io.github.pooriaarab/agentic-scaffold",
38
+ "main": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.js"
44
+ }
45
+ },
46
+ "bin": {
47
+ "agentic-scaffold": "./dist/cli.js",
48
+ "agentic-scaffold-mcp": "./dist/mcp-bin.js"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "typecheck": "tsc --noEmit",
53
+ "test": "vitest run",
54
+ "clean": "rm -rf dist"
55
+ },
56
+ "dependencies": {
57
+ "@modelcontextprotocol/sdk": "^1.12.0",
58
+ "zod": "^3.25.0"
59
+ },
60
+ "devDependencies": {
61
+ "@types/node": "^22.0.0",
62
+ "tsup": "^8.0.0",
63
+ "typescript": "^5.6.0",
64
+ "vitest": "^3.0.0"
65
+ }
66
+ }