Skip to content

feat: add construct-runtime.ts shared utility and script conventions#9

Merged
zkSoju merged 1 commit intomainfrom
feat/construct-runtime-utility
Mar 14, 2026
Merged

feat: add construct-runtime.ts shared utility and script conventions#9
zkSoju merged 1 commit intomainfrom
feat/construct-runtime-utility

Conversation

@zkSoju
Copy link
Copy Markdown
Contributor

@zkSoju zkSoju commented Mar 14, 2026

Summary

  • Ships scripts/lib/construct-runtime.ts — zero-dependency shared utility for construct scripts
  • Updates CONTRIBUTING.md with "Adding Scripts" section documenting the Nakamoto protocol
  • Updates scripts/install.sh with credential check template and CONSTRUCT_DIR setup

What's in construct-runtime.ts

Extracted from construct-k-hole/scripts/dig-search.ts (the reference implementation that runs in production across 4 consumer repos).

Export Purpose
loadEnvFile(startDir) Walk-up .env loader — handles pack installs 5+ levels deep
resolveCredential(...names) Cascade: process.env → .env → ~/.loa/credentials.json
resolveOutputDir(scriptDir, slug) Pack-aware output dir with slug traversal validation
progress(tag, msg) [tag] msg to stderr
output(data) JSON to stdout via writeSync (call once at exit)
fatal(error, extra?) JSON error to stdout + exit(1)

Zero external dependencies. Node.js stdlib only.

Why

Every construct that ships scripts was reimplementing .env loading and output routing independently. K-hole had identical loadEnv() in two scripts that drifted when one was fixed and the other wasn't — causing credential failures in downstream consumers. This utility prevents that class of bug for all future constructs.

Related

Test plan

  • npx tsx --eval "import './scripts/lib/construct-runtime.ts'" compiles cleanly
  • New construct created from template includes scripts/lib/construct-runtime.ts
  • CONTRIBUTING.md renders correctly on GitHub

🤖 Generated with Claude Code

Ships scripts/lib/construct-runtime.ts — zero-dependency shared utility
for credential cascade, pack-aware output dirs, and Nakamoto stdout/stderr
separation. Extracted from construct-k-hole dig-search.ts (the canonical
reference implementation).

Updates:
- CONTRIBUTING.md: new "Adding Scripts" section with Nakamoto protocol docs
- install.sh: template with credential check pattern and CONSTRUCT_DIR

Closes #8

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zkSoju zkSoju requested a review from janitooor March 14, 2026 21:05
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@zkSoju zkSoju merged commit 6e0ea12 into main Mar 14, 2026
6 of 8 checks passed
@zkSoju zkSoju deleted the feat/construct-runtime-utility branch March 14, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: ship construct-runtime.ts in template

1 participant