@amsterdamdatalabs/adl-agent-control-darwin-arm64 0.1.48 → 0.1.54
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/bin/adl +1 -1
- package/bin/lean-ctx-observe-strip +434 -0
- package/bin/lib/lean-ctx-observe-hooks.sh +634 -0
- package/bin/reconcile +45 -0
- package/bin/repo-search-mcp +4 -0
- package/bin/update-azure-agent-pool +29 -0
- package/package.json +3 -2
- package/packages/agent-hooks/src/hooks/lean-ctx/handler.ts +22 -0
- package/packages/agent-hooks/src/hooks/lean-ctx/index.ts +173 -0
- package/packages/agent-hooks/src/hooks/lean-ctx/mapping.ts +121 -0
- package/packages/agent-hooks/src/hooks/lean-ctx/scope-rewrite.ts +207 -0
- package/packages/agent-hooks/src/lean-ctx/env.ts +123 -0
- package/packages/agent-hooks/src/lean-ctx/mcp.ts +142 -0
- package/packages/agent-hooks/src/rules/impl/adl-build-run-denied.ts +51 -0
- package/packages/agent-hooks/src/rules/impl/adl-git-push-policy.ts +25 -1
- package/packages/agent-hooks/src/rules/impl/adl-session-required.ts +403 -0
- package/packages/agent-hooks/src/rules/impl/adl-worktree.ts +51 -0
- package/packages/agent-hooks/src/rules/impl/git-target.ts +13 -0
- package/packages/agent-hooks/src/rules/impl/tool-lean-ctx-global.ts +594 -0
- package/packages/agent-hooks/src/rules/registry.ts +4 -0
- package/packages/agent-hooks/src/rules/shell/invocation.ts +38 -0
- package/packages/agent-settings/assets/GLOBAL-AGENTS.md +112 -0
- package/packages/agent-settings/assets/lean-ctx/config.toml +42 -0
- package/packages/agent-settings/assets/lean-ctx/gitignore +10 -0
- package/packages/agent-settings/assets/lean-ctx/layout.toml +7 -0
- package/packages/agent-settings/assets/mcp.json +3 -0
- package/packages/agent-settings/src/deploy/lean-ctx-deploy.ts +230 -0
- package/packages/agent-settings/src/deploy/lean-ctx-merge.ts +580 -0
- package/packages/agent-settings/src/deploy/mcp-source.ts +6 -5
- package/packages/agent-skills/assets/adl-mechanics/SKILL.md +38 -0
- package/packages/agent-skills/assets/codebase-design/SKILL.md +98 -0
- package/packages/agent-skills/assets/codebase-design/references/DEEPENING.md +37 -0
- package/packages/agent-skills/assets/codebase-design/references/DESIGN-IT-TWICE.md +44 -0
- package/packages/agent-skills/assets/codebase-design/references/TESTABILITY.md +29 -0
- package/packages/agent-skills/assets/debug-issue/SKILL.md +41 -0
- package/packages/agent-skills/assets/domain-modeling/SKILL.md +86 -0
- package/packages/agent-skills/assets/domain-modeling/references/ADR-FORMAT.md +47 -0
- package/packages/agent-skills/assets/domain-modeling/references/CONTEXT-FORMAT.md +60 -0
- package/packages/agent-skills/assets/implement/SKILL.md +28 -0
- package/packages/agent-skills/assets/review-changes/SKILL.md +45 -0
- package/packages/agent-skills/assets/tdd/SKILL.md +49 -0
- package/packages/agent-skills/assets/tdd/references/mocking.md +59 -0
- package/packages/agent-skills/assets/tdd/references/tests.md +77 -0
- package/packages/agent-skills/assets/testing/SKILL.md +54 -0
- package/packages/agent-skills/assets/testing/references/e2e.md +37 -0
- package/packages/agent-skills/assets/testing/references/integration.md +37 -0
- package/packages/agent-skills/assets/testing/references/unit.md +32 -0
- package/packages/agent-skills/assets/to-feature/SKILL.md +91 -0
- package/packages/agent-skills/assets/to-feature/references/FEATURE-SPEC-TEMPLATE.md +88 -0
- package/packages/agent-skills/assets/to-workitems/SKILL.md +90 -0
- package/packages/agent-skills/assets/to-workitems/references/AZURE-DEVOPS-HIERARCHY.md +121 -0
- package/packages/agent-skills/assets/to-workitems/references/TICKET-TEMPLATES.md +70 -0
- package/packages/azdo/src/workflow-rules-matrix.csv +85 -0
- package/packages/fleet/manifest.json +2 -0
- package/packages/fleet/src/install-adl-package.ts +30 -23
- package/packages/fleet/src/launch-agents.ts +649 -0
- package/packages/repo-controls/README.md +11 -7
- package/packages/repo-controls/assets/GLOBAL-INVARIANTS.md +21 -0
- package/packages/repo-controls/assets/enable-integration-auto-complete.mjs +79 -0
- package/packages/repo-controls/assets/scaffold/docs/notes.md +20 -0
- package/packages/repo-controls/assets/scaffold/plans/GAPS-AND-FINDINGS.md +12 -0
- package/packages/repo-controls/azure-pipelines.yml +274 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/closed_set/fixtures/docs/notes.md +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/english_only/fixtures/excluded/frontend/mobile/src/i18n/locales/zh-CN/strings.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/okf_profile/fixtures/okf-ledger-clean/docs/notes.md +17 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/okf_profile/fixtures/okf-ledger-no-lines/docs/notes.md +13 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/semantics/fixtures/semantics-violations/docs/architecture/product/stable-delivery.md +10 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/semantics/fixtures/semantics-violations/docs/architecture/product/stable-recommendation.md +12 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/docs/semantics/fixtures/semantics-violations/docs/architecture/product/target-narration.md +10 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-clean/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-empty-register/frontend/packages/desktop/src/a.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-empty-register/frontend/packages/desktop/src/b.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/fresh/fresh.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub1/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub10/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub11/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub2/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub3/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub4/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub5/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub6/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub7/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub8/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/many/sub9/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/services/i18n/locales/de/common.json +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-excluded/frontend/packages/desktop/src/vendored-crate/Cargo.toml +2 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-missing-tree/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-no-ceilings/frontend/packages/desktop/src/a.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-no-ceilings/frontend/packages/desktop/src/b.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-no-ceilings/frontend/packages/desktop/src/c.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-stale-entry/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/fresh/fresh.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub1/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub10/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub11/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub2/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub3/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub4/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub5/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub6/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub7/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub8/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/many/sub9/only.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unbaselined/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/directory_ratchet/fixtures/directory-ratchet-unusable-register/frontend/packages/desktop/src/renderer/solo/item.ts +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/open_work_cap/fixtures/open-work-cap-clean/plans/GAPS-AND-FINDINGS.md +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/open_work_cap/fixtures/open-work-cap-clean/plans/features/az601-clean/spec.md +10 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/agent/crates/enact-providers/src/snapshots/README.md +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/backend/crates/enact-app/assets/builtin-assistants/avatars/assistant.jpg +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/backend/crates/enact-assets/assets/logos/tools/coding/tool.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/backend/crates/enact-session/src/backend/codex_init_prompt.md +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/frontend/mobile/assets/images/icon.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/frontend/packages/desktop/src/renderer/assets/logos/brand/app.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/frontend/packages/desktop/src/renderer/assets/themes/default-theme.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/frontend/public/pwa/icon-192.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-allowed/frontend/resources/product.png +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/placement/fixtures/placement-stray/backend/crates/enact-session/src/backend/README.md +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/plans_layout/fixtures/plans-layout-clean/plans/features/az347-test-coverage/spec.md +12 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/plans_layout/fixtures/plans-layout-violation/plans/features/az347-test-coverage/spec.md +12 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/__init__.py +11 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/check.py +62 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/NotAMigration.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/0001_long_prefix.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/001_init.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/002_add_index.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/003-dashed-slug.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/004_MixedCase.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/005_trailing space.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/01_short_prefix.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/fixtures/migration-filenames/backend/crates/demo/migrations/not-a-migration.sql +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/profile_data/test_check.py +116 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/references/fixtures/link-targets-broken/docs/architecture/product/links.md +20 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/references/fixtures/link-targets-broken/docs/architecture/product/route-target.md +8 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/references/fixtures/link-targets-clean/docs/architecture/product/links.md +20 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/references/fixtures/link-targets-clean/docs/architecture/product/route-target.md +8 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/root_closed_set/fixtures/.changeset/declared.txt +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/layout/root_markdown_allowlist/fixtures/root-markdown-clean/INDEPENDENT-VERIFICATION.md +3 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/attribute-without-conversion/.gitattributes +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/attribute-without-conversion/large file.bin +3 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/clean/.gitattributes +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/clean/large file.bin +3 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/clean/small.txt +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/missing-filter/large file.bin +0 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/unmatched-extension/.gitattributes +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/lfs/integrity/fixtures/unmatched-extension/payload.dat +0 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/__init__.py +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/__init__.py +12 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/check.py +129 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/fixtures/disjoint/gate-registry.yaml +13 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/fixtures/empty/gate-registry.yaml +7 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/fixtures/overlapping/gate-registry.yaml +13 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/pipeline/phase_disjoint/test_check.py +109 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/__init__.py +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/changeset_plan/__init__.py +11 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/changeset_plan/check.py +149 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/changeset_plan/fixtures/clean/docs/readme.md +4 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/changeset_plan/fixtures/relevant/VERSION +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/changeset_plan/test_check.py +151 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/__init__.py +11 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/check.py +202 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/aligned/.workflows/changesets/package.json +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/aligned/.workflows/package.json +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/aligned/CHANGELOG.md +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/aligned/VERSION +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/mismatched/.workflows/changesets/package.json +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/mismatched/.workflows/package.json +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/mismatched/CHANGELOG.md +5 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/fixtures/mismatched/VERSION +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/release/version_release/test_check.py +162 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/banned_commands/check.py +103 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/clean/backend/Cargo.lock +7 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/clean/backend/Cargo.toml +4 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/clean/backend/rust-toolchain.toml +3 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/clean/backend/src/main.rs +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/clean/frontend/bun.lock +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/empty-bun-lock/backend/Cargo.lock +7 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/empty-bun-lock/backend/Cargo.toml +4 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/empty-bun-lock/backend/rust-toolchain.toml +3 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/empty-bun-lock/backend/src/main.rs +1 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/checks/repository/lockfile_integrity/fixtures/empty-bun-lock/frontend/bun.lock +0 -0
- package/packages/repo-controls/package/adl-compliance/src/adl_compliance/policy/grants-registry.yaml +112 -0
- package/packages/repo-controls/scripts/hooks/pre-push +76 -8
- package/packages/repo-controls/src/findings-ratchet.ts +9 -1
- package/packages/repo-controls/src/hook.ts +73 -21
- package/packages/repo-controls/workflows/scripts/release/verify-npm-artifact.ts +119 -0
package/bin/reconcile
CHANGED
|
@@ -1043,6 +1043,26 @@ install_one_tool() {
|
|
|
1043
1043
|
echo "using installed package payload: $repo_root"
|
|
1044
1044
|
return 0
|
|
1045
1045
|
fi
|
|
1046
|
+
# repo-search-mcp ships in the same published package as adl (PBI az712), so
|
|
1047
|
+
# it follows the adl source-mode split: checkout builds the binary from the
|
|
1048
|
+
# checkout, npm uses (and links) the installed package payload.
|
|
1049
|
+
if [[ "$tool_id" == repo-search-mcp && "$source_mode" == checkout ]]; then
|
|
1050
|
+
echo "ensure repo-search-mcp from explicit checkout source: $repo_root"
|
|
1051
|
+
build_checkout_repo_search_mcp || rc=1
|
|
1052
|
+
if [[ "$mode" == apply && "$rc" -eq 0 ]]; then
|
|
1053
|
+
command -v "$executable" >/dev/null 2>&1 || { echo "ERROR checkout repo-search-mcp executable missing from PATH: $executable" >&2; rc=1; }
|
|
1054
|
+
fi
|
|
1055
|
+
return "$rc"
|
|
1056
|
+
fi
|
|
1057
|
+
if [[ "$tool_id" == repo-search-mcp && "$source_mode" == npm ]]; then
|
|
1058
|
+
if [[ "$mode" != apply ]]; then
|
|
1059
|
+
echo "would use installed package payload: $repo_root"
|
|
1060
|
+
return 0
|
|
1061
|
+
fi
|
|
1062
|
+
adl_package_owns_executable || return 1
|
|
1063
|
+
echo "using installed package payload: $repo_root"
|
|
1064
|
+
return 0
|
|
1065
|
+
fi
|
|
1046
1066
|
echo "ensure latest stable: $tool_id ($manager:$package)"
|
|
1047
1067
|
case "$manager" in
|
|
1048
1068
|
brew)
|
|
@@ -1368,6 +1388,30 @@ build_checkout_adl() {
|
|
|
1368
1388
|
return "$rc"
|
|
1369
1389
|
}
|
|
1370
1390
|
|
|
1391
|
+
# az712: the repo-search MCP server, compiled from the checkout exactly like
|
|
1392
|
+
# adl above. HEAD tree hash (not the worktree) so the gitignored dist/ build
|
|
1393
|
+
# output never perturbs the up-to-date check.
|
|
1394
|
+
build_checkout_repo_search_mcp() {
|
|
1395
|
+
local source_dir="packages/repo-search" entry="src/mcp-server.ts" target="/usr/local/bin/repo-search-mcp" source_hash hash_file rc=0
|
|
1396
|
+
source_hash="$(bun_source_hash "$source_dir")" || return 1
|
|
1397
|
+
hash_file="$(bun_source_hash_file repo-search-mcp)"
|
|
1398
|
+
if [[ -x "$target" && -f "$hash_file" && "$(cat "$hash_file")" == "$source_hash" ]]; then
|
|
1399
|
+
echo "checkout repo-search-mcp binary already up to date (source $source_hash)"
|
|
1400
|
+
return 0
|
|
1401
|
+
fi
|
|
1402
|
+
run_bun_compile repo-search-mcp "$source_hash" "$source_dir" "$entry" "$target" || rc=1
|
|
1403
|
+
if [[ "$mode" == apply && "$rc" -eq 0 ]]; then
|
|
1404
|
+
[[ -x "$target" ]] || { echo "ERROR checkout repo-search-mcp executable missing: $target" >&2; rc=1; }
|
|
1405
|
+
if [[ "$rc" -eq 0 ]]; then
|
|
1406
|
+
mkdir -p "${hash_file%/*}"
|
|
1407
|
+
printf '%s\n' "$source_hash" >"$hash_file.new"
|
|
1408
|
+
mv -f "$hash_file.new" "$hash_file"
|
|
1409
|
+
echo "built checkout repo-search-mcp binary: $target (source $source_hash)"
|
|
1410
|
+
fi
|
|
1411
|
+
fi
|
|
1412
|
+
return "$rc"
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1371
1415
|
# embedding-model installs the enact-embedding static (Model2Vec) artifact
|
|
1372
1416
|
# that adl hook's (the folded-in hook engine's) skill-match hook loads
|
|
1373
1417
|
# from the administrator's cache.
|
|
@@ -2853,6 +2897,7 @@ project_adl_package_payload() {
|
|
|
2853
2897
|
echo "would project Adl package payload from $repo_root to /usr/local/libexec/adl and /usr/local/bin/git{,-ado}"
|
|
2854
2898
|
if [[ "$source_mode" == npm ]]; then
|
|
2855
2899
|
echo "would link /usr/local/bin/adl to $repo_root/bin/adl"
|
|
2900
|
+
echo "would link /usr/local/bin/repo-search-mcp to $repo_root/bin/repo-search-mcp"
|
|
2856
2901
|
fi
|
|
2857
2902
|
return 0
|
|
2858
2903
|
fi
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
export PATH="/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
|
|
5
|
+
|
|
6
|
+
manifest="${1:-}"
|
|
7
|
+
[[ -f "$manifest" ]] || { echo "usage: update-azure-agent-pool MANIFEST" >&2; exit 2; }
|
|
8
|
+
|
|
9
|
+
organization="$(jq -r '.config.azure_agents.organization' "$manifest")"
|
|
10
|
+
pool_id="$(jq -r '.config.azure_agents.pool_id' "$manifest")"
|
|
11
|
+
api_root="https://dev.azure.com/$organization/_apis/distributedtask/pools/$pool_id"
|
|
12
|
+
|
|
13
|
+
token="$(az account get-access-token \
|
|
14
|
+
--resource 499b84ac-1321-427f-aa17-267ca6975798 \
|
|
15
|
+
--query accessToken -o tsv)"
|
|
16
|
+
[[ -n "$token" ]] || { echo "Azure CLI did not return an Azure DevOps token" >&2; exit 1; }
|
|
17
|
+
auth_args=(-H "Authorization: Bearer $token")
|
|
18
|
+
|
|
19
|
+
agents_file="$(mktemp)"
|
|
20
|
+
trap 'rm -f "$agents_file"' EXIT
|
|
21
|
+
curl -fsS "${auth_args[@]}" "$api_root/agents?api-version=7.1" >"$agents_file"
|
|
22
|
+
|
|
23
|
+
while IFS= read -r agent_name; do
|
|
24
|
+
agent_id="$(jq -r --arg name "$agent_name" '.value[] | select(.name == $name) | .id' "$agents_file")"
|
|
25
|
+
[[ -n "$agent_id" ]] || { echo "configured Azure agent not found: $agent_name" >&2; exit 1; }
|
|
26
|
+
curl -fsS "${auth_args[@]}" -X POST -H 'Content-Length: 0' \
|
|
27
|
+
"$api_root/messages?agentId=$agent_id&api-version=6.0" >/dev/null
|
|
28
|
+
echo "Azure Pipelines agent update requested: $agent_name (id $agent_id)"
|
|
29
|
+
done < <(jq -r '.config.azure_agents.enabled_agents[]' "$manifest")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amsterdamdatalabs/adl-agent-control-darwin-arm64",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54",
|
|
4
4
|
"description": "adl CLI binary for darwin/arm64 (agent identity + Azure DevOps front door — see docs/architecture/cli-design.md)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"os": [
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"packages/azdo"
|
|
22
22
|
],
|
|
23
23
|
"bin": {
|
|
24
|
-
"adl": "bin/adl"
|
|
24
|
+
"adl": "bin/adl",
|
|
25
|
+
"repo-search-mcp": "bin/repo-search-mcp"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@iarna/toml": "^2.2.5",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `main.ts`-facing entry point for the `lean-ctx` hook kind's
|
|
3
|
+
* `pre-tool-use` / `post-tool-use` subcommands.
|
|
4
|
+
*
|
|
5
|
+
* Thin wiring only, mirroring `../briefing/handler.ts` and `../crg/handler.ts`:
|
|
6
|
+
* the actual logic lives in `./index.ts`, built against an injectable
|
|
7
|
+
* `Runner` so it can be unit-tested without a real `lean-ctx` binary. This
|
|
8
|
+
* file wires that logic to the production, timeout-enforcing `bunRunner`.
|
|
9
|
+
*
|
|
10
|
+
* `main.ts` never routes a `subcommand: 'mcp'` invocation here — see
|
|
11
|
+
* `../../lean-ctx/mcp.ts`'s header for why that subcommand is dispatched
|
|
12
|
+
* entirely separately, before `main.ts`'s standard JSON-payload flow.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { HookInvocation, HookResult } from '../contract.ts'
|
|
16
|
+
import { bunRunner, createLeanCtxHandler } from './index.ts'
|
|
17
|
+
|
|
18
|
+
const leanCtxHandler = createLeanCtxHandler({ run: bunRunner })
|
|
19
|
+
|
|
20
|
+
export async function handleLeanCtx(inv: HookInvocation): Promise<HookResult> {
|
|
21
|
+
return leanCtxHandler(inv)
|
|
22
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `lean-ctx` hook kind's `pre-tool-use` / `post-tool-use` subcommands:
|
|
3
|
+
* `adl hook lean-ctx pre-tool-use --host=X` / `post-tool-use --host=X`
|
|
4
|
+
* (work item A.2). The `mcp` subcommand is NOT handled here — it is a true
|
|
5
|
+
* stdio-passthrough, long-running MCP server, dispatched straight out of
|
|
6
|
+
* `main.ts` (see `../../lean-ctx/mcp.ts`) before the standard
|
|
7
|
+
* read-stdin-as-one-JSON-payload / `HookHandler` machinery this file uses
|
|
8
|
+
* ever runs.
|
|
9
|
+
*
|
|
10
|
+
* Gating (managed repo + `[hooks] enabled`, silent no-op otherwise) is
|
|
11
|
+
* `main.ts`'s job, identical to every other kind — see its header. This
|
|
12
|
+
* handler only has to:
|
|
13
|
+
*
|
|
14
|
+
* 1. Read the invoking tool's name out of the payload (the same field every
|
|
15
|
+
* host spells `tool_name` for a PreToolUse/PostToolUse call — see
|
|
16
|
+
* `../../pre-tool-use/handler.ts`'s `toDecideInput` for the reference
|
|
17
|
+
* this mirrors).
|
|
18
|
+
* 2. Map (host, direction, tool name) to a `lean-ctx hook <subcommand>` via
|
|
19
|
+
* `./mapping.ts`. No match (kimi/opencode always; any host+tool this
|
|
20
|
+
* task's mapping table does not name) is a SILENT no-op — exit 0, empty
|
|
21
|
+
* stdout/stderr, no `lean-ctx` spawn at all.
|
|
22
|
+
* 3. Spawn `lean-ctx hook <subcommand>` with the payload JSON on stdin and
|
|
23
|
+
* the shared `LEAN_CTX_*` env (`../../lean-ctx/env.ts`), and relay its
|
|
24
|
+
* stdout/stderr/exit code VERBATIM — lean-ctx speaks each host's own
|
|
25
|
+
* hook protocol (deny/rewrite/redirect envelopes) itself, so this must
|
|
26
|
+
* not reinterpret or reshape what it returns.
|
|
27
|
+
*
|
|
28
|
+
* Two exceptions to "relay verbatim":
|
|
29
|
+
*
|
|
30
|
+
* - A hung or missing `lean-ctx` (`status: null` — see `Runner`'s doc) must
|
|
31
|
+
* never block the calling host's tool-call loop, so that degrades to exit 0
|
|
32
|
+
* with a stderr note instead of whatever `lean-ctx` would have returned had
|
|
33
|
+
* it run — same fail-open shape `../briefing/index.ts` and
|
|
34
|
+
* `../crg/index.ts` already use for their own subprocess calls.
|
|
35
|
+
* - A `rewrite` envelope's REPLACEMENT command is re-scoped by
|
|
36
|
+
* `./scope-rewrite.ts` (G1). lean-ctx rewrites the host's command into one
|
|
37
|
+
* that re-execs lean-ctx by absolute path, and the host runs that in the
|
|
38
|
+
* HOST's env — which carries none of the four `LEAN_CTX_*` dir vars set for
|
|
39
|
+
* the child above, so the process that actually ENFORCES silently falls back
|
|
40
|
+
* to built-in defaults instead of the repo's `config.toml`. Prefixing the
|
|
41
|
+
* four assignments onto that command is the narrowest place to fix it: the
|
|
42
|
+
* envelope's shape, decision and every other field are untouched, and any
|
|
43
|
+
* non-rewrite output is returned as the identical string.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
import type { HookHandler, HookInvocation, HookResult } from '../contract.ts'
|
|
47
|
+
import { leanCtxEnvFor } from '../../lean-ctx/env.ts'
|
|
48
|
+
import { spawnWithTimeout } from '../../lib/spawn-with-timeout.ts'
|
|
49
|
+
import { leanCtxSubcommand, type LeanCtxDirection } from './mapping.ts'
|
|
50
|
+
import { scopeRewrittenCommand, sessionIdentityOf } from './scope-rewrite.ts'
|
|
51
|
+
|
|
52
|
+
export interface RunResult {
|
|
53
|
+
readonly status: number | null
|
|
54
|
+
readonly stdout: string
|
|
55
|
+
readonly stderr: string
|
|
56
|
+
/** `true` only when the spawn was killed for exceeding `timeoutMs`. */
|
|
57
|
+
readonly timedOut?: boolean
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface RunOptions {
|
|
61
|
+
readonly cwd: string
|
|
62
|
+
readonly env: Readonly<Record<string, string | undefined>>
|
|
63
|
+
readonly input?: string
|
|
64
|
+
readonly timeoutMs?: number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Process spawning, injected so tests never need a real `lean-ctx` binary. */
|
|
68
|
+
export type Runner = (cmd: string, args: readonly string[], opts: RunOptions) => Promise<RunResult>
|
|
69
|
+
|
|
70
|
+
const BIN = 'lean-ctx'
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* lean-ctx's own PreToolUse/PostToolUse hook subcommands (rewrite, redirect,
|
|
74
|
+
* deny, read-dedup, codex-pretooluse) are simple synchronous lookups/string
|
|
75
|
+
* transforms in the real binary — generous, but well under the host's own
|
|
76
|
+
* tool-call timeout, matching `../crg/index.ts`'s reasoning for its own
|
|
77
|
+
* default.
|
|
78
|
+
*/
|
|
79
|
+
const DEFAULT_TIMEOUT_MS = 10_000
|
|
80
|
+
|
|
81
|
+
/** The tool-name field every host's PreToolUse/PostToolUse payload carries — see `../../pre-tool-use/handler.ts`'s `toDecideInput`. */
|
|
82
|
+
function toolNameOf(payload: Record<string, unknown>): string | null {
|
|
83
|
+
const name = payload.tool_name
|
|
84
|
+
return typeof name === 'string' && name.length > 0 ? name : null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function directionOf(subcommand: string | undefined): LeanCtxDirection | null {
|
|
88
|
+
if (subcommand === 'pre-tool-use') return 'pre'
|
|
89
|
+
if (subcommand === 'post-tool-use') return 'post'
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function silentNoop(): HookResult {
|
|
94
|
+
return { stdout: '', stderr: '', exitCode: 0 }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createLeanCtxHandler(deps: { run: Runner }): HookHandler {
|
|
98
|
+
return async (inv: HookInvocation): Promise<HookResult> => {
|
|
99
|
+
const direction = directionOf(inv.subcommand)
|
|
100
|
+
if (direction === null) {
|
|
101
|
+
return {
|
|
102
|
+
stdout: '',
|
|
103
|
+
stderr: `adl hook: lean-ctx: unknown subcommand: ${String(inv.subcommand)} (expected mcp | pre-tool-use | post-tool-use)\n`,
|
|
104
|
+
exitCode: 1,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const toolName = toolNameOf(inv.payload)
|
|
109
|
+
if (toolName === null) {
|
|
110
|
+
inv.record?.({ reason: 'SKIP no tool_name in payload' })
|
|
111
|
+
return silentNoop()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const subcommand = leanCtxSubcommand(inv.host, direction, toolName)
|
|
115
|
+
if (subcommand === null) {
|
|
116
|
+
inv.record?.({ reason: `SKIP no lean-ctx hook for ${toolName}` })
|
|
117
|
+
return silentNoop()
|
|
118
|
+
}
|
|
119
|
+
const downstream = `${BIN} hook ${subcommand}`
|
|
120
|
+
|
|
121
|
+
const result = await deps.run(BIN, ['hook', subcommand], {
|
|
122
|
+
cwd: inv.root,
|
|
123
|
+
env: leanCtxEnvFor(inv.root, inv.env),
|
|
124
|
+
input: JSON.stringify(inv.payload),
|
|
125
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
if (result.status === null) {
|
|
129
|
+
const reason = result.stderr.trim() || (result.timedOut ? `${BIN} timed out after ${DEFAULT_TIMEOUT_MS}ms` : `${BIN} not found on PATH`)
|
|
130
|
+
const stderr = `lean-ctx ${inv.subcommand} (${subcommand}): ${reason}\n`
|
|
131
|
+
inv.record?.({ reason: `${result.timedOut ? 'TIMEOUT' : 'ERROR'} ${downstream}`, message: stderr.trim(), downstream })
|
|
132
|
+
return { stdout: '', stderr, exitCode: 0 }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
inv.record?.({ reason: result.status === 0 ? 'PASS' : `ERROR exit=${result.status}`, message: result.stderr.trim(), downstream })
|
|
136
|
+
// 2026-09-28: the session identity rides into the rewrite envelope too —
|
|
137
|
+
// see `./scope-rewrite.ts`'s header for the two-envelope race this closes.
|
|
138
|
+
return { stdout: scopeRewrittenCommand(result.stdout, inv.root, sessionIdentityOf(inv.env)), stderr: result.stderr, exitCode: result.status }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The production `Runner`: a real, timeout-enforcing subprocess via
|
|
144
|
+
* `spawnWithTimeout` (see `../../lib/spawn-with-timeout.ts`), resolving
|
|
145
|
+
* `lean-ctx` off `PATH` — the same shape `../briefing/index.ts` and
|
|
146
|
+
* `../crg/index.ts` already use for their own production runners.
|
|
147
|
+
*/
|
|
148
|
+
export const bunRunner: Runner = async (cmd, args, opts) => {
|
|
149
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
150
|
+
try {
|
|
151
|
+
const result = await spawnWithTimeout(cmd, args, {
|
|
152
|
+
cwd: opts.cwd,
|
|
153
|
+
env: opts.env,
|
|
154
|
+
timeoutMs,
|
|
155
|
+
...(opts.input !== undefined ? { stdin: opts.input } : {}),
|
|
156
|
+
})
|
|
157
|
+
if (result.timedOut) {
|
|
158
|
+
return {
|
|
159
|
+
status: null,
|
|
160
|
+
stdout: result.stdout,
|
|
161
|
+
stderr: result.stderr.trim() || `${cmd} timed out after ${timeoutMs}ms`,
|
|
162
|
+
timedOut: true,
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { status: result.exitCode, stdout: result.stdout, stderr: result.stderr }
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
168
|
+
return { status: null, stdout: '', stderr: message }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const handleLeanCtx: HookHandler = createLeanCtxHandler({ run: bunRunner })
|
|
173
|
+
export default handleLeanCtx
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (host, direction, tool name) → `lean-ctx hook <subcommand>` mapping.
|
|
3
|
+
*
|
|
4
|
+
* Ported 1:1 from enact-m5's real wiring — the source of truth is each
|
|
5
|
+
* host's own hooks config, read directly (this session, 2026-09-14):
|
|
6
|
+
*
|
|
7
|
+
* - `.claude/settings.json`: `PreToolUse` matcher `"Bash|bash"` →
|
|
8
|
+
* `lean-ctx-local hook rewrite`; matcher
|
|
9
|
+
* `"Read|read|ReadFile|read_file|View|view|Grep|grep|Search|search|
|
|
10
|
+
* ListFiles|list_files|ListDirectory|list_directory|Glob|glob"` →
|
|
11
|
+
* `hook redirect`. `PostToolUse` matcher `"Read"` → `hook read-dedup`.
|
|
12
|
+
* - `.cursor/hooks.json`: see the CURSOR CORRECTION note below — the
|
|
13
|
+
* original port's matcher strings here were wrong; this describes the
|
|
14
|
+
* corrected mapping actually implemented in `CURSOR` below.
|
|
15
|
+
* `preToolUse` matcher `"Shell"` → `hook rewrite`; matcher `"Grep"` →
|
|
16
|
+
* `hook deny`; matcher `"Read"` → `hook redirect`; matcher `"Write"` →
|
|
17
|
+
* `hook deny`. No `postToolUse` bucket at all.
|
|
18
|
+
* - `.codex/hooks.json`: `PreToolUse` matcher `"Bash|Read|Grep|Glob"` →
|
|
19
|
+
* `lean-ctx-local hook codex-pretooluse`. No `PostToolUse` lean-ctx entry.
|
|
20
|
+
* - kimi, opencode: no lean-ctx wiring in either host's config at all — a
|
|
21
|
+
* lean-ctx pre/post-tool-use invocation for these hosts is always a
|
|
22
|
+
* no-op.
|
|
23
|
+
*
|
|
24
|
+
* Each host's matcher is a regex tested against the payload's tool name; the
|
|
25
|
+
* task's own wording ("match anchored as those hosts do") reflects that
|
|
26
|
+
* every one of these host matchers is an untagged alternation with no
|
|
27
|
+
* partial-match intent (`Bash|bash`, not `.*Bash.*`) — every spelling below
|
|
28
|
+
* is therefore matched as an exact, case-sensitive string against the tool
|
|
29
|
+
* name, never a substring or prefix test.
|
|
30
|
+
*
|
|
31
|
+
* CURSOR CORRECTION (this session, 2026-09-14, verified against
|
|
32
|
+
* https://cursor.com/docs/agent/hooks): the `CURSOR` table below used to
|
|
33
|
+
* carry Claude-vocabulary tool names — `Glob` alongside `Grep`, and
|
|
34
|
+
* `StrReplace`/`Write`/`Edit`/`EditNotebook`/`MultiEdit` all denied — none of
|
|
35
|
+
* which are real Cursor tool names. The docs' "Matcher Patterns" section
|
|
36
|
+
* states verbatim: "preToolUse / postToolUse / postToolUseFailure: Filter by
|
|
37
|
+
* tool type. Values include Shell, Read, Write, Grep, Delete, Task, and MCP
|
|
38
|
+
* tools using the MCP:<tool_name> format." That is Cursor's *complete*
|
|
39
|
+
* `tool_name` vocabulary for these two events — there is no `Glob`,
|
|
40
|
+
* `StrReplace`, `Edit`, `EditNotebook`, or `MultiEdit` in it. `CURSOR` below
|
|
41
|
+
* is corrected to that vocabulary: `Shell` → rewrite, `Grep` → deny (no
|
|
42
|
+
* separate glob-like tool exists to also deny), `Read` → redirect, `Write` →
|
|
43
|
+
* deny (the one edit-like tool Cursor actually has). `Delete`, `Task`, and
|
|
44
|
+
* any `MCP:<tool_name>` call are intentionally left unmapped (no-op, same as
|
|
45
|
+
* any tool name absent from a route's set) — enact-m5's real wiring never
|
|
46
|
+
* named them for lean-ctx.
|
|
47
|
+
*
|
|
48
|
+
* A `preToolUse` payload's `tool_name` field (matched above) is documented
|
|
49
|
+
* alongside `tool_input`, e.g. `{"tool_name": "Shell", "tool_input":
|
|
50
|
+
* {"command": "npm install", "working_directory": "/project"}, ...}` — see
|
|
51
|
+
* `../../pre-tool-use/handler.ts`'s `toDecideInput` for where the sibling
|
|
52
|
+
* `tool_input.command` field (and `beforeShellExecution`'s top-level
|
|
53
|
+
* `command`) get read.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
import type { HostId } from '../contract.ts'
|
|
57
|
+
|
|
58
|
+
export type LeanCtxDirection = 'pre' | 'post'
|
|
59
|
+
|
|
60
|
+
interface ToolRoute {
|
|
61
|
+
readonly subcommand: string
|
|
62
|
+
readonly tools: ReadonlySet<string>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type HostRoutes = Readonly<Record<LeanCtxDirection, readonly ToolRoute[]>>
|
|
66
|
+
|
|
67
|
+
const CLAUDE: HostRoutes = {
|
|
68
|
+
pre: [
|
|
69
|
+
{ subcommand: 'rewrite', tools: new Set(['Bash', 'bash']) },
|
|
70
|
+
{
|
|
71
|
+
subcommand: 'redirect',
|
|
72
|
+
tools: new Set([
|
|
73
|
+
'Read', 'read', 'ReadFile', 'read_file', 'View', 'view',
|
|
74
|
+
'Grep', 'grep', 'Search', 'search',
|
|
75
|
+
'ListFiles', 'list_files', 'ListDirectory', 'list_directory',
|
|
76
|
+
'Glob', 'glob',
|
|
77
|
+
]),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
post: [{ subcommand: 'read-dedup', tools: new Set(['Read']) }],
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const CURSOR: HostRoutes = {
|
|
84
|
+
pre: [
|
|
85
|
+
{ subcommand: 'rewrite', tools: new Set(['Shell']) },
|
|
86
|
+
{ subcommand: 'deny', tools: new Set(['Grep']) },
|
|
87
|
+
{ subcommand: 'redirect', tools: new Set(['Read']) },
|
|
88
|
+
{ subcommand: 'deny', tools: new Set(['Write']) },
|
|
89
|
+
],
|
|
90
|
+
post: [],
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const CODEX: HostRoutes = {
|
|
94
|
+
pre: [{ subcommand: 'codex-pretooluse', tools: new Set(['Bash', 'Read', 'Grep', 'Glob']) }],
|
|
95
|
+
post: [],
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const NONE: HostRoutes = { pre: [], post: [] }
|
|
99
|
+
|
|
100
|
+
const ROUTES: Readonly<Record<HostId, HostRoutes>> = {
|
|
101
|
+
claude: CLAUDE,
|
|
102
|
+
cursor: CURSOR,
|
|
103
|
+
codex: CODEX,
|
|
104
|
+
kimi: NONE,
|
|
105
|
+
opencode: NONE,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Resolve which `lean-ctx hook <subcommand>` a (host, direction, tool name)
|
|
110
|
+
* triple maps to, or `null` when nothing matches — the caller's no-op case
|
|
111
|
+
* (kimi/opencode always, and any tool name not named in the host's own
|
|
112
|
+
* matcher above, e.g. an Edit under Claude, which has no lean-ctx PreToolUse
|
|
113
|
+
* entry at all).
|
|
114
|
+
*/
|
|
115
|
+
export function leanCtxSubcommand(host: HostId, direction: LeanCtxDirection, toolName: string): string | null {
|
|
116
|
+
const routes = ROUTES[host][direction]
|
|
117
|
+
for (const route of routes) {
|
|
118
|
+
if (route.tools.has(toolName)) return route.subcommand
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* G1 — carry this package's `LEAN_CTX_*` scope across lean-ctx's own rewrite.
|
|
3
|
+
*
|
|
4
|
+
* `lean-ctx hook rewrite` does not return a decision about the host's command;
|
|
5
|
+
* it returns a REPLACEMENT command that re-execs lean-ctx by its own absolute
|
|
6
|
+
* path, e.g. `/usr/local/bin/lean-ctx -c 'trash /tmp/x'` or
|
|
7
|
+
* `/usr/local/bin/lean-ctx read README.md`. The host then runs that string in
|
|
8
|
+
* the HOST's environment.
|
|
9
|
+
*
|
|
10
|
+
* That is the whole bug. `./index.ts` spawns its own child with the four dir
|
|
11
|
+
* vars from `../../lean-ctx/env.ts`, so the child that makes the DECISION sees
|
|
12
|
+
* the repo's `config.toml` (249 commands). But the replacement command is
|
|
13
|
+
* executed by the host, whose environment carries only `LEAN_CTX_ACTIVE=1` and
|
|
14
|
+
* `LEAN_CTX_WRAPPED=1` — the two the wrapper sets for itself, measured on this
|
|
15
|
+
* machine — and never the four dir vars. So the process that ENFORCES resolves
|
|
16
|
+
* the global XDG path, finds no `config.toml`, and silently falls back to
|
|
17
|
+
* lean-ctx's 223 built-in defaults.
|
|
18
|
+
*
|
|
19
|
+
* The visible symptom is a deadlock between the two guards: `../../rules/` denies
|
|
20
|
+
* `rm` and directs the caller to `trash`, and `trash` is in the repo allowlist —
|
|
21
|
+
* but the unscoped re-exec answers "[BLOCKED — DO NOT RETRY] 'trash' is not in
|
|
22
|
+
* the shell allowlist", so neither verb works. Both halves were measured
|
|
23
|
+
* directly, 2026-09-15.
|
|
24
|
+
*
|
|
25
|
+
* Rooted at the caller's resolved git root, never `$PWD`. A `$PWD`-derived
|
|
26
|
+
* scope reports 249 at the repo root and 223 from `<repo>/.agents` with no
|
|
27
|
+
* error — one `cd` and the gate reverts to built-ins.
|
|
28
|
+
*
|
|
29
|
+
* Deliberately NOT solved with an env carrier in host config
|
|
30
|
+
* (`.claude/settings.local.json` and friends): Cursor's project config is
|
|
31
|
+
* permissions-only, Kimi reads a single user-level file, and Codex ignores
|
|
32
|
+
* `[shell_environment_policy] set` for untrusted projects — so a carrier
|
|
33
|
+
* cannot cover the hosts that need it. Rewriting the command reaches every
|
|
34
|
+
* host that honours the rewrite, which is exactly the set that has the bug.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { basename } from 'node:path'
|
|
38
|
+
import { leanCtxEnvFor } from '../../lean-ctx/env.ts'
|
|
39
|
+
import { resolveFromEnvOrFile } from '../../rules/impl/adl-identity.ts'
|
|
40
|
+
import { rewriteGitNetworkCommands } from '../../rules/shell/git-identity.ts'
|
|
41
|
+
|
|
42
|
+
/** The four dir vars, in the order they are prefixed. See `../../lean-ctx/env.ts`. */
|
|
43
|
+
const SCOPED_VARS = [
|
|
44
|
+
'LEAN_CTX_CONFIG_DIR',
|
|
45
|
+
'LEAN_CTX_DATA_DIR',
|
|
46
|
+
'LEAN_CTX_STATE_DIR',
|
|
47
|
+
'LEAN_CTX_CACHE_DIR',
|
|
48
|
+
] as const
|
|
49
|
+
|
|
50
|
+
/** Basename the replacement command must invoke for it to be lean-ctx's own re-exec. */
|
|
51
|
+
const WRAPPER = 'lean-ctx'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The three keys lean-ctx emits the replacement input under — one per host
|
|
55
|
+
* protocol dialect, all three in every rewrite envelope. Captured verbatim
|
|
56
|
+
* from the real v3.9.20 binary; all three must be scoped or a host reading
|
|
57
|
+
* the shape we skipped would run the command unscoped.
|
|
58
|
+
*/
|
|
59
|
+
const INPUT_PATHS: readonly (readonly string[])[] = [
|
|
60
|
+
['hookSpecificOutput', 'updatedInput'],
|
|
61
|
+
['modifiedArgs'],
|
|
62
|
+
['updated_input'],
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
/** POSIX single-quoting: wrap in `'…'`, and close/escape/reopen around any embedded `'`. */
|
|
66
|
+
function shellQuote(value: string): string {
|
|
67
|
+
return `'${value.replaceAll("'", "'\\''")}'`
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `VAR='…' VAR='…' …` for `root`, derived from the one shared env helper so there is a single source of truth. */
|
|
71
|
+
function scopePrefix(root: string): string {
|
|
72
|
+
const env = leanCtxEnvFor(root, {})
|
|
73
|
+
return SCOPED_VARS.map((name) => `${name}=${shellQuote(env[name] ?? '')}`).join(' ')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
77
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether `command` is lean-ctx re-execing itself, and so ours to scope.
|
|
82
|
+
*
|
|
83
|
+
* Matched on the first token's BASENAME, not a fixed `/usr/local/bin` path, so
|
|
84
|
+
* a non-standard install location still scopes. An already-scoped command
|
|
85
|
+
* fails this test — its first token is a `VAR=…` assignment — which is what
|
|
86
|
+
* makes this function idempotent; the explicit guard in `scopeRewrittenCommand`
|
|
87
|
+
* does not rely on that, so this can be relaxed without silently double-scoping.
|
|
88
|
+
*/
|
|
89
|
+
function isWrapperReexec(command: string): boolean {
|
|
90
|
+
const first = command.trimStart().split(/\s+/, 1)[0]
|
|
91
|
+
return first !== undefined && first.length > 0 && basename(first) === WRAPPER
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The EFFECTIVE identity to carry into git network commands inside a
|
|
96
|
+
* rewritten command — L3 (STATUS.md 12p): steps
|
|
97
|
+
* 2-3 of the standard, `../../rules/impl/adl-identity.ts`'s
|
|
98
|
+
* `resolveFromEnvOrFile` (the session env `ADL_AGENT_ID_AGENT`, else the
|
|
99
|
+
* machine default-agent file), not the session env var alone. This used to
|
|
100
|
+
* read only `currentAgent` — the raw env var — which meant a session whose
|
|
101
|
+
* identity resolved from the machine default-agent file (no
|
|
102
|
+
* `ADL_AGENT_ID_AGENT` in the environment at all, e.g. a surface without an
|
|
103
|
+
* `adl run --as` session) never got its lean-ctx `-c` re-exec's git network
|
|
104
|
+
* commands carried, even though every OTHER identity-bearing surface in
|
|
105
|
+
* this package (`../../pre-tool-use/handler.ts`'s rewrite, `../../rules/engine.ts`'s
|
|
106
|
+
* own rewrite stage) already falls back to that file. The lean-ctx hook
|
|
107
|
+
* kind runs in the same process the host spawned for `adl hook`, so
|
|
108
|
+
* `inv.env` is the session env `adl run` set — the same environment the
|
|
109
|
+
* rule engine resolves from.
|
|
110
|
+
*/
|
|
111
|
+
export function sessionIdentityOf(env: Readonly<Record<string, string | undefined>>): string | null {
|
|
112
|
+
const resolution = resolveFromEnvOrFile({ get: (name) => env[name] })
|
|
113
|
+
return resolution.ok ? resolution.agent : null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The machine-generated re-exec shapes lean-ctx emits for shell commands:
|
|
118
|
+
* `<binary> -c '<script>'` (single- or double-quoted, `-c` or `--command`,
|
|
119
|
+
* `=` or space separated). A non-shell rewrite (`lean-ctx read <path>`) has
|
|
120
|
+
* no script and is not matched.
|
|
121
|
+
*/
|
|
122
|
+
const REEXEC_SCRIPT_SINGLE = /^(\S+)\s+(?:-c|--command)(?:=|\s+)'((?:\\'|[^'])*)'\s*$/
|
|
123
|
+
const REEXEC_SCRIPT_DOUBLE = /^(\S+)\s+(?:-c|--command)(?:=|\s+)"((?:\\"|[^"])*)"\s*$/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Carry `identity` into the git network commands of the script inside a
|
|
127
|
+
* lean-ctx `-c` re-exec — one scanner (`rewriteGitNetworkCommands`), so the
|
|
128
|
+
* prefix is byte-identical to the one `adl hook pre-tool-use` puts on the
|
|
129
|
+
* native command. Returns the rebuilt command, or null when there is nothing
|
|
130
|
+
* to carry (no script, non-git script, already-carried idempotently, or a
|
|
131
|
+
* DENY outcome — a conflicting/unsafe inline identity is the pre-tool-use
|
|
132
|
+
* guard's deny, never rewritten over here).
|
|
133
|
+
*/
|
|
134
|
+
function carryIdentityIntoReexec(command: string, identity: string): string | null {
|
|
135
|
+
const match = REEXEC_SCRIPT_SINGLE.exec(command) ?? REEXEC_SCRIPT_DOUBLE.exec(command)
|
|
136
|
+
if (match === null) return null
|
|
137
|
+
const binary = match[1] as string
|
|
138
|
+
const script = match[2] as string
|
|
139
|
+
const outcome = rewriteGitNetworkCommands(script, identity)
|
|
140
|
+
if (outcome.kind !== 'rewrite') return null
|
|
141
|
+
return `${binary} -c ${shellQuote(outcome.command)}`
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Prefix the four dir vars onto every replacement command in a `lean-ctx hook`
|
|
146
|
+
* stdout envelope, so the re-exec'd lean-ctx resolves the same `config.toml`
|
|
147
|
+
* its parent did.
|
|
148
|
+
*
|
|
149
|
+
* Fail-open by construction: anything that is not a rewrite envelope carrying a
|
|
150
|
+
* lean-ctx re-exec — a deny, a plain allow, a non-JSON line, empty output — is
|
|
151
|
+
* returned as the IDENTICAL string. This sits in the hook's verbatim relay
|
|
152
|
+
* path, so it must never be the reason a host's tool call breaks.
|
|
153
|
+
*
|
|
154
|
+
* 2026-09-28 — the two-envelope race: on Claude/Codex/Cursor a native shell
|
|
155
|
+
* call gets TWO PreToolUse rewrites (this scope rewrite and the git-identity
|
|
156
|
+
* rewrite in `../../pre-tool-use`), and the host applies only one of them
|
|
157
|
+
* (Claude's hooks guide: "the last one to finish takes effect … the order is
|
|
158
|
+
* non-deterministic"; Codex/Cursor specify no arbitration). So when the
|
|
159
|
+
* session has an identity, the git network commands inside the `-c` script
|
|
160
|
+
* are prefixed here too — whichever envelope the host picks authenticates
|
|
161
|
+
* the push. Everything else about the envelope is unchanged.
|
|
162
|
+
*/
|
|
163
|
+
export function scopeRewrittenCommand(stdout: string, root: string, identity: string | null = null): string {
|
|
164
|
+
if (stdout.trim().length === 0) return stdout
|
|
165
|
+
|
|
166
|
+
let parsed: unknown
|
|
167
|
+
try {
|
|
168
|
+
parsed = JSON.parse(stdout)
|
|
169
|
+
} catch {
|
|
170
|
+
return stdout
|
|
171
|
+
}
|
|
172
|
+
if (!isRecord(parsed)) return stdout
|
|
173
|
+
|
|
174
|
+
const prefix = scopePrefix(root)
|
|
175
|
+
let changed = false
|
|
176
|
+
|
|
177
|
+
for (const path of INPUT_PATHS) {
|
|
178
|
+
let node: unknown = parsed
|
|
179
|
+
for (const segment of path) {
|
|
180
|
+
if (!isRecord(node)) {
|
|
181
|
+
node = undefined
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
node = node[segment]
|
|
185
|
+
}
|
|
186
|
+
if (!isRecord(node)) continue
|
|
187
|
+
|
|
188
|
+
const command = node.command
|
|
189
|
+
if (typeof command !== 'string' || command.length === 0) continue
|
|
190
|
+
if (command.startsWith(`${SCOPED_VARS[0]}=`)) continue
|
|
191
|
+
if (!isWrapperReexec(command)) continue
|
|
192
|
+
|
|
193
|
+
let next = command
|
|
194
|
+
if (identity !== null) {
|
|
195
|
+
const carried = carryIdentityIntoReexec(next, identity)
|
|
196
|
+
if (carried !== null) next = carried
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
node.command = `${prefix} ${next}`
|
|
200
|
+
changed = true
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!changed) return stdout
|
|
204
|
+
|
|
205
|
+
const trailing = stdout.slice(stdout.trimEnd().length)
|
|
206
|
+
return `${JSON.stringify(parsed)}${trailing}`
|
|
207
|
+
}
|