@memnexus-ai/mx-agent-cli 0.1.294 → 0.1.295-next.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/dist/__tests__/agents-md-canonicalization.test.js +31 -1
- package/dist/__tests__/agents-md-canonicalization.test.js.map +1 -1
- package/dist/__tests__/behavioral-extraction.test.js +50 -0
- package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
- package/dist/__tests__/bootstrap-behavioral-contract.test.js +6 -3
- package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/bundle-config.test.js +28 -2
- package/dist/__tests__/bundle-config.test.js.map +1 -1
- package/dist/__tests__/catalog-interaction.test.d.ts +25 -0
- package/dist/__tests__/catalog-interaction.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-interaction.test.js +269 -0
- package/dist/__tests__/catalog-interaction.test.js.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts +2 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.js +204 -0
- package/dist/__tests__/catalog-named-memories.test.js.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts +15 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.js +296 -0
- package/dist/__tests__/catalog-origin-main.test.js.map +1 -0
- package/dist/__tests__/catalog.test.d.ts +2 -0
- package/dist/__tests__/catalog.test.d.ts.map +1 -0
- package/dist/__tests__/catalog.test.js +131 -0
- package/dist/__tests__/catalog.test.js.map +1 -0
- package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
- package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build-integration.test.js +64 -0
- package/dist/__tests__/cli-build-integration.test.js.map +1 -0
- package/dist/__tests__/cli-build.test.d.ts +2 -0
- package/dist/__tests__/cli-build.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build.test.js +640 -0
- package/dist/__tests__/cli-build.test.js.map +1 -0
- package/dist/__tests__/codex-deploy-config.test.js +60 -0
- package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
- package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
- package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
- package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
- package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.js +77 -0
- package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
- package/dist/__tests__/config-fidelity.test.js +166 -33
- package/dist/__tests__/config-fidelity.test.js.map +1 -1
- package/dist/__tests__/config-generation-gate.test.js +78 -0
- package/dist/__tests__/config-generation-gate.test.js.map +1 -1
- package/dist/__tests__/config-sync.test.js +89 -1
- package/dist/__tests__/config-sync.test.js.map +1 -1
- package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
- package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
- package/dist/__tests__/coordination-401-recovery.test.js +39 -32
- package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
- package/dist/__tests__/coordination-brief-pin.test.js +21 -8
- package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
- package/dist/__tests__/coordination-client.test.js +227 -3
- package/dist/__tests__/coordination-client.test.js.map +1 -1
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js +1230 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
- package/dist/__tests__/coordination-memory.test.js +20 -4
- package/dist/__tests__/coordination-memory.test.js.map +1 -1
- package/dist/__tests__/coordination-provision.test.js +22 -14
- package/dist/__tests__/coordination-provision.test.js.map +1 -1
- package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
- package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-status-registration.test.js +480 -0
- package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
- package/dist/__tests__/coordination-token-multitenant.test.js +11 -11
- package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
- package/dist/__tests__/coordination-token.test.js +35 -28
- package/dist/__tests__/coordination-token.test.js.map +1 -1
- package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
- package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
- package/dist/__tests__/creation-pr-class-check.test.js +346 -0
- package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
- package/dist/__tests__/decision-check.test.d.ts +2 -0
- package/dist/__tests__/decision-check.test.d.ts.map +1 -0
- package/dist/__tests__/decision-check.test.js +105 -0
- package/dist/__tests__/decision-check.test.js.map +1 -0
- package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
- package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
- package/dist/__tests__/digest-team-omission.test.js +247 -0
- package/dist/__tests__/digest-team-omission.test.js.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.js +158 -0
- package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
- package/dist/__tests__/fleet-data.test.js +40 -7
- package/dist/__tests__/fleet-data.test.js.map +1 -1
- package/dist/__tests__/fleet-tmux.test.js +2 -2
- package/dist/__tests__/fleet-tmux.test.js.map +1 -1
- package/dist/__tests__/generate-claude.test.js +137 -3
- package/dist/__tests__/generate-claude.test.js.map +1 -1
- package/dist/__tests__/git-env.test.d.ts +14 -0
- package/dist/__tests__/git-env.test.d.ts.map +1 -0
- package/dist/__tests__/git-env.test.js +131 -0
- package/dist/__tests__/git-env.test.js.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.js +626 -0
- package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
- package/dist/__tests__/harness-extract.test.d.ts +19 -0
- package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
- package/dist/__tests__/harness-extract.test.js +566 -0
- package/dist/__tests__/harness-extract.test.js.map +1 -0
- package/dist/__tests__/harness-wiring.test.d.ts +16 -0
- package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/harness-wiring.test.js +469 -0
- package/dist/__tests__/harness-wiring.test.js.map +1 -0
- package/dist/__tests__/hook-heal.test.js +17 -0
- package/dist/__tests__/hook-heal.test.js.map +1 -1
- package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
- package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
- package/dist/__tests__/init-coordination-url.test.js +114 -0
- package/dist/__tests__/init-coordination-url.test.js.map +1 -0
- package/dist/__tests__/memory-autocreate.test.js +574 -8
- package/dist/__tests__/memory-autocreate.test.js.map +1 -1
- package/dist/__tests__/memory-log-result.test.d.ts +13 -0
- package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
- package/dist/__tests__/memory-log-result.test.js +113 -0
- package/dist/__tests__/memory-log-result.test.js.map +1 -0
- package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
- package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
- package/dist/__tests__/memory-named-exists.test.js +288 -0
- package/dist/__tests__/memory-named-exists.test.js.map +1 -0
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
- package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
- package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
- package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
- package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
- package/dist/__tests__/new-project-first-team.test.js +263 -0
- package/dist/__tests__/new-project-first-team.test.js.map +1 -0
- package/dist/__tests__/otel-env.test.d.ts +2 -0
- package/dist/__tests__/otel-env.test.d.ts.map +1 -0
- package/dist/__tests__/otel-env.test.js +127 -0
- package/dist/__tests__/otel-env.test.js.map +1 -0
- package/dist/__tests__/project-config.test.js +283 -1
- package/dist/__tests__/project-config.test.js.map +1 -1
- package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
- package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
- package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
- package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
- package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.js +3095 -0
- package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.js +600 -0
- package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
- package/dist/__tests__/provision-resume.test.d.ts +26 -0
- package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
- package/dist/__tests__/provision-resume.test.js +1164 -0
- package/dist/__tests__/provision-resume.test.js.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
- package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
- package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
- package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
- package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/repo-guard-wiring.test.js +638 -0
- package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
- package/dist/__tests__/report-format.test.d.ts +2 -0
- package/dist/__tests__/report-format.test.d.ts.map +1 -0
- package/dist/__tests__/report-format.test.js +219 -0
- package/dist/__tests__/report-format.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
- package/dist/__tests__/runtime-identity.test.d.ts +2 -0
- package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-identity.test.js +117 -0
- package/dist/__tests__/runtime-identity.test.js.map +1 -0
- package/dist/__tests__/session-pause-provisioning.test.js +6 -1
- package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
- package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
- package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
- package/dist/__tests__/session-record-disclosure.test.js +494 -0
- package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
- package/dist/__tests__/session.test.js +35 -0
- package/dist/__tests__/session.test.js.map +1 -1
- package/dist/__tests__/slug-validation.test.js +27 -21
- package/dist/__tests__/slug-validation.test.js.map +1 -1
- package/dist/__tests__/standards-injection.test.d.ts +2 -0
- package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
- package/dist/__tests__/standards-injection.test.js +179 -0
- package/dist/__tests__/standards-injection.test.js.map +1 -0
- package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
- package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
- package/dist/__tests__/start-interactive-role.test.js +204 -0
- package/dist/__tests__/start-interactive-role.test.js.map +1 -0
- package/dist/__tests__/start-team-identity.test.d.ts +25 -0
- package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
- package/dist/__tests__/start-team-identity.test.js +307 -0
- package/dist/__tests__/start-team-identity.test.js.map +1 -0
- package/dist/__tests__/team-memory-commands.test.js +142 -19
- package/dist/__tests__/team-memory-commands.test.js.map +1 -1
- package/dist/__tests__/template-sync.test.d.ts +19 -0
- package/dist/__tests__/template-sync.test.d.ts.map +1 -0
- package/dist/__tests__/template-sync.test.js +270 -0
- package/dist/__tests__/template-sync.test.js.map +1 -0
- package/dist/__tests__/test-project.test.d.ts +18 -0
- package/dist/__tests__/test-project.test.d.ts.map +1 -0
- package/dist/__tests__/test-project.test.js +465 -0
- package/dist/__tests__/test-project.test.js.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
- package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
- package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
- package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
- package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
- package/dist/__tests__/worktree.test.js +75 -1
- package/dist/__tests__/worktree.test.js.map +1 -1
- package/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +2 -2
- package/dist/agent-config/agents/bar-raiser.md +34 -1
- package/dist/agent-config/agents/red-team.md +34 -1
- package/dist/agent-config/agents/security-reviewer.md +22 -1
- package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
- package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
- package/dist/agent-config/coordination-rosters.generated.json +10 -0
- package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
- package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
- package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
- package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
- package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
- package/dist/agent-config/hooks/coordination-brief.sh +290 -245
- package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
- package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
- package/dist/agent-config/hooks/observability-sync.sh +46 -9
- package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
- package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
- package/dist/agent-config/hooks/worktree-guard.sh +36 -7
- package/dist/agent-config/settings.json +15 -2
- package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +22 -10
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/config-sync.d.ts +37 -0
- package/dist/commands/config-sync.d.ts.map +1 -1
- package/dist/commands/config-sync.js +36 -18
- package/dist/commands/config-sync.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +28 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/coordination.d.ts +150 -8
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +519 -25
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts +913 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +4879 -345
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dashboard.d.ts.map +1 -1
- package/dist/commands/dashboard.js +10 -2
- package/dist/commands/dashboard.js.map +1 -1
- package/dist/commands/decision.d.ts +20 -0
- package/dist/commands/decision.d.ts.map +1 -0
- package/dist/commands/decision.js +54 -0
- package/dist/commands/decision.js.map +1 -0
- package/dist/commands/digest.d.ts.map +1 -1
- package/dist/commands/digest.js +91 -7
- package/dist/commands/digest.js.map +1 -1
- package/dist/commands/fleet-tmux.js +1 -1
- package/dist/commands/fleet-tmux.js.map +1 -1
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +26 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +32 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +98 -5
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/monitor.d.ts.map +1 -1
- package/dist/commands/monitor.js +8 -2
- package/dist/commands/monitor.js.map +1 -1
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +114 -21
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/report.d.ts +33 -0
- package/dist/commands/report.d.ts.map +1 -0
- package/dist/commands/report.js +73 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/session.js +1 -1
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/start.d.ts +42 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +177 -8
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/sync.d.ts +57 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +117 -3
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/update.d.ts +13 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +50 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/usage.d.ts +64 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +96 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/verify-hooks.d.ts +37 -1
- package/dist/commands/verify-hooks.d.ts.map +1 -1
- package/dist/commands/verify-hooks.js +114 -2
- package/dist/commands/verify-hooks.js.map +1 -1
- package/dist/commands/window.d.ts +10 -0
- package/dist/commands/window.d.ts.map +1 -0
- package/dist/commands/window.js +265 -0
- package/dist/commands/window.js.map +1 -0
- package/dist/commands/worktree-sync.d.ts +54 -0
- package/dist/commands/worktree-sync.d.ts.map +1 -0
- package/dist/commands/worktree-sync.js +135 -0
- package/dist/commands/worktree-sync.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-session.d.ts +12 -0
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +189 -42
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/catalog.d.ts +321 -2
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +490 -11
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/claude.d.ts +65 -23
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +335 -19
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/cli-build.d.ts +172 -0
- package/dist/lib/cli-build.d.ts.map +1 -0
- package/dist/lib/cli-build.js +654 -0
- package/dist/lib/cli-build.js.map +1 -0
- package/dist/lib/code-context-file.d.ts +109 -0
- package/dist/lib/code-context-file.d.ts.map +1 -0
- package/dist/lib/code-context-file.js +219 -0
- package/dist/lib/code-context-file.js.map +1 -0
- package/dist/lib/code-context-file.test.d.ts +19 -0
- package/dist/lib/code-context-file.test.d.ts.map +1 -0
- package/dist/lib/code-context-file.test.js +202 -0
- package/dist/lib/code-context-file.test.js.map +1 -0
- package/dist/lib/config-fidelity.d.ts +40 -20
- package/dist/lib/config-fidelity.d.ts.map +1 -1
- package/dist/lib/config-fidelity.js +144 -56
- package/dist/lib/config-fidelity.js.map +1 -1
- package/dist/lib/coordination-client.d.ts +73 -0
- package/dist/lib/coordination-client.d.ts.map +1 -1
- package/dist/lib/coordination-client.js +180 -8
- package/dist/lib/coordination-client.js.map +1 -1
- package/dist/lib/coordination-token.d.ts +304 -6
- package/dist/lib/coordination-token.d.ts.map +1 -1
- package/dist/lib/coordination-token.js +851 -52
- package/dist/lib/coordination-token.js.map +1 -1
- package/dist/lib/decision-check.d.ts +48 -0
- package/dist/lib/decision-check.d.ts.map +1 -0
- package/dist/lib/decision-check.js +149 -0
- package/dist/lib/decision-check.js.map +1 -0
- package/dist/lib/fleet-data.d.ts +34 -0
- package/dist/lib/fleet-data.d.ts.map +1 -1
- package/dist/lib/fleet-data.js +37 -9
- package/dist/lib/fleet-data.js.map +1 -1
- package/dist/lib/fleet-render.js +1 -1
- package/dist/lib/fleet-render.js.map +1 -1
- package/dist/lib/git-identity.d.ts +302 -0
- package/dist/lib/git-identity.d.ts.map +1 -0
- package/dist/lib/git-identity.js +546 -0
- package/dist/lib/git-identity.js.map +1 -0
- package/dist/lib/harness/console/announce.d.ts +45 -0
- package/dist/lib/harness/console/announce.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.js +48 -0
- package/dist/lib/harness/console/announce.js.map +1 -0
- package/dist/lib/harness/console/announce.test.d.ts +2 -0
- package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.test.js +104 -0
- package/dist/lib/harness/console/announce.test.js.map +1 -0
- package/dist/lib/harness/console/by-session.d.ts +50 -0
- package/dist/lib/harness/console/by-session.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.js +83 -0
- package/dist/lib/harness/console/by-session.js.map +1 -0
- package/dist/lib/harness/console/by-session.test.d.ts +2 -0
- package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.test.js +86 -0
- package/dist/lib/harness/console/by-session.test.js.map +1 -0
- package/dist/lib/harness/console/console.d.ts +67 -0
- package/dist/lib/harness/console/console.d.ts.map +1 -0
- package/dist/lib/harness/console/console.js +373 -0
- package/dist/lib/harness/console/console.js.map +1 -0
- package/dist/lib/harness/console/console.test.d.ts +2 -0
- package/dist/lib/harness/console/console.test.d.ts.map +1 -0
- package/dist/lib/harness/console/console.test.js +269 -0
- package/dist/lib/harness/console/console.test.js.map +1 -0
- package/dist/lib/harness/console/decision-request.d.ts +32 -0
- package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.js +112 -0
- package/dist/lib/harness/console/decision-request.js.map +1 -0
- package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
- package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.test.js +75 -0
- package/dist/lib/harness/console/decision-request.test.js.map +1 -0
- package/dist/lib/harness/console/fixtures.d.ts +16 -0
- package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
- package/dist/lib/harness/console/fixtures.js +49 -0
- package/dist/lib/harness/console/fixtures.js.map +1 -0
- package/dist/lib/harness/console/index.d.ts +15 -0
- package/dist/lib/harness/console/index.d.ts.map +1 -0
- package/dist/lib/harness/console/index.js +14 -0
- package/dist/lib/harness/console/index.js.map +1 -0
- package/dist/lib/harness/console/rank.d.ts +73 -0
- package/dist/lib/harness/console/rank.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.js +113 -0
- package/dist/lib/harness/console/rank.js.map +1 -0
- package/dist/lib/harness/console/rank.test.d.ts +2 -0
- package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.test.js +124 -0
- package/dist/lib/harness/console/rank.test.js.map +1 -0
- package/dist/lib/harness/console/render.d.ts +22 -0
- package/dist/lib/harness/console/render.d.ts.map +1 -0
- package/dist/lib/harness/console/render.js +65 -0
- package/dist/lib/harness/console/render.js.map +1 -0
- package/dist/lib/harness/console/render.test.d.ts +2 -0
- package/dist/lib/harness/console/render.test.d.ts.map +1 -0
- package/dist/lib/harness/console/render.test.js +96 -0
- package/dist/lib/harness/console/render.test.js.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.js +96 -0
- package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
- package/dist/lib/harness/console/replay.d.ts +36 -0
- package/dist/lib/harness/console/replay.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.js +59 -0
- package/dist/lib/harness/console/replay.js.map +1 -0
- package/dist/lib/harness/console/replay.test.d.ts +2 -0
- package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.test.js +81 -0
- package/dist/lib/harness/console/replay.test.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.d.ts +50 -0
- package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.js +184 -0
- package/dist/lib/harness/console/turn-reader.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.js +108 -0
- package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
- package/dist/lib/harness/console/types.d.ts +109 -0
- package/dist/lib/harness/console/types.d.ts.map +1 -0
- package/dist/lib/harness/console/types.js +2 -0
- package/dist/lib/harness/console/types.js.map +1 -0
- package/dist/lib/harness/contract.d.ts +229 -0
- package/dist/lib/harness/contract.d.ts.map +1 -0
- package/dist/lib/harness/contract.js +22 -0
- package/dist/lib/harness/contract.js.map +1 -0
- package/dist/lib/harness/credential.d.ts +23 -0
- package/dist/lib/harness/credential.d.ts.map +1 -0
- package/dist/lib/harness/credential.js +81 -0
- package/dist/lib/harness/credential.js.map +1 -0
- package/dist/lib/harness/credential.test.d.ts +2 -0
- package/dist/lib/harness/credential.test.d.ts.map +1 -0
- package/dist/lib/harness/credential.test.js +74 -0
- package/dist/lib/harness/credential.test.js.map +1 -0
- package/dist/lib/harness/evaluate.d.ts +390 -0
- package/dist/lib/harness/evaluate.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.js +988 -0
- package/dist/lib/harness/evaluate.js.map +1 -0
- package/dist/lib/harness/evaluate.test.d.ts +2 -0
- package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.test.js +621 -0
- package/dist/lib/harness/evaluate.test.js.map +1 -0
- package/dist/lib/harness/extract.d.ts +152 -0
- package/dist/lib/harness/extract.d.ts.map +1 -0
- package/dist/lib/harness/extract.js +1601 -0
- package/dist/lib/harness/extract.js.map +1 -0
- package/dist/lib/harness/gate.d.ts +48 -0
- package/dist/lib/harness/gate.d.ts.map +1 -0
- package/dist/lib/harness/gate.js +60 -0
- package/dist/lib/harness/gate.js.map +1 -0
- package/dist/lib/harness/gate.test.d.ts +2 -0
- package/dist/lib/harness/gate.test.d.ts.map +1 -0
- package/dist/lib/harness/gate.test.js +111 -0
- package/dist/lib/harness/gate.test.js.map +1 -0
- package/dist/lib/harness/self-check.d.ts +59 -0
- package/dist/lib/harness/self-check.d.ts.map +1 -0
- package/dist/lib/harness/self-check.js +56 -0
- package/dist/lib/harness/self-check.js.map +1 -0
- package/dist/lib/harness/self-check.test.d.ts +2 -0
- package/dist/lib/harness/self-check.test.d.ts.map +1 -0
- package/dist/lib/harness/self-check.test.js +43 -0
- package/dist/lib/harness/self-check.test.js.map +1 -0
- package/dist/lib/harness/transcript.d.ts +65 -0
- package/dist/lib/harness/transcript.d.ts.map +1 -0
- package/dist/lib/harness/transcript.js +144 -0
- package/dist/lib/harness/transcript.js.map +1 -0
- package/dist/lib/harness/transcript.test.d.ts +2 -0
- package/dist/lib/harness/transcript.test.d.ts.map +1 -0
- package/dist/lib/harness/transcript.test.js +118 -0
- package/dist/lib/harness/transcript.test.js.map +1 -0
- package/dist/lib/harness-wiring.d.ts +145 -0
- package/dist/lib/harness-wiring.d.ts.map +1 -0
- package/dist/lib/harness-wiring.js +280 -0
- package/dist/lib/harness-wiring.js.map +1 -0
- package/dist/lib/hook-staleness.d.ts +95 -0
- package/dist/lib/hook-staleness.d.ts.map +1 -0
- package/dist/lib/hook-staleness.js +304 -0
- package/dist/lib/hook-staleness.js.map +1 -0
- package/dist/lib/jsonl.d.ts +270 -2
- package/dist/lib/jsonl.d.ts.map +1 -1
- package/dist/lib/jsonl.js +472 -76
- package/dist/lib/jsonl.js.map +1 -1
- package/dist/lib/memory.d.ts +350 -23
- package/dist/lib/memory.d.ts.map +1 -1
- package/dist/lib/memory.js +751 -38
- package/dist/lib/memory.js.map +1 -1
- package/dist/lib/otel-env.d.ts +90 -0
- package/dist/lib/otel-env.d.ts.map +1 -0
- package/dist/lib/otel-env.js +98 -0
- package/dist/lib/otel-env.js.map +1 -0
- package/dist/lib/project-config.d.ts +167 -0
- package/dist/lib/project-config.d.ts.map +1 -1
- package/dist/lib/project-config.js +321 -5
- package/dist/lib/project-config.js.map +1 -1
- package/dist/lib/projects-registry.d.ts +82 -0
- package/dist/lib/projects-registry.d.ts.map +1 -0
- package/dist/lib/projects-registry.js +145 -0
- package/dist/lib/projects-registry.js.map +1 -0
- package/dist/lib/projects-registry.test.d.ts +2 -0
- package/dist/lib/projects-registry.test.d.ts.map +1 -0
- package/dist/lib/projects-registry.test.js +176 -0
- package/dist/lib/projects-registry.test.js.map +1 -0
- package/dist/lib/repo-guard-scope.d.ts +126 -0
- package/dist/lib/repo-guard-scope.d.ts.map +1 -0
- package/dist/lib/repo-guard-scope.js +249 -0
- package/dist/lib/repo-guard-scope.js.map +1 -0
- package/dist/lib/report-format.d.ts +132 -0
- package/dist/lib/report-format.d.ts.map +1 -0
- package/dist/lib/report-format.js +317 -0
- package/dist/lib/report-format.js.map +1 -0
- package/dist/lib/roster.d.ts +87 -0
- package/dist/lib/roster.d.ts.map +1 -0
- package/dist/lib/roster.js +332 -0
- package/dist/lib/roster.js.map +1 -0
- package/dist/lib/roster.test.d.ts +15 -0
- package/dist/lib/roster.test.d.ts.map +1 -0
- package/dist/lib/roster.test.js +299 -0
- package/dist/lib/roster.test.js.map +1 -0
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +5 -0
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +129 -0
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +225 -0
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/dist/lib/runtime/identity.d.ts +72 -0
- package/dist/lib/runtime/identity.d.ts.map +1 -0
- package/dist/lib/runtime/identity.js +128 -0
- package/dist/lib/runtime/identity.js.map +1 -0
- package/dist/lib/standards.d.ts +99 -0
- package/dist/lib/standards.d.ts.map +1 -0
- package/dist/lib/standards.js +201 -0
- package/dist/lib/standards.js.map +1 -0
- package/dist/lib/team-identity.d.ts +134 -0
- package/dist/lib/team-identity.d.ts.map +1 -0
- package/dist/lib/team-identity.js +193 -0
- package/dist/lib/team-identity.js.map +1 -0
- package/dist/lib/templates.d.ts +29 -2
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +1042 -82
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/terminal-ui.d.ts.map +1 -1
- package/dist/lib/terminal-ui.js +12 -1
- package/dist/lib/terminal-ui.js.map +1 -1
- package/dist/lib/test-project.d.ts +95 -0
- package/dist/lib/test-project.d.ts.map +1 -0
- package/dist/lib/test-project.js +103 -0
- package/dist/lib/test-project.js.map +1 -0
- package/dist/lib/vault.d.ts +60 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +102 -0
- package/dist/lib/vault.js.map +1 -0
- package/dist/lib/vault.test.d.ts +17 -0
- package/dist/lib/vault.test.d.ts.map +1 -0
- package/dist/lib/vault.test.js +169 -0
- package/dist/lib/vault.test.js.map +1 -0
- package/dist/lib/window-view.d.ts +63 -0
- package/dist/lib/window-view.d.ts.map +1 -0
- package/dist/lib/window-view.js +217 -0
- package/dist/lib/window-view.js.map +1 -0
- package/dist/lib/window-view.test.d.ts +2 -0
- package/dist/lib/window-view.test.d.ts.map +1 -0
- package/dist/lib/window-view.test.js +168 -0
- package/dist/lib/window-view.test.js.map +1 -0
- package/dist/lib/worktree-sync.d.ts +439 -0
- package/dist/lib/worktree-sync.d.ts.map +1 -0
- package/dist/lib/worktree-sync.js +1167 -0
- package/dist/lib/worktree-sync.js.map +1 -0
- package/dist/lib/worktree.d.ts +58 -1
- package/dist/lib/worktree.d.ts.map +1 -1
- package/dist/lib/worktree.js +91 -4
- package/dist/lib/worktree.js.map +1 -1
- package/dist/standards/decision-request.md +98 -0
- package/dist/standards/fail-loud-standard.md +495 -0
- package/dist/standards/po-communication-standard.md +126 -0
- package/dist/standards/report-format.md +128 -0
- package/dist/standards/writing-standard.md +382 -0
- package/package.json +3 -2
- package/scripts/generate-claude.mjs +119 -46
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# subagent-write-guard — PreToolUse(Bash) guard that refuses four `gh` write
|
|
3
|
+
# commands when the caller is a DISPATCHED SUBAGENT, and allows them on the
|
|
4
|
+
# MAIN THREAD.
|
|
5
|
+
#
|
|
6
|
+
# Contract: reads the tool-call JSON on stdin.
|
|
7
|
+
# exit 0 = allow, exit 2 = block (a non-zero exit blocks the Bash command).
|
|
8
|
+
#
|
|
9
|
+
# WHY. Product-owner ruling, given 2026-08-21 (#12): "The sub-agent shouldn't be
|
|
10
|
+
# able to merge the PR, but the team lead should." Commits 4ac2951 and 7c23b68
|
|
11
|
+
# gave the bar-raiser and red-team agent types Bash so their gates could run real
|
|
12
|
+
# commands. The security review on that change found settings.json allows bare
|
|
13
|
+
# `Bash` and denies none of `gh pr merge`, `gh pr review`, `gh issue close` or
|
|
14
|
+
# `gh api -X`, so a grader that followed an instruction planted in the pull
|
|
15
|
+
# request it was grading could approve or merge that pull request itself. The
|
|
16
|
+
# party who wrote a change never produces the verdict on it, and the party who
|
|
17
|
+
# produces the verdict does not get to act on it either.
|
|
18
|
+
#
|
|
19
|
+
# WHY NOT A permissions.deny ENTRY. `permissions.deny` in settings.json binds
|
|
20
|
+
# every session in the worktree, the team lead's included. A deny on
|
|
21
|
+
# `Bash(gh pr merge *)` would satisfy the first half of the ruling and break the
|
|
22
|
+
# second. Permission rules have no caller dimension; a hook does.
|
|
23
|
+
#
|
|
24
|
+
# THE SIGNAL IS .agent_id. The harness sets it only inside a dispatched subagent
|
|
25
|
+
# and never on the main thread. Two sources, checked 2026-08-21:
|
|
26
|
+
#
|
|
27
|
+
# 1. The published hook reference, https://code.claude.com/docs/en/hooks, hook
|
|
28
|
+
# input fields table:
|
|
29
|
+
# agent_id — "Unique identifier for the subagent. Present only when the
|
|
30
|
+
# hook fires inside a subagent call. Use this to distinguish
|
|
31
|
+
# subagent hook calls from main-thread calls."
|
|
32
|
+
# 2. The installed bundle (version 2.1.238,
|
|
33
|
+
# ~/.npm-global/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe),
|
|
34
|
+
# zod .describe() on agent_id: "Subagent identifier. Present only when the
|
|
35
|
+
# hook fires from within a subagent (e.g., a tool called by an AgentTool
|
|
36
|
+
# worker). Absent for the main thread, even in --agent sessions. Use this
|
|
37
|
+
# field (not agent_type) to distinguish subagent calls from main-thread
|
|
38
|
+
# calls."
|
|
39
|
+
#
|
|
40
|
+
# memory-checkpoint-reminder.sh already branches on .agent_id for the same
|
|
41
|
+
# reason (#5136), so this file adds no new dependency on harness input.
|
|
42
|
+
#
|
|
43
|
+
# .agent_id, not .agent_type: agent_type is ALSO set on the main thread of an
|
|
44
|
+
# --agent session, so branching on it would refuse a legitimate lead. Pinned by
|
|
45
|
+
# a test.
|
|
46
|
+
#
|
|
47
|
+
# Measured directly, 2026-08-21: a PreToolUse(Bash) call from a dispatched
|
|
48
|
+
# subagent carried agent_id (17 characters), agent_type
|
|
49
|
+
# ("implementation-engineer"), and the DISPATCHER'S session_id and
|
|
50
|
+
# transcript_path. session_id and transcript_path therefore cannot separate a
|
|
51
|
+
# subagent from its lead. agent_id is the only field that does.
|
|
52
|
+
#
|
|
53
|
+
# WHAT IS REFUSED, for a subagent:
|
|
54
|
+
# gh pr merge the ruling's subject
|
|
55
|
+
# gh pr review approving or requesting changes is the reviewer's verdict,
|
|
56
|
+
# and settings.json denies it to nobody
|
|
57
|
+
# gh issue close closing the issue a change is graded against
|
|
58
|
+
# gh api when the effective HTTP method is not GET
|
|
59
|
+
#
|
|
60
|
+
# `gh api` METHOD INFERENCE. `-X`/`--method` names the method outright. With no
|
|
61
|
+
# such flag, `gh` sends GET unless a field flag is present (-f, -F, --field,
|
|
62
|
+
# --raw-field, --input), in which case it sends POST. Both forms are refused,
|
|
63
|
+
# because the second is a complete route around the first: `gh api
|
|
64
|
+
# repos/{owner}/{repo}/pulls/1/merge -f merge_method=squash` merges a pull
|
|
65
|
+
# request and contains no `-X`. The ruling names `gh api -X`; refusing the
|
|
66
|
+
# fieldful no-`-X` form is this file's judgement, recorded here because it widens
|
|
67
|
+
# the named scope by one form.
|
|
68
|
+
#
|
|
69
|
+
# `--help` / `-h` immediately after the subcommand is allowed: it prints usage
|
|
70
|
+
# and makes no API call.
|
|
71
|
+
#
|
|
72
|
+
# FAILURE DIRECTION — CLOSED, and this is the opposite of gh-pr-edit-guard.sh.
|
|
73
|
+
# That guard is a signpost about a broken binary, and the cost of a miss is one
|
|
74
|
+
# confusing error, so it fails open. This one answers "may this caller take an
|
|
75
|
+
# irreversible, externally-visible action", and a guard that cannot answer must
|
|
76
|
+
# not answer yes. Three states, kept apart:
|
|
77
|
+
# * agent_id present → subagent → refuse a matched command
|
|
78
|
+
# * agent_id absent, envelope well-formed → main thread → allow
|
|
79
|
+
# * envelope not well-formed, or jq missing → INDETERMINATE → refuse a matched
|
|
80
|
+
# command, saying that identity could not be established
|
|
81
|
+
# "Well-formed" means the payload parses as a JSON object carrying session_id or
|
|
82
|
+
# hook_event_name, both of which the harness sets on every call. The absence of
|
|
83
|
+
# agent_id is only evidence of a main thread when there is an envelope for it to
|
|
84
|
+
# be absent from.
|
|
85
|
+
#
|
|
86
|
+
# The indeterminate branch refuses ONLY the four matched command families, never
|
|
87
|
+
# an unrelated Bash call. With jq missing there is no parse, so that branch scans
|
|
88
|
+
# the raw stdin text for the same patterns without segment splitting. It
|
|
89
|
+
# over-matches prose that quotes those commands. That is the intended direction
|
|
90
|
+
# for a degraded environment, and it costs a blocked message, not lost work.
|
|
91
|
+
#
|
|
92
|
+
# The degraded scan still needs `grep`. With grep also gone the hook allows, and
|
|
93
|
+
# that is stated rather than fixed: refusing every Bash call in a worktree whose
|
|
94
|
+
# PATH has lost grep leaves no route to repair it from inside the session, which
|
|
95
|
+
# is a worse outcome than the one it prevents. Named here so the limit is a
|
|
96
|
+
# recorded decision and not an unnoticed hole.
|
|
97
|
+
#
|
|
98
|
+
# RULING HISTORY (recorded by the bootstrap lead, who witnessed both rulings
|
|
99
|
+
# in the lead's own session; the implementer did not witness them and did not
|
|
100
|
+
# write this block):
|
|
101
|
+
# 2026-08-21 "The sub-agent shouldn't be able to merge the PR, but the team
|
|
102
|
+
# lead should." This is the ruling the four families below enforce.
|
|
103
|
+
# 2026-08-22 A read-only variant was chosen ("block gh pr comment too") and
|
|
104
|
+
# reversed by the product owner minutes later: "I think they should
|
|
105
|
+
# be able to comment on a PR, but not merge them." gh pr comment
|
|
106
|
+
# stays allowed for subagents. No code changed for either message;
|
|
107
|
+
# the implementer halted on the first and was countermanded before
|
|
108
|
+
# writing anything.
|
|
109
|
+
#
|
|
110
|
+
# MATCHING IS ASYMMETRIC, and deliberately so (security review of 4dd3212, one
|
|
111
|
+
# Must Fix). The main thread runs all four families legitimately, so a false
|
|
112
|
+
# refusal there is a real cost. It is not matched precisely; it is not matched AT
|
|
113
|
+
# ALL. The main-thread test is a bare `exit 0` before any pattern is evaluated. An
|
|
114
|
+
# earlier version of this paragraph claimed the main thread "keeps the precise
|
|
115
|
+
# segment-anchored GHPFX", which was false in the reassuring direction and is
|
|
116
|
+
# corrected here. A subagent has NO legitimate use of any of the four, so
|
|
117
|
+
# precision buys nothing on that path and costs a bypass. The subagent path
|
|
118
|
+
# matches with the unanchored GHSUB patterns, which accept any non-word character
|
|
119
|
+
# before `gh`.
|
|
120
|
+
#
|
|
121
|
+
# THE WHOLE ASYMMETRY RESTS ON ONE FIELD. Any dispatch path that delivers a
|
|
122
|
+
# subagent WITHOUT agent_id receives the main-thread path, which is now an
|
|
123
|
+
# unconditional allow with no matching at all. That is the single point of
|
|
124
|
+
# failure, it is not defended anywhere else in this file, and it is the first
|
|
125
|
+
# thing to re-measure if the harness changes how subagents are launched.
|
|
126
|
+
#
|
|
127
|
+
# What the first version got wrong: GHPFX admits a launcher word followed by an
|
|
128
|
+
# optional NUMERIC argument only. `timeout 30 gh pr merge 1` was refused and
|
|
129
|
+
# `timeout -s KILL 30 gh pr merge 1` was not, which is the exact wrapper AGENTS.md
|
|
130
|
+
# tells every agent to use. Measured on 4dd3212, subagent payload, jq present:
|
|
131
|
+
# `timeout -s KILL 30`, `env -i` and `nice -n 5` before the command each exited 0,
|
|
132
|
+
# meaning allowed. Enumerating launcher flags is a losing game; not needing the
|
|
133
|
+
# enumeration is the fix.
|
|
134
|
+
#
|
|
135
|
+
# ACCEPTED COST, stated as two lists rather than as general coverage. A subagent
|
|
136
|
+
# that names one of these commands is refused unless the naming happens in a
|
|
137
|
+
# carrier this file recognises.
|
|
138
|
+
#
|
|
139
|
+
# COVERED, quoted text blanked before matching:
|
|
140
|
+
# echo, printf, cat, tee, write
|
|
141
|
+
# grep, rg, jq pattern arguments, never executed
|
|
142
|
+
# mx / mx-agent with --content, --body or --query the mandated memory path
|
|
143
|
+
# gh with --body, --title or --comment
|
|
144
|
+
# git commit / tag / notes with -m or --message
|
|
145
|
+
#
|
|
146
|
+
# NOT COVERED, and a subagent naming a refused command through one of these is
|
|
147
|
+
# refused. Measured, not assumed:
|
|
148
|
+
# sed 's/gh pr merge/x/' a carrier, but not on the list
|
|
149
|
+
# git log --grep='gh pr merge' only commit/tag/notes are carriers
|
|
150
|
+
# awk, perl -e, python3 -c each can execute what it is handed
|
|
151
|
+
# ANY carrier holding $( ) or a backtick, including the covered ones, because
|
|
152
|
+
# a substitution executes (see check_sink). This invariant was FALSE for
|
|
153
|
+
# heredocs until f90382b's successor: an unquoted delimiter expands the body,
|
|
154
|
+
# and the body was being dropped before check_sink ever saw it. See
|
|
155
|
+
# strip_heredocs. A heredoc with a QUOTED delimiter is inert and stays
|
|
156
|
+
# allowed, which is the one place a subagent can write a substitution
|
|
157
|
+
# verbatim.
|
|
158
|
+
#
|
|
159
|
+
# The refusal says what to do instead, so the cost is one blocked call and a
|
|
160
|
+
# re-word. A subagent that needs a report attached to a pull request hands it to
|
|
161
|
+
# the lead, who posts it with attribution.
|
|
162
|
+
#
|
|
163
|
+
# SCOPE — WHAT THIS IS NOT. This is a guardrail, not a security boundary, the
|
|
164
|
+
# same posture as git-mutation-guard.sh. It is bypassable by design: indirection
|
|
165
|
+
# through a script file, shell-variable or `eval` assembly, an alias, a git
|
|
166
|
+
# push that triggers a merge workflow, or a payload handed to a remote shell all
|
|
167
|
+
# escape it, and no attempt is made to close them. It stops a subagent that has
|
|
168
|
+
# been told to merge from merging, which is the recorded failure. It does not
|
|
169
|
+
# contain a subagent that intends to.
|
|
170
|
+
#
|
|
171
|
+
# NOT REFUSED, deliberately: `gh pr close`, `gh pr reopen`, `gh issue reopen`,
|
|
172
|
+
# `gh pr comment`, `gh pr create`, `gh workflow run` (workflow-dispatch-guard.sh
|
|
173
|
+
# owns that one) and every read form. The ruling names four commands. Widening
|
|
174
|
+
# past a named ruling is the product owner's call, not this file's.
|
|
175
|
+
#
|
|
176
|
+
# OUTPUT ROUTING (KI-HOOKS-STDERR-SYSTEMIC): the harness surfaces a blocking
|
|
177
|
+
# hook's STDERR, not its stdout. All refuse() output goes to stderr (>&2). The
|
|
178
|
+
# allow paths stay silent.
|
|
179
|
+
MXHT_HOOK=subagent-write-guard MXHT_EVENT=PreToolUse MXHT_TOOL=Bash
|
|
180
|
+
# >>> SHARED hook-timing probe v1
|
|
181
|
+
# Diagnostic instrumentation: records how long THIS hook ran, so hook time can be
|
|
182
|
+
# separated from time spent waiting on the API when a session stalls mid-stream.
|
|
183
|
+
# Appends one line to a local, gitignored log. Read it with
|
|
184
|
+
# mx-agent-system/scripts/hook-timing-report.sh. Nothing is transmitted anywhere.
|
|
185
|
+
#
|
|
186
|
+
# FAIL SILENT IS DELIBERATE HERE, and it is the opposite of this repo's usual
|
|
187
|
+
# fail-loud direction. Do not "correct" it to fail-loud by applying the fleet
|
|
188
|
+
# default. A diagnostic that can break the gate it observes is worse than no
|
|
189
|
+
# diagnostic: an unwritable path or a full disk would otherwise take out every
|
|
190
|
+
# guard on the PreToolUse path at once. Every step below is guarded and every
|
|
191
|
+
# failure path is a silent no-op that leaves the hook's behaviour untouched.
|
|
192
|
+
#
|
|
193
|
+
# NEAR-ZERO OVERHEAD: bash builtins only on the hot path ($EPOCHREALTIME, printf
|
|
194
|
+
# -T, one read, one append). No subprocess, no network, no JSON parsing, and the
|
|
195
|
+
# hook's stdin is never touched (the hook owns it). mkdir runs at most once per
|
|
196
|
+
# worktree. Kill switch: MX_HOOK_TIMING=0.
|
|
197
|
+
MXHT_T0="${EPOCHREALTIME:-}"
|
|
198
|
+
_mxht_emit() {
|
|
199
|
+
[ -z "${MXHT_DONE:-}" ] || return 0 # an ERR trap that exits fires EXIT too
|
|
200
|
+
MXHT_DONE=1
|
|
201
|
+
[ "${MX_HOOK_TIMING:-1}" != "0" ] || return 0
|
|
202
|
+
[ -n "${MXHT_T0:-}" ] && [ -n "${EPOCHREALTIME:-}" ] || return 0
|
|
203
|
+
local root="${CLAUDE_PROJECT_DIR:-${CLAUDE_WORKTREE_PATH:-}}"
|
|
204
|
+
[ -n "$root" ] && [ -d "$root" ] || return 0
|
|
205
|
+
local dir="$root/.mx-hook-timing"
|
|
206
|
+
[ -d "$dir" ] || mkdir -p "$dir" 2>/dev/null || return 0
|
|
207
|
+
# EPOCHREALTIME is seconds.microseconds; the separator is locale-dependent, so
|
|
208
|
+
# strip both forms and subtract as plain integer microseconds.
|
|
209
|
+
local dur=-1
|
|
210
|
+
{ dur=$(( ${EPOCHREALTIME//[.,]/} - ${MXHT_T0//[.,]/} )); } 2>/dev/null
|
|
211
|
+
[ "$dur" -ge 0 ] 2>/dev/null || return 0
|
|
212
|
+
local stamp hour
|
|
213
|
+
printf -v stamp '%(%Y-%m-%d %H:%M:%S)T' -1
|
|
214
|
+
printf -v hour '%(%H)T' -1
|
|
215
|
+
# BOUNDED BY CONSTRUCTION: a 24-slot ring, one file per hour-of-day, so the log
|
|
216
|
+
# is at most 24 files each holding one hour of this machine's hook calls. The
|
|
217
|
+
# first writer into a slot on a new day truncates it instead of appending —
|
|
218
|
+
# detected by reading the slot's first line, which is a builtin read (no stat,
|
|
219
|
+
# no rm, no find, no cron). Two writers can race that truncation and lose a
|
|
220
|
+
# line or two at an hour boundary; that is acceptable for a sampling diagnostic.
|
|
221
|
+
local f="$dir/h$hour.log" first="" line
|
|
222
|
+
# THE SLOT MUST BE AN ORDINARY FILE, OR NOT EXIST YET (security review, #4848).
|
|
223
|
+
# Anything else is a silent no-op. Two concrete failures if this check is
|
|
224
|
+
# dropped: a FIFO at the slot makes the `read` below block until the hook's
|
|
225
|
+
# settings.json timeout kills it, and a PreToolUse guard killed that way loses
|
|
226
|
+
# its exit 2 — the command it meant to block then runs; a symlink at the slot
|
|
227
|
+
# sends the day-rollover truncation onto the symlink's target. The `-e || -L`
|
|
228
|
+
# wrapper is what lets a not-yet-created slot through (-e is false for a
|
|
229
|
+
# dangling symlink, so -L is needed to catch that case too).
|
|
230
|
+
if [ -e "$f" ] || [ -L "$f" ]; then
|
|
231
|
+
[ -f "$f" ] && [ ! -L "$f" ] || return 0
|
|
232
|
+
fi
|
|
233
|
+
[ -r "$f" ] && { read -r first < "$f"; } 2>/dev/null
|
|
234
|
+
printf -v line '%s dur_us=%s hook=%s event=%s ppid=%s tool=%s\n' \
|
|
235
|
+
"$stamp" "$dur" "${MXHT_HOOK:--}" "${MXHT_EVENT:--}" "$PPID" "${MXHT_TOOL:--}"
|
|
236
|
+
# One printf of ~90 bytes to an O_APPEND fd is atomic under PIPE_BUF, so
|
|
237
|
+
# concurrent hooks cannot interleave partial lines.
|
|
238
|
+
# The 2>/dev/null wraps the GROUP, not the printf: a failing redirection is
|
|
239
|
+
# reported by the shell before an inner 2>/dev/null would be in effect, and a
|
|
240
|
+
# "Permission denied" on stderr from a PreToolUse hook is surfaced to the model.
|
|
241
|
+
if [ "${first%% *}" = "${stamp%% *}" ]; then
|
|
242
|
+
{ printf '%s' "$line" >>"$f"; } 2>/dev/null
|
|
243
|
+
else
|
|
244
|
+
{ printf '%s' "$line" >"$f"; } 2>/dev/null
|
|
245
|
+
fi
|
|
246
|
+
}
|
|
247
|
+
# `|| :` IS LOAD-BEARING — do not simplify to `trap _mxht_emit EXIT`. The hooks
|
|
248
|
+
# this block is inlined into run under `set -e`, and the EXIT trap runs with
|
|
249
|
+
# errexit still in force. Without `|| :`, a non-zero return from the probe — the
|
|
250
|
+
# final printf failing on an unwritable slot is the reachable case — replaces the
|
|
251
|
+
# hook's own exit status: a PreToolUse guard's exit 2 becomes exit 1, which the
|
|
252
|
+
# harness reads as "error", not "block", so the command it meant to block runs.
|
|
253
|
+
# Pinned verbatim by hook-timing-parity.test.sh.
|
|
254
|
+
trap '_mxht_emit || :' EXIT
|
|
255
|
+
# <<< SHARED hook-timing probe v1
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
set -uo pipefail
|
|
259
|
+
# NO `set -e` HERE, and the shared probe block above says "the hooks this block is
|
|
260
|
+
# inlined into run under `set -e`". That sentence is inaccurate for TWELVE of the
|
|
261
|
+
# sixteen instrumented hooks, this one included; only four set -e. Counted with
|
|
262
|
+
# `grep -LE '^set -[a-z]*e'` over the list in hook-timing-parity.test.sh. It is NOT corrected
|
|
263
|
+
# in place: hook-timing-parity.test.sh pins the block byte-for-byte across all 16
|
|
264
|
+
# instrumented hooks, so editing it here alone fails that gate, and editing all 16
|
|
265
|
+
# is a fleet-wide change that needs its own review. The `|| :` on the EXIT trap
|
|
266
|
+
# stays verbatim regardless — under `-uo pipefail` it is harmless, and it is what
|
|
267
|
+
# keeps a failing probe from replacing this guard's exit 2 with exit 1 in the hooks
|
|
268
|
+
# that DO set -e. Recorded here so the inaccuracy is known rather than unnoticed.
|
|
269
|
+
|
|
270
|
+
# Read stdin with the bash redirection builtin rather than `cat`. A hook whose
|
|
271
|
+
# very first statement needs an external binary cannot fail in a controlled way
|
|
272
|
+
# when the thing that is broken is the environment itself: with PATH unset or
|
|
273
|
+
# wrong, `cat` exits 127 and the hook exits 127 with it, which the harness reads
|
|
274
|
+
# as "error" and not as "block".
|
|
275
|
+
INPUT=$(</dev/stdin)
|
|
276
|
+
|
|
277
|
+
# ── caller identity ───────────────────────────────────────────────────────────
|
|
278
|
+
# Three states, see FAILURE DIRECTION in the header. AGENT_ID is read only as a
|
|
279
|
+
# 0/1 branch selector and is NEVER printed: harness-supplied text must not reach
|
|
280
|
+
# another agent's context through a refusal message.
|
|
281
|
+
IS_SUBAGENT=0
|
|
282
|
+
ENVELOPE_OK=0
|
|
283
|
+
COMMAND=""
|
|
284
|
+
JQ_OK=0
|
|
285
|
+
if command -v jq >/dev/null 2>&1; then
|
|
286
|
+
JQ_OK=1
|
|
287
|
+
fi
|
|
288
|
+
|
|
289
|
+
if [[ $JQ_OK -eq 1 ]]; then
|
|
290
|
+
if printf '%s' "$INPUT" | jq -e 'type == "object" and (has("session_id") or has("hook_event_name"))' >/dev/null 2>&1; then
|
|
291
|
+
ENVELOPE_OK=1
|
|
292
|
+
fi
|
|
293
|
+
AGENT_ID=$(printf '%s' "$INPUT" | jq -r '.agent_id // empty' 2>/dev/null) || AGENT_ID=""
|
|
294
|
+
# `if`, not `[[ ... ]] && VAR=1` — never leave a failing test as the last
|
|
295
|
+
# statement in reach of a non-zero exit.
|
|
296
|
+
if [[ -n "$AGENT_ID" ]]; then
|
|
297
|
+
IS_SUBAGENT=1
|
|
298
|
+
fi
|
|
299
|
+
COMMAND=$(printf '%s' "$INPUT" | jq -r '.tool_input.command // .command // empty' 2>/dev/null) || COMMAND=""
|
|
300
|
+
fi
|
|
301
|
+
|
|
302
|
+
# MAIN THREAD → ALLOW, silently, before any scanning. This is the half of the
|
|
303
|
+
# ruling that a permissions.deny entry cannot express.
|
|
304
|
+
if [[ $ENVELOPE_OK -eq 1 && $IS_SUBAGENT -eq 0 ]]; then
|
|
305
|
+
exit 0
|
|
306
|
+
fi
|
|
307
|
+
|
|
308
|
+
# --- backslash line-continuation folding -------------------------------------
|
|
309
|
+
# `gh pr \<newline> merge 1` is ONE command to the shell and two records to awk,
|
|
310
|
+
# so every downstream matcher sees `gh pr` and `merge 1` separately and neither
|
|
311
|
+
# matches. Fold the continuations first. Found by the security review of 4dd3212.
|
|
312
|
+
fold_continuations() {
|
|
313
|
+
sed -e :a -e '/\\$/N; s/\\\n[[:space:]]*/ /; ta' 2>/dev/null || true
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
# --- heredoc-body stripping (consumer-aware AND expansion-aware) -------------
|
|
317
|
+
# Three outcomes for a body, not two:
|
|
318
|
+
# keepbody 1 the CONSUMER executes it (bash/sh/zsh/dash/ksh/eval/source/`.`,
|
|
319
|
+
# or a pipe into one). Every line is kept.
|
|
320
|
+
# keepbody 2 the consumer does not execute it, but the delimiter is UNQUOTED,
|
|
321
|
+
# so the SHELL expands it first. Only the lines carrying `$(` or a
|
|
322
|
+
# backtick are kept.
|
|
323
|
+
# keepbody 0 the delimiter is quoted (<<'EOF' or <<"EOF"), so the body is
|
|
324
|
+
# inert text. Dropped whole.
|
|
325
|
+
# The operator line itself is always preserved.
|
|
326
|
+
#
|
|
327
|
+
# This no longer mirrors git-mutation-guard.sh and gh-pr-edit-guard.sh, which
|
|
328
|
+
# still carry the two-outcome shape. That divergence is deliberate and is tracked
|
|
329
|
+
# in #49; nothing pins these functions across the three files.
|
|
330
|
+
strip_heredocs() {
|
|
331
|
+
awk '
|
|
332
|
+
!inbody {
|
|
333
|
+
line = $0
|
|
334
|
+
if (match(line, /<<[-]?[[:space:]]*["'"'"']?[A-Za-z_][A-Za-z0-9_]*["'"'"']?/)) {
|
|
335
|
+
d = substr(line, RSTART, RLENGTH)
|
|
336
|
+
# ORDER IS LOAD-BEARING. Read the quoting off the RAW match, BEFORE the
|
|
337
|
+
# two gsubs below strip the quotes out of d. Computed after them this test
|
|
338
|
+
# is always true, and the <<QUOTED bodies the shell leaves inert would be
|
|
339
|
+
# scanned as if they expanded.
|
|
340
|
+
unquoted = (d !~ /["'"'"']/)
|
|
341
|
+
gsub(/<<[-]?[[:space:]]*["'"'"']?/, "", d)
|
|
342
|
+
gsub(/["'"'"'].*/, "", d)
|
|
343
|
+
delim = d
|
|
344
|
+
inbody = 1
|
|
345
|
+
keepbody = 0
|
|
346
|
+
if (line ~ /(^|[^[:alnum:]_])(bash|sh|zsh|dash|ksh|eval|source)([^[:alnum:]_]|$)/) keepbody = 1
|
|
347
|
+
if (line ~ /(^|[[:space:]])\.[[:space:]]/) keepbody = 1
|
|
348
|
+
if (line ~ /\|[^|]*(bash|sh|zsh|dash|ksh|eval)([^[:alnum:]_]|$)/) keepbody = 1
|
|
349
|
+
# WHO EXECUTES THE BODY IS TWO QUESTIONS, NOT ONE. The three tests above
|
|
350
|
+
# ask whether the CONSUMER runs the body. They never asked whether the
|
|
351
|
+
# SHELL expands it first. With an unquoted delimiter bash performs command
|
|
352
|
+
# substitution on every body line before the consumer sees anything, so
|
|
353
|
+
# `cat <<EOF` holding `$(gh pr merge 1)` runs the merge and hands cat the
|
|
354
|
+
# output. Measured on f90382b: that form, the <<-EOF form, the backtick
|
|
355
|
+
# form, `cat > f <<EOF` and `tee f <<EOF` were all allowed, while the
|
|
356
|
+
# shell expanded every one of them. keepbody 2 keeps ONLY the lines that
|
|
357
|
+
# carry a substitution, so a heredoc of plain prose naming a refused
|
|
358
|
+
# command stays allowed and the invariant in ACCEPTED COST holds again.
|
|
359
|
+
if (keepbody == 0 && unquoted) keepbody = 2
|
|
360
|
+
}
|
|
361
|
+
print line
|
|
362
|
+
next
|
|
363
|
+
}
|
|
364
|
+
{
|
|
365
|
+
t = $0
|
|
366
|
+
gsub(/^[[:space:]]+/, "", t)
|
|
367
|
+
if (t == delim) { inbody = 0; keepbody = 0; next }
|
|
368
|
+
if (keepbody == 1) print $0
|
|
369
|
+
else if (keepbody == 2 && ($0 ~ /\$\(/ || $0 ~ /`/)) print $0
|
|
370
|
+
}
|
|
371
|
+
' 2>/dev/null || true
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
# --- segment split + sink-scoped quote blanking -------------------------------
|
|
375
|
+
# Emits one command segment per line, splitting on unquoted `;` `&&` `||` `|`.
|
|
376
|
+
# Segments whose leading command is a text SINK have their quoted content
|
|
377
|
+
# blanked, so prose that merely mentions `gh pr edit` is not mistaken for an
|
|
378
|
+
# invocation. `gh` itself counts as a sink only for its own --body/--title/
|
|
379
|
+
# --comment ARGUMENT text; the segment's own `gh pr edit ...` words are outside
|
|
380
|
+
# the quotes and still scanned, so `gh pr edit --body "x"` is still blocked
|
|
381
|
+
# while `gh pr comment 1 --body "use gh pr edit"` is not.
|
|
382
|
+
split_segments() {
|
|
383
|
+
awk '
|
|
384
|
+
function get_lead_cmd(seg, s) {
|
|
385
|
+
s = seg; gsub(/^[[:space:]]+/, "", s)
|
|
386
|
+
while (match(s, /^[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*[[:space:]]+/))
|
|
387
|
+
s = substr(s, RSTART + RLENGTH)
|
|
388
|
+
while (match(s, /^[0-9]*[<>][>&]?[^[:space:]]*[[:space:]]+/))
|
|
389
|
+
s = substr(s, RSTART + RLENGTH)
|
|
390
|
+
if (match(s, /^[^[:space:]]+/)) return substr(s, RSTART, RLENGTH)
|
|
391
|
+
return ""
|
|
392
|
+
}
|
|
393
|
+
function check_sink(seg, cmd, s, sc) {
|
|
394
|
+
# A COMMAND SUBSTITUTION IS NEVER TEXT. This clause runs FIRST, before any
|
|
395
|
+
# carrier is recognised, and it is the whole reason blanking was unsafe: the
|
|
396
|
+
# blanker erases a quoted region, and `$( )` or a backtick inside that region
|
|
397
|
+
# is text to the blanker and an executed command to the shell. So
|
|
398
|
+
# `echo "$(gh pr merge 1)"` merged the pull request while this function
|
|
399
|
+
# classified it as prose. Measured on 6d6249c for echo, printf, cat, tee,
|
|
400
|
+
# git commit -m, gh --body and the backtick form: all seven allowed. The
|
|
401
|
+
# degraded no-jq branch does no blanking and caught every one of them, so the
|
|
402
|
+
# guard was WEAKER with jq than without. Returning 0 here means "not a sink",
|
|
403
|
+
# which leaves the quotes intact and lets the matcher see the invocation.
|
|
404
|
+
if (seg ~ /\$\(/ || seg ~ /`/) return 0
|
|
405
|
+
cmd = get_lead_cmd(seg)
|
|
406
|
+
if (cmd == "echo" || cmd == "printf" || cmd == "cat" || cmd == "tee" || cmd == "write")
|
|
407
|
+
return 1
|
|
408
|
+
# PATTERN CARRIERS. These take their argument as a pattern or a literal and
|
|
409
|
+
# never execute it. Without them a subagent cannot search for, or record, the
|
|
410
|
+
# name of a command this guard refuses.
|
|
411
|
+
if (cmd == "grep" || cmd == "rg" || cmd == "jq")
|
|
412
|
+
return 1
|
|
413
|
+
# THE MEMORY PATH. AGENTS.md makes MemNexus the sole memory store, so a
|
|
414
|
+
# memory-creator recording the lesson about this guard has to be able to name
|
|
415
|
+
# the command in --content. Measured on 6d6249c: it could not.
|
|
416
|
+
if ((cmd == "mx" || cmd == "mx-agent") && (seg ~ /--content/ || seg ~ /--body/ || seg ~ /--query/))
|
|
417
|
+
return 1
|
|
418
|
+
if (cmd == "gh" && (seg ~ /--body/ || seg ~ /--title/ || seg ~ /--comment/))
|
|
419
|
+
return 1
|
|
420
|
+
if (cmd == "git") {
|
|
421
|
+
s = seg; gsub(/^[[:space:]]+/, "", s); sub(/^git[[:space:]]+/, "", s)
|
|
422
|
+
while (match(s, /^(-C[[:space:]]+[^[:space:]]+|-c[[:space:]]+[^[:space:]]+|--[a-z][-a-z0-9]*(=[^[:space:]]*)?)[[:space:]]+/))
|
|
423
|
+
s = substr(s, RSTART + RLENGTH)
|
|
424
|
+
if (match(s, /^[^[:space:]]+/)) {
|
|
425
|
+
sc = substr(s, RSTART, RLENGTH)
|
|
426
|
+
if ((sc == "commit" || sc == "tag" || sc == "notes") && \
|
|
427
|
+
(seg ~ /-[a-zA-Z]*m[[:space:]]/ || seg ~ /--message/))
|
|
428
|
+
return 1
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return 0
|
|
432
|
+
}
|
|
433
|
+
function blank_quotes(seg, n, i, c, out, isq, idq) {
|
|
434
|
+
n = length(seg); out = ""; isq = 0; idq = 0
|
|
435
|
+
for (i = 1; i <= n; i++) {
|
|
436
|
+
c = substr(seg, i, 1)
|
|
437
|
+
if (isq) {
|
|
438
|
+
if (c == "'"'"'") { isq = 0; out = out c } else out = out " "
|
|
439
|
+
continue
|
|
440
|
+
}
|
|
441
|
+
if (idq) {
|
|
442
|
+
if (c == "\\") { out = out " "; i++; continue }
|
|
443
|
+
if (c == "\"") { idq = 0; out = out c } else out = out " "
|
|
444
|
+
continue
|
|
445
|
+
}
|
|
446
|
+
if (c == "'"'"'") { isq = 1; out = out c; continue }
|
|
447
|
+
if (c == "\"") { idq = 1; out = out c; continue }
|
|
448
|
+
out = out c
|
|
449
|
+
}
|
|
450
|
+
return out
|
|
451
|
+
}
|
|
452
|
+
{
|
|
453
|
+
line = $0; n = length(line)
|
|
454
|
+
isq = 0; idq = 0; num = 0; seg_s = 1
|
|
455
|
+
for (i = 1; i <= n; i++) {
|
|
456
|
+
c = substr(line, i, 1)
|
|
457
|
+
if (isq) { if (c == "'"'"'") isq = 0; continue }
|
|
458
|
+
if (idq) { if (c == "\\") { i++; continue }; if (c == "\"") idq = 0; continue }
|
|
459
|
+
if (c == "'"'"'") { isq = 1; continue }
|
|
460
|
+
if (c == "\"") { idq = 1; continue }
|
|
461
|
+
sp = 0; sl = 1
|
|
462
|
+
if (c == ";") sp = 1
|
|
463
|
+
else if (c == "&" && i < n && substr(line, i+1, 1) == "&") { sp = 1; sl = 2 }
|
|
464
|
+
else if (c == "|" && i < n && substr(line, i+1, 1) == "|") { sp = 1; sl = 2 }
|
|
465
|
+
else if (c == "|") sp = 1
|
|
466
|
+
if (sp) {
|
|
467
|
+
num++; segs[num] = substr(line, seg_s, i - seg_s)
|
|
468
|
+
seg_s = i + sl; if (sl == 2) i++
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
num++; segs[num] = substr(line, seg_s)
|
|
472
|
+
for (s = 1; s <= num; s++) {
|
|
473
|
+
if (check_sink(segs[s])) print blank_quotes(segs[s])
|
|
474
|
+
else print segs[s]
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
' 2>/dev/null || true
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
# Reduce untrusted command text to something safe to print back: first line
|
|
481
|
+
# only, control characters and non-ASCII removed, truncated. The command arrives
|
|
482
|
+
# from the model and is echoed into a message another agent reads.
|
|
483
|
+
sanitize() {
|
|
484
|
+
printf '%s' "$1" \
|
|
485
|
+
| head -n 1 \
|
|
486
|
+
| LC_ALL=C tr -d '\000-\037\177' \
|
|
487
|
+
| LC_ALL=C tr -c 'A-Za-z0-9 _.,:/=@+~^-' '?' \
|
|
488
|
+
| cut -c1-200
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
refuse() {
|
|
492
|
+
local family="$1" reason="$2" safe_cmd
|
|
493
|
+
safe_cmd="$(sanitize "$COMMAND")"
|
|
494
|
+
[[ -n "$safe_cmd" ]] || safe_cmd="(unavailable: the hook payload could not be parsed)"
|
|
495
|
+
{
|
|
496
|
+
echo ""
|
|
497
|
+
echo "BLOCKED: $family"
|
|
498
|
+
echo " Command: $safe_cmd"
|
|
499
|
+
echo ""
|
|
500
|
+
if [[ "$reason" == "subagent" ]]; then
|
|
501
|
+
echo "WHY: this tool call comes from a DISPATCHED SUBAGENT. Product-owner ruling,"
|
|
502
|
+
echo "2026-08-21 (#12): a subagent does not merge the pull request, and the team lead"
|
|
503
|
+
echo "does. Merging, approving, requesting changes, closing an issue, and writing"
|
|
504
|
+
echo "through the API are the lead's to take from the main session. A subagent that"
|
|
505
|
+
echo "graded the change must not also be able to act on its own verdict, and a"
|
|
506
|
+
echo "subagent that read an instruction planted in a pull request must not be able to"
|
|
507
|
+
echo "merge that pull request."
|
|
508
|
+
else
|
|
509
|
+
echo "WHY: this hook could not establish whether the call comes from the main session"
|
|
510
|
+
echo "or from a dispatched subagent. The harness sets agent_id only inside a subagent,"
|
|
511
|
+
echo "and reading it needs a parseable payload and jq. Neither was available here, so"
|
|
512
|
+
echo "the absence of agent_id proves nothing. A guard that cannot tell who is asking"
|
|
513
|
+
echo "does not answer yes to an irreversible action."
|
|
514
|
+
echo ""
|
|
515
|
+
echo "If jq is missing from this environment, that is the thing to fix:"
|
|
516
|
+
echo " command -v jq"
|
|
517
|
+
fi
|
|
518
|
+
echo ""
|
|
519
|
+
echo "WHAT TO DO INSTEAD:"
|
|
520
|
+
echo " Report the state to your team lead and stop: which pull request, what the"
|
|
521
|
+
echo " checks say, and what you would do. The lead runs the merge from the main"
|
|
522
|
+
echo " session."
|
|
523
|
+
echo " Read forms are untouched: gh pr view, gh pr checks, gh pr diff, gh api (GET),"
|
|
524
|
+
echo " gh issue view. gh pr comment and gh pr create are untouched too."
|
|
525
|
+
echo ""
|
|
526
|
+
} >&2
|
|
527
|
+
exit 2
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
# ── matching ──────────────────────────────────────────────────────────────────
|
|
531
|
+
# `gh` must START a command segment: at start-of-line (segments are emitted one
|
|
532
|
+
# per line), after a separator, or after a shell keyword — optionally preceded by
|
|
533
|
+
# leading redirections, env-var assignments, and launcher words that exec their
|
|
534
|
+
# argv, and optionally by a path whose final component is `gh`. Mirrors
|
|
535
|
+
# gh-pr-edit-guard.sh's GHSEG, deliberately: the guards should agree about what
|
|
536
|
+
# counts as an invocation rather than a mention (the loose-match failure is
|
|
537
|
+
# #4804).
|
|
538
|
+
# The segment-anchored GHPFX and its four RE_* patterns lived here until the
|
|
539
|
+
# fourth security pass found them unreferenced. After the main thread was moved to
|
|
540
|
+
# an early exit, nothing evaluated them: the subagent path uses SUB_*, the
|
|
541
|
+
# degraded path uses RAW_*, and both are unanchored. Deleted rather than kept,
|
|
542
|
+
# because a reader finding a precise pattern in the file reasonably concludes
|
|
543
|
+
# something precise is being done with it.
|
|
544
|
+
|
|
545
|
+
# DEGRADED-MODE regexes. The anchored prefix above cannot be used on raw stdin:
|
|
546
|
+
# the text there is JSON, so an invocation reads `"command":"gh pr merge 1"` and
|
|
547
|
+
# the character before `gh` is a double quote, which is not a segment boundary in
|
|
548
|
+
# any shell. Matching the raw payload with GHPFX therefore matches nothing, which
|
|
549
|
+
# is a fail-OPEN in the one branch that exists to fail closed. Found by the
|
|
550
|
+
# absent-identity case in subagent-write-guard.test.sh, which the first draft of
|
|
551
|
+
# this file passed by allowing the merge. These accept any non-word character
|
|
552
|
+
# before `gh`, which also matches prose that quotes the command. That
|
|
553
|
+
# over-matching is the intended direction for a degraded environment.
|
|
554
|
+
GHRAW='(^|[^A-Za-z0-9_-])([^[:space:]";&|]*/)?gh[[:space:]]+'
|
|
555
|
+
RAW_MERGE="${GHRAW}pr[[:space:]]+merge([^A-Za-z0-9_-]|\$)"
|
|
556
|
+
RAW_REVIEW="${GHRAW}pr[[:space:]]+review([^A-Za-z0-9_-]|\$)"
|
|
557
|
+
RAW_ICLOSE="${GHRAW}issue[[:space:]]+close([^A-Za-z0-9_-]|\$)"
|
|
558
|
+
RAW_API="${GHRAW}api([^A-Za-z0-9_-]|\$)"
|
|
559
|
+
|
|
560
|
+
# SUBAGENT-BRANCH regexes. Same unanchored idea as the degraded ones, plus a run
|
|
561
|
+
# of closing punctuation after `gh`, so a command-substitution launcher is caught:
|
|
562
|
+
# in `$(which gh) pr merge 1` the character after `gh` is `)`, and without this
|
|
563
|
+
# class the `gh[[:space:]]+pr` requirement fails and the merge is allowed. Covers
|
|
564
|
+
# the backtick and quoted forms for the same reason. See MATCHING IS ASYMMETRIC.
|
|
565
|
+
GHSUB="(^|[^A-Za-z0-9_-])([^[:space:]\";&|]*/)?gh[)}\"'\`]*[[:space:]]+"
|
|
566
|
+
SUB_MERGE="${GHSUB}pr[[:space:]]+merge([^A-Za-z0-9_-]|\$)"
|
|
567
|
+
SUB_REVIEW="${GHSUB}pr[[:space:]]+review([^A-Za-z0-9_-]|\$)"
|
|
568
|
+
SUB_ICLOSE="${GHSUB}issue[[:space:]]+close([^A-Za-z0-9_-]|\$)"
|
|
569
|
+
SUB_API="${GHSUB}api([^A-Za-z0-9_-]|\$)"
|
|
570
|
+
|
|
571
|
+
# Everything after the matched subcommand, as argv-ish tokens. Quoted text inside
|
|
572
|
+
# sink commands is blanked upstream, so a `-h` inside a message body cannot reach
|
|
573
|
+
# here.
|
|
574
|
+
TAIL_RE='([^[:space:];&|]*/)?gh[[:space:]]+(pr[[:space:]]+(merge|review)|issue[[:space:]]+close|api)([[:space:]]+(.*))?$'
|
|
575
|
+
|
|
576
|
+
# `--help`/`-h` as the FIRST token after the subcommand prints usage and makes no
|
|
577
|
+
# API call. Only that position is allowed: a `-h` anywhere in the tail used to
|
|
578
|
+
# wave through `gh pr edit 4785 --body-file b.md -h` in the neighbouring guard
|
|
579
|
+
# (SF-4), and the same trick must not work here.
|
|
580
|
+
is_help_first() {
|
|
581
|
+
local tail="$1"
|
|
582
|
+
# shellcheck disable=SC2206 # deliberate word-splitting: this is argv, not a path
|
|
583
|
+
local toks=($tail)
|
|
584
|
+
[[ ${#toks[@]} -gt 0 ]] || return 1
|
|
585
|
+
[[ "${toks[0]}" == "--help" || "${toks[0]}" == "-h" ]]
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
# Effective HTTP method for `gh api`. See `gh api` METHOD INFERENCE in the header.
|
|
589
|
+
# Returns 0 when the call writes.
|
|
590
|
+
api_writes() {
|
|
591
|
+
local tail="$1" tok method="" want_method=0 saw_field=0
|
|
592
|
+
# shellcheck disable=SC2206 # deliberate word-splitting: this is argv, not a path
|
|
593
|
+
local toks=($tail)
|
|
594
|
+
for tok in ${toks[@]+"${toks[@]}"}; do
|
|
595
|
+
if [[ $want_method -eq 1 ]]; then
|
|
596
|
+
method="$tok"; want_method=0; continue
|
|
597
|
+
fi
|
|
598
|
+
case "$tok" in
|
|
599
|
+
-X|--method) want_method=1 ;;
|
|
600
|
+
--method=*) method="${tok#--method=}" ;;
|
|
601
|
+
-X?*) method="${tok#-X}" ;;
|
|
602
|
+
-f|-F|--field|--raw-field|--input) saw_field=1 ;;
|
|
603
|
+
-f*|-F*|--field=*|--raw-field=*|--input=*) saw_field=1 ;;
|
|
604
|
+
esac
|
|
605
|
+
done
|
|
606
|
+
if [[ -n "$method" ]]; then
|
|
607
|
+
# A named method decides, fields or not.
|
|
608
|
+
[[ "$(printf '%s' "$method" | tr '[:lower:]' '[:upper:]')" != "GET" ]]
|
|
609
|
+
return $?
|
|
610
|
+
fi
|
|
611
|
+
# No named method: gh sends POST when a field flag is present, GET otherwise.
|
|
612
|
+
[[ $saw_field -eq 1 ]]
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if [[ $JQ_OK -eq 0 || $ENVELOPE_OK -eq 0 ]]; then
|
|
616
|
+
# DEGRADED SCAN. No parse, so no segment splitting and no tail: any raw text
|
|
617
|
+
# matching a refused family is refused. Over-matching is the intended direction
|
|
618
|
+
# here; see FAILURE DIRECTION in the header.
|
|
619
|
+
SCAN_RAW=" $INPUT"
|
|
620
|
+
if printf '%s' "$SCAN_RAW" | grep -qE "$RAW_MERGE"; then
|
|
621
|
+
refuse "gh pr merge" "indeterminate"
|
|
622
|
+
elif printf '%s' "$SCAN_RAW" | grep -qE "$RAW_REVIEW"; then
|
|
623
|
+
refuse "gh pr review" "indeterminate"
|
|
624
|
+
elif printf '%s' "$SCAN_RAW" | grep -qE "$RAW_ICLOSE"; then
|
|
625
|
+
refuse "gh issue close" "indeterminate"
|
|
626
|
+
elif printf '%s' "$SCAN_RAW" | grep -qE "$RAW_API"; then
|
|
627
|
+
# No tail parse is possible here, so every `gh api` form is refused,
|
|
628
|
+
# including a GET. A read the lead can repeat is the cheap side of this.
|
|
629
|
+
refuse "gh api" "indeterminate"
|
|
630
|
+
fi
|
|
631
|
+
exit 0
|
|
632
|
+
fi
|
|
633
|
+
|
|
634
|
+
# Subagent, parseable payload. Nothing to scan without a command — a Bash call
|
|
635
|
+
# with no command string cannot be one of the four.
|
|
636
|
+
if [[ -z "$COMMAND" ]]; then
|
|
637
|
+
exit 0
|
|
638
|
+
fi
|
|
639
|
+
|
|
640
|
+
SCAN=$(printf '%s' "$COMMAND" | fold_continuations | strip_heredocs)
|
|
641
|
+
|
|
642
|
+
while IFS= read -r seg; do
|
|
643
|
+
[[ -n "$seg" ]] || continue
|
|
644
|
+
|
|
645
|
+
GH_TAIL=""
|
|
646
|
+
TAIL_READ=0
|
|
647
|
+
if [[ "$seg" =~ $TAIL_RE ]]; then
|
|
648
|
+
GH_TAIL="${BASH_REMATCH[5]}"
|
|
649
|
+
TAIL_READ=1
|
|
650
|
+
fi
|
|
651
|
+
|
|
652
|
+
if printf '%s' "$seg" | grep -qE "$SUB_MERGE"; then
|
|
653
|
+
is_help_first "$GH_TAIL" || refuse "gh pr merge" "subagent"
|
|
654
|
+
elif printf '%s' "$seg" | grep -qE "$SUB_REVIEW"; then
|
|
655
|
+
is_help_first "$GH_TAIL" || refuse "gh pr review" "subagent"
|
|
656
|
+
elif printf '%s' "$seg" | grep -qE "$SUB_ICLOSE"; then
|
|
657
|
+
is_help_first "$GH_TAIL" || refuse "gh issue close" "subagent"
|
|
658
|
+
elif printf '%s' "$seg" | grep -qE "$SUB_API"; then
|
|
659
|
+
is_help_first "$GH_TAIL" && continue
|
|
660
|
+
# The method comes from the tail. GHSUB matches invocation forms that TAIL_RE
|
|
661
|
+
# cannot split, `$(which gh) api ...` among them, and an unread tail means the
|
|
662
|
+
# method is unknown. Unknown is not GET.
|
|
663
|
+
if [[ $TAIL_READ -eq 0 ]]; then
|
|
664
|
+
refuse "gh api, with a method that could not be read" "subagent"
|
|
665
|
+
fi
|
|
666
|
+
api_writes "$GH_TAIL" && refuse "gh api, with a method other than GET" "subagent"
|
|
667
|
+
fi
|
|
668
|
+
done < <(printf '%s\n' "$SCAN" | split_segments)
|
|
669
|
+
|
|
670
|
+
exit 0
|