Skip to content

Release 0.0.0 - #14

Merged
heitorsDev merged 36 commits into
mainfrom
release/0.0.0
Aug 9, 2026
Merged

heitorsDev merged 36 commits into
mainfrom
release/0.0.0

Conversation

@heitorsDev

Copy link
Copy Markdown
Owner

Integration branch per ADR 0006 — merges the full v0.0.0 scope (issues #2-#7)
from release/0.0.0 into main.

Merging this PR is itself the live trigger for #7's release-automation
workflow: it will tag v0.0.0 and create a GitHub Release named 0.0.0.

Contents

ADRs 0001-0007 in docs/adr/ document the architecture decisions behind
all of the above.

heitorsDev and others added 30 commits August 8, 2026 16:25
…sponse

TDD seam 1 (issue #2): valid unexpired credentials + mocked usage-endpoint
200 response -> exact expected {session, weekly}. Fixes node --test glob
resolution in the npm script along the way (bare `test/` dir arg didn't
resolve as a module path).
TDD seam 2 (issue #2): fail-open, never throws.
TDD seam 4 (issue #2): ADR 0003's read-only/never-refresh contract as an
observable behavior — zero fetch calls, not an internal-call assertion.
…ROFILE%

TDD seam 6 (issue #2): getUsage() now takes an optional path override,
defaulting to resolveCredentialsPath() (win32 vs POSIX). Switched fs import
to the default export so node:test's mock.method can redefine
readFileSync — the ESM namespace's named-export properties are
non-configurable and can't be mocked directly.
Endpoint URL, headers, credentials path segments now named constants —
easier to adapt for a different user-agent/profile shape later without
touching usage.js logic.
service.js: low-level ops (path resolution, credentials read, network
fetch, response-window parsing). controller.js: getUsage orchestration —
the same public seam tests already exercise. No behavior change, just
splitting the one large file.
…aw-string fouls

Vendor-namespaced file replaces src/usage/constants.js — sets up for
other vendors later without mixing formats. Also caught two spots that
skipped the same standard: service.js read the credentials-file key as
inline .claudeAiOauth, and controller.js read the usage-response fields
as inline body.five_hour/body.seven_day. Both now go through named
constants (OAUTH_CREDENTIALS_KEY, USAGE_FIELD_SESSION/WEEKLY) alongside
the endpoint/header constants already extracted.
…vice orchestrates

controller.js: fetchUsage only, the network-IO adapter.
service.js: resolveCredentialsPath, readCredentials, isExpired,
parseWindow, and getUsage — the orchestrating public seam, now calling
into controller.fetchUsage. Public interface tests hit moved from
usage/controller.js to usage/service.js accordingly.
Embedded Anthropic usage fetch (read-only)
…nalContext

TDD seam 1 (issue #3): known-good getUsage() response -> stdout is the
exact expected hookSpecificOutput.additionalContext with both percentages.
handleUserPromptSubmit imports getUsage from usage/service.js only, per
ADR 0007. Also fixes npm test to use node --test's own recursive
discovery (bare 'test/**/*.test.js' glob doesn't expand across
subdirectories under a non-globstar shell — it silently dropped
test/usage.test.js once test/hooks/ was added).
…m 2)

Confirms fail-silent behavior (no additionalContext, no error) is
observable at the hook seam, not just inside getUsage() — already
covered by the existing null-check in handleUserPromptSubmit, so this
seam went green without an implementation change.
controller.js: thin stdin->handler->stdout wrapper, runnable standalone
(node src/hooks/user-prompt-submit/controller.js) — satisfies the
'self-contained script' acceptance criterion ahead of #5's settings.json
wiring. No logic here per ADR 0007; all of it lives in service.js, which
is what the TDD seams test directly.
controller.js per ADR 0007 means an internal IO adapter a feature's
service.js calls INTO. This file is the opposite: the external entrypoint
Claude Code invokes directly, which calls INTO service.js. Same name,
different role — renamed to avoid the collision. No behavior change.
Main-session injection via UserPromptSubmit
Shared by every hook feature that injects usage as additionalContext —
subagent-start and pre-tool-use (issue #4) need the identical formatting
user-prompt-submit already had. No behavior change, all 8 tests still
green.
…seam 1)

Covers both subagent kinds — plain Agent/Task and Workflow-tool
(agent_type: 'workflow-subagent') — same additionalContext shape as
user-prompt-submit, via the shared formatAdditionalContext. hook.js is
the process-IO entrypoint; service.js (handleSubagentStart) is the
tested public seam, importing getUsage from usage/service.js only.
…ent_id (issue #4, TDD seams 2-4)

throttle.js: shouldRefresh(agentId, throttleEvery, statePath) — a
per-agent_id counter persisted to a JSON state file, default N=5,
resets to 0 on the call that crosses the threshold. service.js
(handlePreToolUse) is the tested public seam: reads the throttle
decision, only calls getUsage()/formats additionalContext when the
threshold is actually crossed. hook.js is the process-IO entrypoint.

Seams covered: N-1 calls -> zero fetches; Nth call -> exactly one fetch
+ fresh context + state reset; two interleaved agent_ids each under
threshold individually -> neither refreshes (throttle state is
genuinely per-agent, not global).
…(issue #4 acceptance criteria)

Both hooks already null-checked getUsage()'s result (inherited from #3's
pattern) — these tests just make that acceptance criterion observable
directly, same as #3's seam 2. PreToolUse case also confirms throttle
state still resets on the threshold-crossing call even when the fetch
returns nothing.
…esponse class

Each hook feature (user-prompt-submit, subagent-start, pre-tool-use) now
constructs new UsageHookResponse(hookEventName) and calls .build(usage)
instead of repeating the null-check + hookSpecificOutput object shape
three times. Pure DRY refactor — no behavior change, all 15 tests still
green untouched. Common interface point for any future per-hook-type
variation (e.g. instruction text), without deciding that content now.
Subagent injection via SubagentStart + throttled PreToolUse
… (issue #5, TDD seams 1-3)

Mirrors caveman's addCommandHook/hasCavemanHook/removeHooks pattern:
marker-substring idempotency check before appending, never touches
unrelated existing hook entries.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…py (issue #5, TDD seam 4)

Copies src/{hooks,usage,vendors} into ~/.claude/session-guard/ (or
CLAUDE_CONFIG_DIR) so the registered hook commands survive after a
curl-pipe install's temp clone is discarded. --uninstall strips both
the hook entries and the copied files.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
.claude-plugin/plugin.json wires the same three hooks via
\${CLAUDE_PLUGIN_ROOT}; marketplace.json makes it addable via
/plugin marketplace add, the second of the two distribution paths
from ADR 0004.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
install.sh / install.ps1: check Node >=18, run bin/install.js directly
inside a local clone, otherwise fetch the repo tarball/zip into a temp
dir themselves and run it from there. No npm registry publish, no npx,
anywhere in the path (ADR 0004 amendment). Verified manually end-to-end
against a temp CLAUDE_CONFIG_DIR (install, re-run idempotent, uninstall
cleans both settings.json and the copied files).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Installer: curl-pipe shims + Claude Code plugin (no npm/npx)
First dependency in the repo — dev-only, never shipped to end users
(the installer/plugin runtime stays pure stdlib per ADR 0004/0005).
Fixes the two lint errors it surfaced: missing Buffer/fetch globals
in eslint.config.js, and a genuinely unused import in
user-prompt-submit.test.js.
heitorsDev and others added 6 commits August 8, 2026 23:49
…ease/** (issue #6)

Matrix ubuntu-latest + windows-latest, per ADR 0005. No live calls to
Anthropic's usage endpoint (tests already mock fetch/fs). Triggers on
pull_request (any base) and push to release/** only — never on
pull_request:closed, which belongs entirely to #7's release-creation
workflow.
…CI (issue #6)

\`import.meta.url === \`file://\${process.argv[1]}\`\` never matches on
Windows: process.argv[1] is a backslash path (D:\a\...), but
import.meta.url is a properly-encoded file:// URL
(file:///D:/a/.../hook.js). Every hook.js/bin/install.js entrypoint
would have silently never run main() when actually invoked by Claude
Code on Windows — caught live by feat/ci's first PR run (Windows job
failed the installer's fresh-install seam with ENOENT, since
bin/install.js never wrote settings.json).

Fixed with pathToFileURL(process.argv[1]).href, which normalizes
separators/encoding correctly on both platforms — the standard Node
idiom for ESM main-module detection.
CI: lint + test on ubuntu/windows (issue #6)
release/0.0.0 -> 0.0.0, release/1.2.3-beta.1 -> 1.2.3-beta.1 (suffix
passes through unchanged), feat/something -> null (guards the
release-workflow trigger decision).
… -> main merge (issue #7)

Triggers on pull_request:closed to main, guarded by merged==true and
head ref starting with release/ (parseVersion returning null would
also short-circuit, but the startsWith guard keeps non-release PRs
from ever reaching the job). No changelog, no npm publish, no
marketplace submission — tag + release only, per ADR 0006/0007's
personal-first posture (ADR 0005).
Release automation: tag + GitHub Release on release/* -> main merge (issue #7)
@heitorsDev
heitorsDev merged commit b6e34ff into main Aug 9, 2026
4 checks passed
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.

1 participant