-
Notifications
You must be signed in to change notification settings - Fork 3
fix(core): static-import gray-matter, ajv-formats, schema.json (v1.5.1) #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,32 +5,23 @@ | |
| // ValidateFunction for runtime validation of LogicSpec objects. | ||
| // ============================================================================= | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
| import { createRequire } from "node:module"; | ||
| import { dirname, join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { Ajv, type ValidateFunction } from "ajv"; | ||
| import addFormatsMod from "ajv-formats"; | ||
| import schemaJson from "./schema.json" with { type: "json" }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
rg -n \
--glob 'package.json' \
--glob '*.yml' \
--glob '*.yaml' \
--glob '.nvmrc' \
--glob '.node-version' \
--glob '.tool-versions' \
'"type"|"engines"|node-version|NODE_VERSION|bun' .
rg -n 'schema\.json|with \{ type: "json" \}' packages/coreRepository: SingularityAI-Dev/logic-md Length of output: 1279 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '--- package engines ---\n'
python3 - <<'PY'
import json, pathlib
for p in sorted(pathlib.Path('.').rglob('package.json')):
if any(s in p.parts for s in ('node_modules', '.git')):
continue
try:
data=json.loads(p.read_text())
except Exception as e:
continue
fields={k:data.get(k) for k in ('type','engines') if k in data}
if fields:
print(f'{p}: {fields}')
PY
printf '\n--- core package metadata relevant to engines/typescript/bundlers ---\n'
sed -n '1,120p' packages/core/package.json
printf '\n--- TypeScript configs ---\n'
for f in package.json tsconfig.json packages/*/tsconfig.json; do
[ -f "$f" ] && { echo "===== $f ====="; sed -n '1,160p' "$f"; }
done
printf '\n--- CI/workflow node versions and package manager hints ---\n'
rg -n --glob '*.yml' --glob '*.yaml' --glob 'package-lock.json' --glob 'pnpm-lock.yaml' --glob 'bun.lockb' --glob 'bun.lock' 'node:|node-version|npm|pnpm|corepack|bun|engines|types' .github package.json packages/core/package.json packages/cli/package.json packages/mcp/package.json || true
printf '\n--- Read packages/core/schema.ts relevant lines ---\n'
sed -n '1,80p' packages/core/schema.ts
printf '\n--- static check: JSON import attribute usage ---\n'
python3 - <<'PY'
from pathlib import Path
for p in Path('.').rglob('*.ts'):
if not p.match('*schema.ts'):
continue
s=p.read_text()
if 'with { type: "json" }' in s or "with { type: 'json' }" in s:
print(p)
PYRepository: SingularityAI-Dev/logic-md Length of output: 255 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- package engines ---'
python3 - <<'PY'
import json, pathlib
for p in sorted(pathlib.Path('.').rglob('package.json')):
if any(s in p.parts for s in ('node_modules', '.git')):
continue
try:
data=json.loads(p.read_text())
except Exception as e:
continue
fields={k:data.get(k) for k in ('type','engines') if k in data}
if fields:
print(f"{p}: {fields}")
PY
printf '%s\n' ''
printf '%s\n' '--- core package metadata relevant to engines/typescript/bundlers ---'
sed -n '1,120p' packages/core/package.json
printf '%s\n' ''
printf '%s\n' '--- TypeScript configs ---'
for f in package.json tsconfig.json packages/*/tsconfig.json; do
if [ -f "$f" ]; then
echo "===== $f ====="
sed -n '1,160p' "$f"
fi
done
printf '%s\n' ''
printf '%s\n' '--- CI/workflow node versions and package manager hints ---'
rg -n --glob '*.yml' --glob '*.yaml' --glob 'package-lock.json' --glob 'pnpm-lock.yaml' --glob 'bun.lockb' --glob 'bun.lock' 'node:|node-version|npm|pnpm|corepack|bun|engines|types' .github package.json packages/core/package.json packages/cli/package.json packages/mcp/package.json || true
printf '%s\n' ''
printf '%s\n' '--- Read packages/core/schema.ts relevant lines ---'
sed -n '1,80p' packages/core/schema.ts
printf '%s\n' ''
printf '%s\n' '--- static check: JSON import attribute usage ---'
python3 - <<'PY'
from pathlib import Path
for p in Path('.').rglob('*.ts'):
if not p.name.endswith('schema.ts'):
continue
s=p.read_text()
if 'with { type: "json" }' in s or "with { type: 'json' }" in s:
print(p)
PYRepository: SingularityAI-Dev/logic-md Length of output: 8005 Raise the
🤖 Prompt for AI AgentsSource: MCP tools |
||
| import type { LogicSpec } from "./types.js"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
| // ajv-formats is a CJS module with `export default` that doesn't resolve | ||
| // correctly under verbatimModuleSyntax + nodenext. Use createRequire instead. | ||
| const addFormats = require("ajv-formats") as { | ||
| default: (ajv: Ajv) => Ajv; | ||
| }; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| // ajv-formats is CJS; unwrap the interop default so this works under both | ||
| // Node ESM and single-file bundlers. | ||
| const addFormats = ((addFormatsMod as { default?: unknown }).default ?? addFormatsMod) as ( | ||
| ajv: Ajv, | ||
| ) => Ajv; | ||
|
|
||
| /** | ||
| * Reads and parses the embedded JSON Schema from disk. | ||
| * Uses `import.meta.url` for path resolution so it works regardless | ||
| * of the caller's working directory. | ||
| * Returns the embedded JSON Schema (statically imported so it survives | ||
| * bundling into single-file executables). | ||
| */ | ||
| export function getSchema(): Record<string, unknown> { | ||
| const schemaPath = join(__dirname, "schema.json"); | ||
| const raw = readFileSync(schemaPath, "utf8"); | ||
| return JSON.parse(raw) as Record<string, unknown>; | ||
| return structuredClone(schemaJson) as Record<string, unknown>; | ||
| } | ||
|
|
||
| /** Cached validator instance (module-level singleton) */ | ||
|
|
@@ -52,8 +43,7 @@ export function createValidator(): ValidateFunction<LogicSpec> { | |
| } | ||
|
|
||
| const ajv = new Ajv({ allErrors: true, strict: true }); | ||
| const applyFormats = addFormats.default ?? addFormats; | ||
| (applyFormats as (ajv: Ajv) => Ajv)(ajv); | ||
| addFormats(ajv); | ||
|
|
||
| const schema = getSchema(); | ||
| cachedValidator = ajv.compile<LogicSpec>(schema); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Prune the changelog to the required 20-entry rolling window.
The file now contains substantially more than 20 notable entries, so adding
[1.5.1]without removing older entries violates the repository’s changelog policy. Retain the latest 20 entries and move older history to git history or a separate archive.As per coding guidelines,
CHANGELOG.mdmaintains a rolling log of the last 20 entries.🤖 Prompt for AI Agents
Source: Coding guidelines