molecule-ai-workspace-runtime/molecule_runtime
rabbitblood 89739bf848 feat: pre-commit hook to block internal paths in public monorepo (A)
Anti-leak proposal item A. Companion to D (decision tree in role
prompts, separate PR on org-templates).

Why a local pre-commit hook
===========================

Agents try to `git add /research/foo.md` despite SHARED_RULES, the
.gitignore patterns, and the CI gate. Each leak attempt costs ~5 cycles
(PR opens, CI fails, agent retries with workaround) and pollutes git
history with reverts.

A pre-commit hook converts the failure from "PR opens then fails" →
"commit refused immediately, with the recovery command printed in the
same error message the agent reads." Agents act on what's in the
current response context — putting the redirect command literally in
the failure output is the highest-density feedback we can provide.

What changes
============

- molecule_runtime/scripts/pre-commit-block-internal-paths.sh —
  bash hook. Checks `git remote get-url origin`, only enforces in
  Molecule-AI/molecule-monorepo + molecule-core. In every other repo
  (internal, plugins, templates, third-party) it's a no-op.

  When forbidden paths are staged, refuses the commit with the redirect
  recipe + the alternative public-facing paths + the workflow-edit path
  for legitimate exceptions.

- molecule_runtime/precommit_hook.py — install_pre_commit_hook():
  1. Extracts bundled hook to ~/.molecule-runtime/git-hooks/pre-commit
  2. chmod +x
  3. Sets core.hooksPath globally — UNLESS already set by an operator
     (then logs a warning + skips, doesn't clobber)

- molecule_runtime/main.py — calls install_pre_commit_hook() at
  step 0.2, right after install_credential_helper()

- pyproject.toml bumped to 0.1.11

Both A and D together close the loop: D ensures the agent knows the
right path before writing; A enforces it at the local git boundary if
the agent forgets. CI gate remains the third backstop for anything
that gets pushed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:48:47 -07:00
..
adapters Merge branch 'main' of https://github.com/Molecule-AI/molecule-ai-workspace-runtime into fix/507-mcp-server-path-absolute-imports 2026-04-21 06:37:38 -07:00
builtin_tools test+fix(builtin_tools/validation): add test coverage + fix ".." bypass in regex 2026-04-21 00:55:08 +00:00
plugins_registry fix(plugins_registry/builtins): strip API keys from plugin setup.sh env 2026-04-20 22:52:13 +00:00
policies feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
scripts feat: pre-commit hook to block internal paths in public monorepo (A) 2026-04-24 00:48:47 -07:00
skill_loader feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
__init__.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
a2a_cli.py fix(a2a_cli): validate WORKSPACE_ID in discover() before X-Workspace-ID header 2026-04-21 01:35:37 +00:00
a2a_client.py fix(builtin_tools/validation): extend WORKSPACE_ID validation to top-level modules 2026-04-21 00:55:08 +00:00
a2a_executor.py feat: migrate a2a-sdk 1.x (KI-009) (#39) 2026-04-24 01:54:33 +00:00
a2a_mcp_server.py fix(builtin_tools/audit): fail-secure RBAC — read-only default when config unavailable 2026-04-20 22:47:38 +00:00
a2a_tools.py fix(builtin_tools/validation): complete WORKSPACE_ID validation in a2a_tools.py 2026-04-21 00:55:08 +00:00
agent.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
claude_sdk_executor.py feat: migrate a2a-sdk 1.x (KI-009) (#39) 2026-04-24 01:54:33 +00:00
cli_executor.py feat: migrate a2a-sdk 1.x (KI-009) (#39) 2026-04-24 01:54:33 +00:00
config.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
consolidation.py fix(builtin_tools/validation): cover remaining WORKSPACE_ID URL usages 2026-04-21 00:55:08 +00:00
coordinator.py fix(builtin_tools/validation): cover remaining WORKSPACE_ID URL usages 2026-04-21 00:55:08 +00:00
credential_helper.py feat: ship GitHub credential-helper inline in runtime (fixes #1933 class) 2026-04-24 00:41:32 -07:00
events.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
executor_helpers.py fix(heartbeat): increment/decrement active_tasks + push on clear (#1372, #1408) 2026-04-21 06:37:12 -07:00
heartbeat.py fix(heartbeat): refresh on-disk auth token on 401 + retry once (#1877) 2026-04-23 13:26:36 -07:00
initial_prompt.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
llm_auth.py fix(llm_auth): tighten base-URL hostname match + strip whitespace + no token in logs 2026-04-23 10:46:07 -07:00
main.py feat: pre-commit hook to block internal paths in public monorepo (A) 2026-04-24 00:48:47 -07:00
molecule_ai_status.py fix(builtin_tools/validation): cover remaining WORKSPACE_ID URL usages 2026-04-21 00:55:08 +00:00
platform_auth.py fix(heartbeat): refresh on-disk auth token on 401 + retry once (#1877) 2026-04-23 13:26:36 -07:00
plugins.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
precommit_hook.py feat: pre-commit hook to block internal paths in public monorepo (A) 2026-04-24 00:48:47 -07:00
preflight.py fix: gate session resume on file existence (closes #488) 2026-04-16 11:12:03 -07:00
prompt.py fix: switch top-level from adapters import to absolute imports (#1) 2026-04-16 07:53:03 -07:00
transcript_auth.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00
watcher.py feat: initial release of molecule-ai-workspace-runtime 0.1.0 2026-04-16 04:26:06 -07:00