agentic-scaffold 0.0.0-stage → 0.1.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 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,108 @@
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
+ Canonical scaffold for a CLI plus library plus MCP server pack.
4
+
5
+ Clone this repo to start a new pack. It gives one core with three
6
+ faces: a terminal command, an npm import, and an MCP server.
7
+
8
+ ## What you get
9
+
10
+ - One core: brand config, logs, guards, routing, dry run, cost reports.
11
+ - Three faces over that core: CLI, library, MCP server.
12
+ - A frozen core contract, so packs share one API.
13
+ - A worker entry and a wrangler sample for edge deploys.
14
+ - Build, typecheck, and tests that pass from a fresh clone.
15
+
16
+ ## Quick start
17
+
18
+ ```sh
19
+ git clone https://github.com/pooriaarab/agentic-scaffold.git my-pack
20
+ cd my-pack
21
+ npm install
22
+ npm run build
23
+ npm run typecheck
24
+ npm test
25
+ ```
26
+
27
+ Run the command:
28
+
29
+ ```sh
30
+ node dist/cli.js summary --text "hello world hello"
31
+ ```
32
+
33
+ Call the library:
34
+
35
+ ```js
36
+ import { summarizeText } from "./dist/index.js";
37
+
38
+ console.log(summarizeText("hello world hello"));
39
+ ```
40
+
41
+ Start the MCP server:
42
+
43
+ ```sh
44
+ node dist/cli.js mcp
45
+ ```
46
+
47
+ ## Three usecases
48
+
49
+ 1. You run one text summary from the terminal.
50
+ 2. You import the summary function in a script.
51
+ 3. You let an agent call the same function as an MCP tool.
52
+
53
+ ## Clone checklist
54
+
55
+ This repo is a template. Replace each slot in each file that holds it.
56
+
57
+ - `__PACK_NAME__`: the directory name, like `my-pack`.
58
+ - `__NPM_NAME__`: the npm name, like `agentic-<block>` (bare name, never @pooriaarab/ scoped unless the brief says scoped).
59
+ - `__PACK_COMMAND__`: the terminal command, like `my-pack`.
60
+ - `__PACK_DESCRIPTION__`: one plain sentence, under 100 chars.
61
+ - `__PACK_KEYWORDS__`: plain keywords, like `notes, search, cli`.
62
+ - `__GITHUB_USER__`: the repo owner, like `pooriaarab`.
63
+
64
+ Slot files: `AGENTS.md`, `SKILL.md`, `RULES.md`, `llms.txt`,
65
+ `server.json`, `.mcp.json`, `wrangler.jsonc`.
66
+
67
+ Then rename the scaffold identity itself:
68
+
69
+ - `package.json`: name, bin commands, mcpName. Remove `"private": true`.
70
+ - `src/index.ts`: the `DEFAULT_BRAND` fields.
71
+ - This file: the pitch and the examples above.
72
+
73
+ At publish time, set `server.json` version to the npm version and
74
+ `server.json` repository id from `gh api repos/OWNER/REPO --jq .id`.
75
+
76
+ ## Gates
77
+
78
+ Run all three before you push a pack:
79
+
80
+ ```sh
81
+ npm run build && npm run typecheck && npm test
82
+ ```
83
+
84
+ Then run the real installed CLI once from a tarball:
85
+
86
+ ```sh
87
+ npm pack
88
+ npx --yes --package ./pooriaarab-agentic-scaffold-0.1.0.tgz agentic-pack summary --text "hello"
89
+ ```
90
+
91
+ ## Release flow
92
+
93
+ Push to `main` for review. Merge to `release` to publish. The
94
+ publish workflow ships only when the version is new.
95
+
96
+ ## Layout
97
+
98
+ - `src/index.ts`: the library face.
99
+ - `src/cli.ts`: the terminal face.
100
+ - `src/mcp.ts`: the MCP server. `src/mcp-bin.ts` starts it.
101
+ - `src/worker.ts`: the edge worker face.
102
+ - `src/core.ts`: the shared core.
103
+ - `agentic-core.d.ts`: the frozen contract.
104
+ - `docs/agentic-core.md`: the contract in plain words.
105
+
106
+ ## License
107
+
108
+ MIT. See `LICENSE`.
@@ -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.1" : 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
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ VERSION,
3
+ defineBrand
4
+ } from "./chunk-E72J53UI.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,91 @@
1
+ import {
2
+ DEFAULT_BRAND
3
+ } from "./chunk-P7R4J6SZ.js";
4
+ import {
5
+ GuardError,
6
+ LocalRouterAdapter,
7
+ VendorError,
8
+ createLogger,
9
+ dispatchText,
10
+ getCostReport,
11
+ summarizeText
12
+ } from "./chunk-E72J53UI.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
+ };
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-P7R4J6SZ.js";
5
+ import {
6
+ GuardError,
7
+ LocalRouterAdapter,
8
+ VERSION,
9
+ VendorError,
10
+ dispatchText,
11
+ getCostReport,
12
+ summarizeText
13
+ } from "./chunk-E72J53UI.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-P7R4J6SZ.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-E72J53UI.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-USTEVUWE.js";
5
+ import "./chunk-P7R4J6SZ.js";
6
+ import "./chunk-E72J53UI.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-USTEVUWE.js";
5
+ import "./chunk-P7R4J6SZ.js";
6
+ import "./chunk-E72J53UI.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-E72J53UI.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,58 @@
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.1",
4
+ "description": "Canonical scaffold for a CLI plus library plus MCP server pack.",
5
+ "keywords": [
6
+ "cli",
7
+ "mcp",
8
+ "scaffold",
9
+ "starter",
10
+ "typescript"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Pooria Arab",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/pooriaarab/agentic-scaffold.git"
17
+ },
18
+ "type": "module",
19
+ "private": false,
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "mcpName": "io.github.pooriaarab/agentic-scaffold",
30
+ "main": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ }
37
+ },
38
+ "bin": {
39
+ "agentic-scaffold": "./dist/cli.js",
40
+ "agentic-scaffold-mcp": "./dist/mcp-bin.js"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "vitest run",
46
+ "clean": "rm -rf dist"
47
+ },
48
+ "dependencies": {
49
+ "@modelcontextprotocol/sdk": "^1.12.0",
50
+ "zod": "^3.25.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^22.0.0",
54
+ "tsup": "^8.0.0",
55
+ "typescript": "^5.6.0",
56
+ "vitest": "^3.0.0"
57
+ }
58
+ }