monkeyshape 0.0.0-stage → 0.1.0

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 clinsky
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,79 @@
1
- # Temporary Holding Version
1
+ # monkeyshape
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
+ Opinionated checks, configs and conventions for humans and coding agents building software
4
+ together on **Bun**, **TypeScript**, **Effect** and **beads**.
5
+
6
+ Agents write a lot of prose and forget most of it. A rule written in `AGENTS.md` works only if
7
+ it is loaded and noticed; a check works every time and costs no context until it fires.
8
+ monkeyshape turns lessons into checks, keeps everything loaded automatically on a budget,
9
+ and treats real-world results as the judge of done.
10
+
11
+ ```console
12
+ $ mshape check
13
+ src/core/cache.ts:1 rules/no-nondeterminism
14
+ reads the wall clock. Use Clock or DateTime.now so tests control time.
15
+
16
+ src/core/client.ts arch/host-access
17
+ imports 'node:fs/promises', but module 'core' has no hostAccess. Reach the host through a service in an adapter module.
18
+
19
+ mshape check failed: 2 problems
20
+ ```
21
+
22
+ ## Install
23
+
24
+ ```sh
25
+ bun add -d monkeyshape effect @biomejs/biome typescript @types/bun
26
+ ```
27
+
28
+ monkeyshape runs on Bun and asks your `tsc` and `biome` which files they cover; `effect` is a
29
+ peer dependency. Add these files (the tests build a repo from exactly these blocks):
30
+
31
+ ```jsonc
32
+ // tsconfig.json
33
+ { "extends": "monkeyshape/tsconfig.base.json", "include": ["src", "test", "shape.config.ts"] }
34
+ ```
35
+
36
+ ```jsonc
37
+ // biome.json
38
+ {
39
+ "root": true,
40
+ "extends": ["monkeyshape/biome"],
41
+ "files": { "includes": ["src/**", "test/**", "shape.config.ts", "*.json"] }
42
+ }
43
+ ```
44
+
45
+ ```ts
46
+ // shape.config.ts
47
+ import { defineConfig } from "monkeyshape";
48
+
49
+ export default defineConfig({
50
+ arch: {
51
+ modules: {
52
+ core: { description: "Deterministic logic. No host I/O." },
53
+ adapters: { description: "Host I/O behind services.", mayImport: ["core"], hostAccess: true },
54
+ },
55
+ },
56
+ });
57
+ ```
58
+
59
+ ```md
60
+ <!-- AGENTS.md -->
61
+ # My project: commands, gotchas and decision authority for agents, in 150 lines or fewer.
62
+ ```
63
+
64
+ Then make it your gate: `tsc && biome ci --error-on-warnings && mshape check && bun test`.
65
+
66
+ ## What `mshape check` enforces
67
+
68
+ | Check | Removes |
69
+ |---|---|
70
+ | `arch` | Layering drift, host access from pure code (common paths, statically; not a sandbox), unvetted packages, import cycles |
71
+ | `rules` | Silent decoding, hidden clocks/env/timers, thrown errors, nested runtimes, spread errors |
72
+ | `refs` | Docs and comments that point at paths, scripts or decisions that don't exist |
73
+ | `budgets` | Bloated `AGENTS.md`, decision logs and memories; oversized files |
74
+ | `coverage` | Code that escaped the typechecker or the linter and rots silently |
75
+
76
+ Existing violations can be grandfathered with `mshape baseline --init`; counts may then only
77
+ go down. Every escape hatch (`// shape-ignore <rule>: <reason>`, config allowances) needs a reason.
78
+
79
+ Early (0.x). What ships and what's next: [docs/roadmap.md](docs/roadmap.md). MIT licensed.
@@ -0,0 +1,71 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
3
+ "root": false,
4
+ "vcs": {
5
+ "enabled": true,
6
+ "clientKind": "git",
7
+ "useIgnoreFile": true
8
+ },
9
+ "formatter": {
10
+ "enabled": true,
11
+ "indentStyle": "space",
12
+ "indentWidth": 2,
13
+ "lineWidth": 100
14
+ },
15
+ "javascript": {
16
+ "formatter": {
17
+ "quoteStyle": "double",
18
+ "semicolons": "always"
19
+ }
20
+ },
21
+ "linter": {
22
+ "enabled": true,
23
+ "rules": {
24
+ "preset": "recommended",
25
+ "correctness": {
26
+ "useImportExtensions": "error"
27
+ },
28
+ "suspicious": {
29
+ "noExplicitAny": "error",
30
+ "noConsole": "error"
31
+ },
32
+ "style": {
33
+ "noNonNullAssertion": "error",
34
+ "noEnum": "error",
35
+ "noNamespace": "error",
36
+ "noParameterAssign": "error",
37
+ "useImportType": "error",
38
+ "useExportType": "error"
39
+ },
40
+ "performance": {
41
+ "noBarrelFile": "error",
42
+ "noReExportAll": "error"
43
+ },
44
+ "nursery": {
45
+ "noFloatingPromises": "error",
46
+ "noMisusedPromises": "error"
47
+ },
48
+ "complexity": {
49
+ "useLiteralKeys": "off"
50
+ }
51
+ }
52
+ },
53
+ "assist": {
54
+ "enabled": true,
55
+ "actions": {
56
+ "source": {
57
+ "organizeImports": "on"
58
+ }
59
+ }
60
+ },
61
+ "overrides": [
62
+ {
63
+ "includes": ["src/api/**"],
64
+ "linter": { "rules": { "performance": { "noBarrelFile": "off" } } }
65
+ },
66
+ {
67
+ "includes": ["src/cli/**", "tools/**", "**/*.test.ts", "**/*.test.tsx"],
68
+ "linter": { "rules": { "suspicious": { "noConsole": "off" } } }
69
+ }
70
+ ]
71
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "lib": ["ESNext"],
6
+ "module": "Preserve",
7
+ "moduleResolution": "bundler",
8
+ "moduleDetection": "force",
9
+ "types": ["bun"],
10
+ "noEmit": true,
11
+ "allowImportingTsExtensions": true,
12
+ "verbatimModuleSyntax": true,
13
+ "erasableSyntaxOnly": true,
14
+ "isolatedModules": true,
15
+ "skipLibCheck": true,
16
+ "forceConsistentCasingInFileNames": true,
17
+
18
+ "strict": true,
19
+ "noUncheckedIndexedAccess": true,
20
+ "exactOptionalPropertyTypes": true,
21
+ "noImplicitOverride": true,
22
+ "noImplicitReturns": true,
23
+ "noFallthroughCasesInSwitch": true,
24
+ "noPropertyAccessFromIndexSignature": true,
25
+ "noUnusedLocals": true,
26
+ "noUnusedParameters": true,
27
+ "noUncheckedSideEffectImports": true,
28
+ "allowUnreachableCode": false,
29
+ "allowUnusedLabels": false
30
+ }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "monkeyshape",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Opinionated checks, configs and conventions for humans and coding agents building together on Bun, TypeScript, Effect and beads.",
5
+ "keywords": [
6
+ "bun",
7
+ "typescript",
8
+ "effect",
9
+ "effect-ts",
10
+ "static-analysis",
11
+ "linter",
12
+ "quality-gate",
13
+ "coding-agents",
14
+ "ai-agents",
15
+ "developer-tools",
16
+ "beads"
17
+ ],
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/clinsky/monkeyshape.git"
22
+ },
23
+ "homepage": "https://github.com/clinsky/monkeyshape#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/clinsky/monkeyshape/issues"
26
+ },
27
+ "type": "module",
28
+ "packageManager": "bun@1.4.2",
29
+ "engines": {
30
+ "bun": ">=1.4.2"
31
+ },
32
+ "bin": {
33
+ "mshape": "./src/cli/main.ts"
34
+ },
35
+ "exports": {
36
+ ".": "./src/api/monkeyshape.ts",
37
+ "./tsconfig.base.json": "./config/tsconfig.base.json",
38
+ "./biome": "./config/biome.base.json"
39
+ },
40
+ "files": [
41
+ "src",
42
+ "config",
43
+ "!src/**/*.test.ts",
44
+ "README.md",
45
+ "LICENSE"
46
+ ],
47
+ "scripts": {
48
+ "typecheck": "tsc -p .",
49
+ "lint": "biome ci --error-on-warnings .",
50
+ "fix": "biome check --write .",
51
+ "shape": "bun src/cli/main.ts check",
52
+ "check": "bun run typecheck && bun run lint && bun run shape && bun test"
53
+ },
54
+ "dependencies": {
55
+ "oxc-parser": "0.156.0"
56
+ },
57
+ "peerDependencies": {
58
+ "effect": "4.0.0"
59
+ },
60
+ "devDependencies": {
61
+ "@biomejs/biome": "2.5.15",
62
+ "@types/bun": "1.4.2",
63
+ "effect": "4.0.0",
64
+ "typescript": "7.0.2"
65
+ }
66
+ }
@@ -0,0 +1,55 @@
1
+ /** `.shape/baseline.json`: grandfathered violation counts per rule and file. */
2
+ import { Effect, Schema } from "effect";
3
+ import type { Counts } from "../core/ratchet.ts";
4
+ import { decodeStrict } from "../helpers/decodeStrict.ts";
5
+ import { WorkspaceError } from "../schemas/errors.ts";
6
+ import { readText } from "./workspace.ts";
7
+
8
+ export const BASELINE_FILE = ".shape/baseline.json";
9
+
10
+ const Baseline = Schema.Struct({
11
+ version: Schema.Literal(1),
12
+ counts: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Int)),
13
+ });
14
+
15
+ export const readBaseline = (root: string) =>
16
+ Effect.gen(function* () {
17
+ if (!(yield* Effect.promise(() => Bun.file(`${root}/${BASELINE_FILE}`).exists())))
18
+ return {} as Counts;
19
+ const text = yield* readText(root, BASELINE_FILE);
20
+ const json = yield* Effect.try({
21
+ try: (): unknown => JSON.parse(text),
22
+ catch: () =>
23
+ new WorkspaceError({ operation: "parse", path: BASELINE_FILE, reason: "not valid JSON" }),
24
+ });
25
+ const baseline = yield* decodeStrict(Baseline)(json).pipe(
26
+ Effect.mapError(
27
+ (error) =>
28
+ new WorkspaceError({ operation: "decode", path: BASELINE_FILE, reason: error.message }),
29
+ ),
30
+ );
31
+ return baseline.counts;
32
+ });
33
+
34
+ const sorted = (counts: Counts): Counts =>
35
+ Object.fromEntries(
36
+ Object.keys(counts)
37
+ .sort()
38
+ .map((rule) => [
39
+ rule,
40
+ Object.fromEntries(
41
+ Object.entries(counts[rule] ?? {}).sort(([a], [b]) => a.localeCompare(b)),
42
+ ),
43
+ ]),
44
+ );
45
+
46
+ export const writeBaseline = (root: string, counts: Counts) =>
47
+ Effect.tryPromise({
48
+ try: () =>
49
+ Bun.write(
50
+ `${root}/${BASELINE_FILE}`,
51
+ `${JSON.stringify({ version: 1, counts: sorted(counts) }, null, 2)}\n`,
52
+ ),
53
+ catch: (cause) =>
54
+ new WorkspaceError({ operation: "write", path: BASELINE_FILE, reason: String(cause) }),
55
+ });
@@ -0,0 +1,25 @@
1
+ /** Loads `shape.config.ts` by importing it, then decodes it strictly. */
2
+ import { Effect } from "effect";
3
+ import { decodeStrict } from "../helpers/decodeStrict.ts";
4
+ import { resolveConfig, ShapeConfig } from "../schemas/config.ts";
5
+ import { ConfigError } from "../schemas/errors.ts";
6
+
7
+ export const CONFIG_FILE = "shape.config.ts";
8
+
9
+ /** `path` overrides the repo's own config, e.g. to try monkeyshape on a repo before adopting it. */
10
+ export const loadConfig = (root: string, path = `${root}/${CONFIG_FILE}`) =>
11
+ Effect.gen(function* () {
12
+ if (!(yield* Effect.promise(() => Bun.file(path).exists())))
13
+ return yield* Effect.fail(
14
+ new ConfigError({ path: CONFIG_FILE, reason: "not found; every adopting repo has one" }),
15
+ );
16
+ const module = yield* Effect.tryPromise({
17
+ try: () => import(path) as Promise<{ readonly default?: unknown }>,
18
+ catch: (cause) =>
19
+ new ConfigError({ path: CONFIG_FILE, reason: `could not load: ${String(cause)}` }),
20
+ });
21
+ const config = yield* decodeStrict(ShapeConfig)(module.default).pipe(
22
+ Effect.mapError((error) => new ConfigError({ path: CONFIG_FILE, reason: error.message })),
23
+ );
24
+ return resolveConfig(config);
25
+ });
@@ -0,0 +1,268 @@
1
+ /** Loads the repo into a `Snapshot`: git's file list, the texts checks read, and what bd, tsc and biome report. */
2
+ import { realpath, stat } from "node:fs/promises";
3
+ import { posix } from "node:path";
4
+ import { Effect } from "effect";
5
+ import { parseJsonc } from "../core/coverage.ts";
6
+ import { type Integration, isTsSource, type Snapshot } from "../core/model.ts";
7
+ import type { ResolvedConfig } from "../schemas/config.ts";
8
+ import { WorkspaceError } from "../schemas/errors.ts";
9
+
10
+ const run = (root: string, command: ReadonlyArray<string>) =>
11
+ Effect.tryPromise({
12
+ try: async () => {
13
+ const child = Bun.spawn([...command], { cwd: root, stdout: "pipe", stderr: "ignore" });
14
+ const stdout = await new Response(child.stdout).text();
15
+ return { stdout, code: await child.exited };
16
+ },
17
+ catch: (cause) =>
18
+ new WorkspaceError({ operation: "run", path: command.join(" "), reason: String(cause) }),
19
+ });
20
+
21
+ /** For optional tools: a spawn failure is an exit code to report, not a reason to abort. */
22
+ const runTool = (root: string, command: ReadonlyArray<string>) =>
23
+ run(root, command).pipe(Effect.orElseSucceed(() => ({ stdout: "", code: -1 })));
24
+
25
+ export const readText = (root: string, path: string) =>
26
+ Effect.tryPromise({
27
+ try: () => Bun.file(`${root}/${path}`).text(),
28
+ catch: (cause) => new WorkspaceError({ operation: "read", path, reason: String(cause) }),
29
+ });
30
+
31
+ /** Files and directories alike: git lists a submodule as one entry, and it is a directory. */
32
+ const exists = (root: string, path: string) =>
33
+ Effect.promise(() =>
34
+ stat(`${root}/${path}`).then(
35
+ () => true,
36
+ () => false,
37
+ ),
38
+ );
39
+
40
+ const listFiles = (root: string) =>
41
+ Effect.gen(function* () {
42
+ const result = yield* run(root, [
43
+ "git",
44
+ "ls-files",
45
+ "--cached",
46
+ "--others",
47
+ "--exclude-standard",
48
+ "-z",
49
+ ]);
50
+ if (result.code !== 0)
51
+ return yield* Effect.fail(
52
+ new WorkspaceError({ operation: "list", path: root, reason: "not a git repository" }),
53
+ );
54
+ // Nested repositories and worktrees show up as a directory entry; they are not ours.
55
+ return result.stdout.split("\0").filter((file) => file !== "" && !file.endsWith("/"));
56
+ });
57
+
58
+ type Loaded<A> = { readonly integration: Integration; readonly value: A | undefined };
59
+
60
+ const failed = <A>(reason: string): Loaded<A> => ({
61
+ integration: { state: "failed", reason },
62
+ value: undefined,
63
+ });
64
+
65
+ const jsonRows = (stdout: string): ReadonlyArray<unknown> | undefined => {
66
+ const parsed = parseJsonc(stdout);
67
+ // `bd list --limit 0 --json` wraps the rows as `{ issues: [...] }`; limited lists are bare.
68
+ const rows =
69
+ typeof parsed === "object" && parsed !== null && "issues" in parsed ? parsed.issues : parsed;
70
+ return Array.isArray(rows) ? rows : undefined;
71
+ };
72
+
73
+ /** bd memories and every bead id. A repo without `.beads` is absent; bd missing is unavailable. */
74
+ const beads = (root: string) =>
75
+ Effect.gen(function* () {
76
+ type Value = { memories: ReadonlyMap<string, string>; ids: ReadonlySet<string> };
77
+ if (!(yield* exists(root, ".beads/config.yaml")))
78
+ return { integration: { state: "absent" }, value: undefined } satisfies Loaded<Value>;
79
+ if (Bun.which("bd") === null)
80
+ return {
81
+ integration: { state: "unavailable", reason: "bd is not on PATH" },
82
+ value: undefined,
83
+ } satisfies Loaded<Value>;
84
+ const memories = yield* runTool(root, ["bd", "memories", "--json"]);
85
+ const parsedMemories = memories.code === 0 ? parseJsonc(memories.stdout) : undefined;
86
+ if (typeof parsedMemories !== "object" || parsedMemories === null)
87
+ return failed<Value>(`\`bd memories --json\` exited ${memories.code} or printed no object`);
88
+ const list = yield* runTool(root, [
89
+ "bd",
90
+ "list",
91
+ "--all",
92
+ "--brief",
93
+ "--skip-labels",
94
+ "--limit",
95
+ "0",
96
+ "--json",
97
+ ]);
98
+ const rows = list.code === 0 ? jsonRows(list.stdout) : undefined;
99
+ if (rows === undefined)
100
+ return failed<Value>(`\`bd list --json\` exited ${list.code} or printed no rows`);
101
+ const value: Value = {
102
+ memories: new Map(
103
+ Object.entries(parsedMemories).filter(
104
+ (entry): entry is [string, string] => typeof entry[1] === "string",
105
+ ),
106
+ ),
107
+ ids: new Set(
108
+ rows.flatMap((issue) =>
109
+ typeof issue === "object" &&
110
+ issue !== null &&
111
+ "id" in issue &&
112
+ typeof issue.id === "string"
113
+ ? [issue.id]
114
+ : [],
115
+ ),
116
+ ),
117
+ };
118
+ return { integration: { state: "ok" }, value } satisfies Loaded<Value>;
119
+ });
120
+
121
+ /**
122
+ * A tool installed in the repo, as a command. Run through the current bun: the bin shims
123
+ * start with `#!/usr/bin/env node`, and a Bun-only machine has no node.
124
+ */
125
+ const localBin = (root: string, name: string) =>
126
+ Effect.map(exists(root, `node_modules/.bin/${name}`), (found) =>
127
+ found ? [process.execPath, `${root}/node_modules/.bin/${name}`] : undefined,
128
+ );
129
+
130
+ /**
131
+ * The tsconfigs a project's references point at. A reference names a tsconfig file or a
132
+ * directory holding `tsconfig.json`; references are not inherited through `extends`, so the
133
+ * file's own JSON is the whole answer. Unreadable files yield none; tsc reports them itself.
134
+ */
135
+ const referencesOf = (root: string, tsconfig: string) =>
136
+ Effect.gen(function* () {
137
+ const text = yield* readText(root, tsconfig).pipe(Effect.orElseSucceed(() => "{}"));
138
+ const parsed = parseJsonc(text);
139
+ const references =
140
+ typeof parsed === "object" && parsed !== null && "references" in parsed
141
+ ? parsed.references
142
+ : undefined;
143
+ if (!Array.isArray(references)) return [];
144
+ const out: Array<string> = [];
145
+ for (const reference of references) {
146
+ if (typeof reference !== "object" || reference === null || !("path" in reference)) continue;
147
+ if (typeof reference.path !== "string") continue;
148
+ const target = posix.normalize(posix.join(posix.dirname(tsconfig), reference.path));
149
+ const isDirectory = yield* Effect.promise(() =>
150
+ stat(`${root}/${target}`).then(
151
+ (info) => info.isDirectory(),
152
+ () => false,
153
+ ),
154
+ );
155
+ out.push(isDirectory ? posix.join(target, "tsconfig.json") : target);
156
+ }
157
+ return out;
158
+ });
159
+
160
+ /**
161
+ * The union of every configured tsconfig's program and, transitively, of every project it
162
+ * references, as tsc itself resolves each one. `tsc -p` checks one project and `--build`
163
+ * won't list files, so the reference graph is walked here, each project once.
164
+ */
165
+ const typechecked = (root: string, realRoot: string, tsconfigs: ReadonlyArray<string>) =>
166
+ Effect.gen(function* () {
167
+ const tsc = yield* localBin(root, "tsc");
168
+ if (tsc === undefined)
169
+ return {
170
+ integration: { state: "unavailable", reason: "typescript is not installed" },
171
+ value: undefined,
172
+ } satisfies Loaded<ReadonlySet<string>>;
173
+ const files = new Set<string>();
174
+ const seen = new Set<string>();
175
+ const queue = tsconfigs.map((tsconfig) => posix.normalize(tsconfig));
176
+ for (let tsconfig = queue.shift(); tsconfig !== undefined; tsconfig = queue.shift()) {
177
+ if (seen.has(tsconfig)) continue;
178
+ seen.add(tsconfig);
179
+ const result = yield* runTool(root, [...tsc, "-p", tsconfig, "--listFilesOnly"]);
180
+ if (result.code !== 0)
181
+ return failed<ReadonlySet<string>>(
182
+ `\`tsc -p ${tsconfig} --listFilesOnly\` exited ${result.code}`,
183
+ );
184
+ for (const line of result.stdout.split("\n"))
185
+ if (line.startsWith(`${realRoot}/`)) files.add(line.slice(realRoot.length + 1));
186
+ queue.push(...(yield* referencesOf(root, tsconfig)));
187
+ }
188
+ return { integration: { state: "ok" }, value: files } satisfies Loaded<ReadonlySet<string>>;
189
+ });
190
+
191
+ /** The files biome processes, from its verbose report, with `extends` and ignores resolved. */
192
+ const linted = (root: string) =>
193
+ Effect.gen(function* () {
194
+ const biome = yield* localBin(root, "biome");
195
+ if (biome === undefined)
196
+ return {
197
+ integration: { state: "unavailable", reason: "@biomejs/biome is not installed" },
198
+ value: undefined,
199
+ } satisfies Loaded<ReadonlySet<string>>;
200
+ const result = yield* runTool(root, [
201
+ ...biome,
202
+ "lint",
203
+ "--verbose",
204
+ "--colors=off",
205
+ "--max-diagnostics=0",
206
+ ".",
207
+ ]);
208
+ const report = result.stdout.split("Files processed:")[1];
209
+ if (report === undefined)
210
+ return failed<ReadonlySet<string>>(
211
+ `\`biome lint --verbose\` printed no "Files processed:" list (exit ${result.code})`,
212
+ );
213
+ const files = new Set(
214
+ report.split("\n").flatMap((line) => {
215
+ const match = /^\s+- (.+)$/.exec(line);
216
+ return match?.[1] === undefined ? [] : [match[1].trim()];
217
+ }),
218
+ );
219
+ return { integration: { state: "ok" }, value: files } satisfies Loaded<ReadonlySet<string>>;
220
+ });
221
+
222
+ export const loadSnapshot = (root: string, config: ResolvedConfig) =>
223
+ Effect.gen(function* () {
224
+ const listed = yield* listFiles(root);
225
+ // A file deleted but not yet staged is still listed; it isn't part of the repo now.
226
+ const found = yield* Effect.forEach(listed, (file) => exists(root, file), { concurrency: 32 });
227
+ const present = listed.filter((_, i) => found[i] === true);
228
+ const configs = new Set([...config.coverage.tsconfigs, config.coverage.biome, "package.json"]);
229
+ const wanted = present.filter(
230
+ (file) => isTsSource(file) || file.endsWith(".md") || configs.has(file),
231
+ );
232
+ const texts = new Map(
233
+ yield* Effect.forEach(
234
+ wanted,
235
+ (file) => Effect.map(readText(root, file), (text) => [file, text] as const),
236
+ {
237
+ concurrency: 32,
238
+ },
239
+ ),
240
+ );
241
+ const manifest = parseJsonc(texts.get("package.json") ?? "{}");
242
+ const scripts =
243
+ typeof manifest === "object" &&
244
+ manifest !== null &&
245
+ "scripts" in manifest &&
246
+ typeof manifest.scripts === "object"
247
+ ? Object.keys(manifest.scripts ?? {})
248
+ : [];
249
+ const realRoot = yield* Effect.promise(() => realpath(root));
250
+ const loadedBeads = yield* beads(root);
251
+ const loadedTsc = yield* typechecked(root, realRoot, config.coverage.tsconfigs);
252
+ const loadedBiome = yield* linted(root);
253
+ const snapshot: Snapshot = {
254
+ files: present,
255
+ texts,
256
+ packageScripts: new Set(scripts),
257
+ memories: loadedBeads.value?.memories,
258
+ beadIds: loadedBeads.value?.ids,
259
+ typechecked: loadedTsc.value,
260
+ linted: loadedBiome.value,
261
+ integrations: {
262
+ beads: loadedBeads.integration,
263
+ tsc: loadedTsc.integration,
264
+ biome: loadedBiome.integration,
265
+ },
266
+ };
267
+ return snapshot;
268
+ });
@@ -0,0 +1,8 @@
1
+ /** The public surface: what an adopter imports from `monkeyshape`. */
2
+ import type { ShapeConfig } from "../schemas/config.ts";
3
+
4
+ export { decodeStrict } from "../helpers/decodeStrict.ts";
5
+ export type { Allowance, ModuleRule, ShapeConfig } from "../schemas/config.ts";
6
+
7
+ /** Identity, for type-checking `shape.config.ts`: `export default defineConfig({ ... })`. */
8
+ export const defineConfig = (config: ShapeConfig): ShapeConfig => config;