agentic-scaffold 0.1.1 → 0.1.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are in this file. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## 0.1.3 - 2026-10-29
8
+
9
+ ### Removed
10
+
11
+ - The Worker route `POST /summarize` is gone. Use `POST /api/v1/summarize` instead.
12
+ The new route needs a bearer key. See the migration section in the
13
+ [README](README.md#migration-worker-auth).
14
+
15
+ ### Security
16
+
17
+ - The `zod` dependency is `^4.6.7`. zod 3.25.76 was below the fixed version for
18
+ GHSA-mrhx-c7xc-m3w5, which allows memory exhaustion when validating oversized
19
+ constrained collections. The package API is unchanged.
20
+ - `POST /api/v1/summarize` requires a bearer key with the `text:read` scope. A missing
21
+ key gets 401, a missing scope gets 403, and a Worker with no `AUTH_TOKENS` secret gets
22
+ 503. Before, the route had no auth.
23
+
24
+ ### Fixed
25
+
26
+ - The deployed Worker builds its Auth from the `AUTH_TOKENS` string secret. Before, a
27
+ Cloudflare binding could not hold an Auth object, so a deployed Worker always answered
28
+ 503. The `AUTH` env field stays as a test seam.
29
+ - `mcp --help`, `-h`, `--version` and `-V` print and exit 0 for the cli and the mcp bin,
30
+ without starting the server.
31
+
32
+ ### Changed
33
+
34
+ - The publish workflow runs one publish at a time for each ref, so two runs cannot
35
+ publish at once.
36
+ - The publish workflow also publishes to ants.land. It skips a version that is already
37
+ there.
38
+ - The repository has a CI workflow (Node 22: typecheck, test, build) and a `ci:local`
39
+ script.
package/README.md CHANGED
@@ -1,108 +1,78 @@
1
- # Agentic scaffold
1
+ # agentic-scaffold
2
2
 
3
- Canonical scaffold for a CLI plus library plus MCP server pack.
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)
4
6
 
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
+ [Package](https://www.npmjs.com/package/agentic-scaffold) · [Source](https://github.com/pooriaarab/agentic-scaffold) · [Support](https://github.com/pooriaarab/agentic-scaffold/issues)
7
8
 
8
- ## What you get
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.
9
10
 
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
11
+ ## Install
17
12
 
18
13
  ```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
14
+ npm install agentic-scaffold
25
15
  ```
26
16
 
27
- Run the command:
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.
28
22
 
29
23
  ```sh
30
- node dist/cli.js summary --text "hello world hello"
24
+ npx agentic-scaffold summary --text "hello world hello"
31
25
  ```
32
26
 
33
- Call the library:
27
+ Success prints JSON with `chars: 17`, `words: 3`, `lines: 1`, and `hello` counted twice.
34
28
 
35
29
  ```js
36
- import { summarizeText } from "./dist/index.js";
37
-
30
+ import { summarizeText, getCostReport } from "agentic-scaffold";
38
31
  console.log(summarizeText("hello world hello"));
32
+ console.log(getCostReport()); // { entries: [], dispatches: 0, units: 0 }
39
33
  ```
40
34
 
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.
35
+ ## Features and runtime surfaces
52
36
 
53
- ## Clone checklist
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` (open) and `POST /api/v1/summarize` (needs a bearer key with the `text:read` scope); users deploy it themselves.
54
44
 
55
- This repo is a template. Replace each slot in each file that holds it.
45
+ Start MCP with `npx agentic-scaffold mcp`. Preview routing with `npx agentic-scaffold dispatch --text hello --dry-run`.
56
46
 
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`.
47
+ ## Migration: Worker auth
63
48
 
64
- Slot files: `AGENTS.md`, `SKILL.md`, `RULES.md`, `llms.txt`,
65
- `server.json`, `.mcp.json`, `wrangler.jsonc`.
49
+ `POST /summarize` is gone. Use `POST /api/v1/summarize`. It needs `Authorization: Bearer <key>` and a principal with the `text:read` scope. A missing or bad key gets 401. A key without the scope gets 403. Set the `AUTH_TOKENS` secret to a JSON object of bearer token (32 bytes or more) to `kind:name`, or to `{ "as": "kind:name", "scopes": ["text:read"] }`. A bad entry refuses the whole table. If `AUTH_TOKENS` is missing, the route answers 503. `GET /health` stays open.
66
50
 
67
- Then rename the scaffold identity itself:
51
+ ## Limits
68
52
 
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.
53
+ This starter has zero vendor-specific integrations. Local dispatch creates a receipt without external delivery.
54
+ CLI and MCP dispatch use the local adapter by default; SDK callers can supply the HTTP adapter.
55
+ HTTP delivery defaults to a ten-second timeout, with no retries. Cost units count text length rather than billing charges.
56
+ Reports reset when the process exits. CLI help and MCP identity still use the starter name `agentic-pack`.
72
57
 
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:
58
+ ## Customize a cloned starter
79
59
 
80
60
  ```sh
61
+ git clone https://github.com/pooriaarab/agentic-scaffold.git my-pack
62
+ cd my-pack
63
+ npm ci
81
64
  npm run build && npm run typecheck && npm test
65
+ node dist/cli.js summary --text "hello world hello"
82
66
  ```
83
67
 
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
68
+ Replace `__PACK_NAME__`, `__NPM_NAME__`, `__PACK_COMMAND__`, `__PACK_DESCRIPTION__`, `__PACK_KEYWORDS__`, and `__GITHUB_USER__` wherever they appear.
69
+ Check `AGENTS.md`, `SKILL.md`, `RULES.md`, `llms.txt`, `server.json`, `.mcp.json`, and `wrangler.jsonc`.
70
+ Update package identity, bin commands, `mcpName`, and `DEFAULT_BRAND` in `src/index.ts`.
71
+ Set the MCP manifest version and repository ID before publishing your own package.
97
72
 
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.
73
+ The repository includes a shared core contract and a publish workflow. Inspect that workflow before adopting its release process.
74
+ Version 0.1.3 is an early starter release; interfaces can change. See [CHANGELOG.md](CHANGELOG.md).
105
75
 
106
76
  ## License
107
77
 
108
- MIT. See `LICENSE`.
78
+ MIT.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  VERSION,
3
3
  defineBrand
4
- } from "./chunk-E72J53UI.js";
4
+ } from "./chunk-WGT6VR2C.js";
5
5
 
6
6
  // src/index.ts
7
7
  var DEFAULT_BRAND = defineBrand({
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_BRAND
3
- } from "./chunk-P7R4J6SZ.js";
3
+ } from "./chunk-ENKHKKTS.js";
4
4
  import {
5
5
  GuardError,
6
6
  LocalRouterAdapter,
@@ -9,7 +9,7 @@ import {
9
9
  dispatchText,
10
10
  getCostReport,
11
11
  summarizeText
12
- } from "./chunk-E72J53UI.js";
12
+ } from "./chunk-WGT6VR2C.js";
13
13
 
14
14
  // src/mcp.ts
15
15
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -206,7 +206,7 @@ function summarizeText(text, options = {}) {
206
206
 
207
207
  // src/version.ts
208
208
  import { createRequire } from "module";
209
- var VERSION = true ? "0.1.1" : readPackageVersion();
209
+ var VERSION = true ? "0.1.3" : readPackageVersion();
210
210
 
211
211
  export {
212
212
  defineBrand,
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  DEFAULT_BRAND
4
- } from "./chunk-P7R4J6SZ.js";
4
+ } from "./chunk-ENKHKKTS.js";
5
5
  import {
6
6
  GuardError,
7
7
  LocalRouterAdapter,
@@ -10,7 +10,7 @@ import {
10
10
  dispatchText,
11
11
  getCostReport,
12
12
  summarizeText
13
- } from "./chunk-E72J53UI.js";
13
+ } from "./chunk-WGT6VR2C.js";
14
14
 
15
15
  // src/cli.ts
16
16
  import { readFileSync, realpathSync } from "fs";
@@ -36,6 +36,16 @@ function parseArgs(argv) {
36
36
  throw new UsageError(`unknown command "${first}"`);
37
37
  }
38
38
  request.command = first;
39
+ if (first === "mcp" && args.length > 0) {
40
+ if (args[0] === "--help" || args[0] === "-h") {
41
+ request.command = "help";
42
+ return request;
43
+ }
44
+ if (args[0] === "--version" || args[0] === "-V") {
45
+ request.command = "version";
46
+ return request;
47
+ }
48
+ }
39
49
  while (args.length > 0) {
40
50
  const flag = args.shift();
41
51
  if (flag === "--dry-run" && request.command === "dispatch") {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_BRAND
3
- } from "./chunk-P7R4J6SZ.js";
3
+ } from "./chunk-ENKHKKTS.js";
4
4
  import {
5
5
  GuardError,
6
6
  HttpRouterAdapter,
@@ -16,7 +16,7 @@ import {
16
16
  recordCost,
17
17
  resetCosts,
18
18
  summarizeText
19
- } from "./chunk-E72J53UI.js";
19
+ } from "./chunk-WGT6VR2C.js";
20
20
  export {
21
21
  DEFAULT_BRAND,
22
22
  GuardError,
package/dist/mcp-bin.js CHANGED
@@ -1,11 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  startMcp
4
- } from "./chunk-USTEVUWE.js";
5
- import "./chunk-P7R4J6SZ.js";
6
- import "./chunk-E72J53UI.js";
4
+ } from "./chunk-QLQX3SPS.js";
5
+ import {
6
+ DEFAULT_BRAND
7
+ } from "./chunk-ENKHKKTS.js";
8
+ import {
9
+ VERSION
10
+ } from "./chunk-WGT6VR2C.js";
7
11
 
8
12
  // src/mcp-bin.ts
13
+ var flag = process.argv[2];
14
+ if (flag === "--help" || flag === "-h") {
15
+ console.log(`${DEFAULT_BRAND.name} ${VERSION}
16
+ Usage: ${DEFAULT_BRAND.command}-mcp
17
+ Starts the MCP server on stdio.`);
18
+ process.exit(0);
19
+ }
20
+ if (flag === "--version" || flag === "-V") {
21
+ console.log(VERSION);
22
+ process.exit(0);
23
+ }
9
24
  startMcp().catch((error) => {
10
25
  console.error(error instanceof Error ? error.message : String(error));
11
26
  process.exit(1);
package/dist/mcp.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createMcpServer,
3
3
  startMcp
4
- } from "./chunk-USTEVUWE.js";
5
- import "./chunk-P7R4J6SZ.js";
6
- import "./chunk-E72J53UI.js";
4
+ } from "./chunk-QLQX3SPS.js";
5
+ import "./chunk-ENKHKKTS.js";
6
+ import "./chunk-WGT6VR2C.js";
7
7
  export {
8
8
  createMcpServer,
9
9
  startMcp
package/dist/worker.d.ts CHANGED
@@ -1,8 +1,19 @@
1
+ import { Auth } from 'agentic-identity';
2
+
1
3
  interface WorkerEnv {
2
4
  PACK_NAME?: string;
5
+ /**
6
+ * Secret. A JSON object of bearer token to `kind:name` (see `createTokenAuth`).
7
+ * Cloudflare bindings hold strings, so the Worker builds its Auth from this.
8
+ * Without it, protected routes answer 503.
9
+ */
10
+ AUTH_TOKENS?: string;
11
+ /** Test seam: an Auth port that replaces `AUTH_TOKENS`. A Cloudflare binding cannot hold an object. */
12
+ AUTH?: Auth;
3
13
  }
14
+ declare const SUMMARIZE_SCOPE = "text:read";
4
15
  declare const _default: {
5
16
  fetch(request: Request, env: WorkerEnv): Promise<Response>;
6
17
  };
7
18
 
8
- export { type WorkerEnv, _default as default };
19
+ export { SUMMARIZE_SCOPE, type WorkerEnv, _default as default };
package/dist/worker.js CHANGED
@@ -1,9 +1,73 @@
1
1
  import {
2
2
  VERSION,
3
3
  summarizeText
4
- } from "./chunk-E72J53UI.js";
4
+ } from "./chunk-WGT6VR2C.js";
5
5
 
6
6
  // src/worker.ts
7
+ import { requirePrincipal } from "agentic-identity/http";
8
+
9
+ // src/auth.ts
10
+ import { isScope, parsePrincipal } from "agentic-identity";
11
+ var MIN_TOKEN_BYTES = 32;
12
+ var TOKEN_SHAPE = /^[A-Za-z0-9_-]{1,512}$/;
13
+ var DEFAULT_SCOPES = ["text:read"];
14
+ var warned = /* @__PURE__ */ new Set();
15
+ function refuse(reason) {
16
+ if (!warned.has(reason)) {
17
+ warned.add(reason);
18
+ console.error(`AUTH_TOKENS is refused: ${reason}`);
19
+ }
20
+ }
21
+ function same(a, b) {
22
+ let diff = a.length ^ b.length;
23
+ for (let i = 0; i < Math.max(a.length, b.length); i++) diff |= (a.charCodeAt(i) || 0) ^ (b.charCodeAt(i) || 0);
24
+ return diff === 0;
25
+ }
26
+ function contextOf(entry) {
27
+ const object = typeof entry === "object" && entry !== null && !Array.isArray(entry) ? entry : void 0;
28
+ const who = typeof entry === "string" ? entry : object?.as;
29
+ const cut = typeof who === "string" ? who.indexOf(":") : -1;
30
+ if (typeof who !== "string" || cut < 1 || cut === who.length - 1) return void 0;
31
+ const given = object?.scopes;
32
+ if (given !== void 0 && !(Array.isArray(given) && given.every(isScope))) return void 0;
33
+ try {
34
+ const { kind, id } = parsePrincipal({ kind: who.slice(0, cut), id: who.slice(cut + 1) });
35
+ return { principalId: id, kind, chain: [{ id, kind }], scopes: given ?? [...DEFAULT_SCOPES] };
36
+ } catch {
37
+ return void 0;
38
+ }
39
+ }
40
+ function createTokenAuth(raw) {
41
+ let table;
42
+ try {
43
+ const parsed = JSON.parse(raw ?? "");
44
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("not a JSON object");
45
+ table = /* @__PURE__ */ new Map();
46
+ for (const [token, entry] of Object.entries(parsed)) {
47
+ if (new TextEncoder().encode(token).length < MIN_TOKEN_BYTES) throw new Error(`a token is shorter than ${MIN_TOKEN_BYTES} bytes`);
48
+ if (!TOKEN_SHAPE.test(token)) throw new Error("a token holds a character outside A-Z a-z 0-9 _ - or is over 512 bytes");
49
+ const context = contextOf(entry);
50
+ if (!context) throw new Error("an entry is not a valid kind:name or { as, scopes }");
51
+ table.set(token, context);
52
+ }
53
+ } catch (error) {
54
+ table = void 0;
55
+ refuse(error instanceof SyntaxError ? "not valid JSON" : error.message);
56
+ }
57
+ const known = table;
58
+ return {
59
+ async authenticate(request) {
60
+ const bearer = /^Bearer (.+)$/.exec(request.headers.get("authorization") ?? "")?.[1];
61
+ if (bearer === void 0 || !known) return null;
62
+ let found = null;
63
+ for (const [token, context] of known) if (same(token, bearer)) found = context;
64
+ return found;
65
+ }
66
+ };
67
+ }
68
+
69
+ // src/worker.ts
70
+ var SUMMARIZE_SCOPE = "text:read";
7
71
  function json(value, status = 200) {
8
72
  return new Response(JSON.stringify(value), {
9
73
  status,
@@ -16,7 +80,15 @@ var worker_default = {
16
80
  if (request.method === "GET" && url.pathname === "/health") {
17
81
  return json({ ok: true, pack: env.PACK_NAME ?? "agentic-pack", version: VERSION });
18
82
  }
19
- if (request.method === "POST" && url.pathname === "/summarize") {
83
+ if (request.method === "POST" && url.pathname === "/api/v1/summarize") {
84
+ if (!env.AUTH && !env.AUTH_TOKENS) {
85
+ return json({ error: "auth is not configured" }, 503);
86
+ }
87
+ const auth = env.AUTH ?? createTokenAuth(env.AUTH_TOKENS);
88
+ const principal = await requirePrincipal(request, auth, { scope: SUMMARIZE_SCOPE });
89
+ if (principal instanceof Response) {
90
+ return principal;
91
+ }
20
92
  let body;
21
93
  try {
22
94
  body = await request.json();
@@ -36,5 +108,6 @@ var worker_default = {
36
108
  }
37
109
  };
38
110
  export {
111
+ SUMMARIZE_SCOPE,
39
112
  worker_default as default
40
113
  };
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "agentic-scaffold",
3
- "version": "0.1.1",
4
- "description": "Canonical scaffold for a CLI plus library plus MCP server pack.",
3
+ "version": "0.1.3",
4
+ "description": "TypeScript scaffold for a Node.js library, CLI, and MCP server with Zod schemas, text statistics, routing adapters, and dispatch guards.",
5
5
  "keywords": [
6
+ "typescript",
7
+ "Node.js",
6
8
  "cli",
7
9
  "mcp",
10
+ "Model Context Protocol",
11
+ "Zod",
8
12
  "scaffold",
9
13
  "starter",
10
- "typescript"
14
+ "sdk",
15
+ "text-statistics",
16
+ "http",
17
+ "dispatch",
18
+ "guards"
11
19
  ],
12
20
  "license": "MIT",
13
21
  "author": "Pooria Arab",
@@ -21,7 +29,8 @@
21
29
  "node": ">=18"
22
30
  },
23
31
  "files": [
24
- "dist"
32
+ "dist",
33
+ "CHANGELOG.md"
25
34
  ],
26
35
  "publishConfig": {
27
36
  "access": "public"
@@ -43,11 +52,13 @@
43
52
  "build": "tsup",
44
53
  "typecheck": "tsc --noEmit",
45
54
  "test": "vitest run",
46
- "clean": "rm -rf dist"
55
+ "clean": "rm -rf dist",
56
+ "ci:local": "WRANGLER_SEND_METRICS=false npm run typecheck && npm test && npm run build"
47
57
  },
48
58
  "dependencies": {
49
59
  "@modelcontextprotocol/sdk": "^1.12.0",
50
- "zod": "^3.25.0"
60
+ "agentic-identity": "^0.7.0",
61
+ "zod": "^4.6.7"
51
62
  },
52
63
  "devDependencies": {
53
64
  "@types/node": "^22.0.0",