@swarmify/agents-cli 1.13.3 → 1.14.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/README.md +2 -319
- package/bin/agents.js +2 -0
- package/package.json +13 -79
- package/scripts/postinstall.js +4 -71
- package/CHANGELOG.md +0 -316
- package/LICENSE +0 -21
- package/dist/commands/__tests__/sessions-tail.test.d.ts +0 -2
- package/dist/commands/__tests__/sessions-tail.test.d.ts.map +0 -1
- package/dist/commands/__tests__/sessions-tail.test.js +0 -108
- package/dist/commands/__tests__/sessions-tail.test.js.map +0 -1
- package/dist/commands/__tests__/sessions.test.d.ts +0 -2
- package/dist/commands/__tests__/sessions.test.d.ts.map +0 -1
- package/dist/commands/__tests__/sessions.test.js +0 -636
- package/dist/commands/__tests__/sessions.test.js.map +0 -1
- package/dist/commands/cloud.d.ts +0 -11
- package/dist/commands/cloud.d.ts.map +0 -1
- package/dist/commands/cloud.js +0 -363
- package/dist/commands/cloud.js.map +0 -1
- package/dist/commands/commands.d.ts +0 -12
- package/dist/commands/commands.d.ts.map +0 -1
- package/dist/commands/commands.js +0 -629
- package/dist/commands/commands.js.map +0 -1
- package/dist/commands/daemon.d.ts +0 -11
- package/dist/commands/daemon.d.ts.map +0 -1
- package/dist/commands/daemon.js +0 -119
- package/dist/commands/daemon.js.map +0 -1
- package/dist/commands/drive.d.ts +0 -11
- package/dist/commands/drive.d.ts.map +0 -1
- package/dist/commands/drive.js +0 -175
- package/dist/commands/drive.js.map +0 -1
- package/dist/commands/exec.d.ts +0 -11
- package/dist/commands/exec.d.ts.map +0 -1
- package/dist/commands/exec.js +0 -251
- package/dist/commands/exec.js.map +0 -1
- package/dist/commands/factory.d.ts +0 -11
- package/dist/commands/factory.d.ts.map +0 -1
- package/dist/commands/factory.js +0 -445
- package/dist/commands/factory.js.map +0 -1
- package/dist/commands/fork.d.ts +0 -11
- package/dist/commands/fork.d.ts.map +0 -1
- package/dist/commands/fork.js +0 -147
- package/dist/commands/fork.js.map +0 -1
- package/dist/commands/hooks.d.ts +0 -12
- package/dist/commands/hooks.d.ts.map +0 -1
- package/dist/commands/hooks.js +0 -690
- package/dist/commands/hooks.js.map +0 -1
- package/dist/commands/init.d.ts +0 -15
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -137
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/mcp.d.ts +0 -12
- package/dist/commands/mcp.d.ts.map +0 -1
- package/dist/commands/mcp.js +0 -583
- package/dist/commands/mcp.js.map +0 -1
- package/dist/commands/models.d.ts +0 -11
- package/dist/commands/models.d.ts.map +0 -1
- package/dist/commands/models.js +0 -170
- package/dist/commands/models.js.map +0 -1
- package/dist/commands/packages.d.ts +0 -11
- package/dist/commands/packages.d.ts.map +0 -1
- package/dist/commands/packages.js +0 -551
- package/dist/commands/packages.js.map +0 -1
- package/dist/commands/permissions.d.ts +0 -12
- package/dist/commands/permissions.d.ts.map +0 -1
- package/dist/commands/permissions.js +0 -724
- package/dist/commands/permissions.js.map +0 -1
- package/dist/commands/plugins.d.ts +0 -11
- package/dist/commands/plugins.d.ts.map +0 -1
- package/dist/commands/plugins.js +0 -393
- package/dist/commands/plugins.js.map +0 -1
- package/dist/commands/profiles.d.ts +0 -12
- package/dist/commands/profiles.d.ts.map +0 -1
- package/dist/commands/profiles.js +0 -255
- package/dist/commands/profiles.js.map +0 -1
- package/dist/commands/pty.d.ts +0 -21
- package/dist/commands/pty.d.ts.map +0 -1
- package/dist/commands/pty.js +0 -391
- package/dist/commands/pty.js.map +0 -1
- package/dist/commands/pull.d.ts +0 -11
- package/dist/commands/pull.d.ts.map +0 -1
- package/dist/commands/pull.js +0 -456
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/push.d.ts +0 -11
- package/dist/commands/push.d.ts.map +0 -1
- package/dist/commands/push.js +0 -188
- package/dist/commands/push.js.map +0 -1
- package/dist/commands/refresh-memory.d.ts +0 -16
- package/dist/commands/refresh-memory.d.ts.map +0 -1
- package/dist/commands/refresh-memory.js +0 -52
- package/dist/commands/refresh-memory.js.map +0 -1
- package/dist/commands/resource-view.d.ts +0 -39
- package/dist/commands/resource-view.d.ts.map +0 -1
- package/dist/commands/resource-view.js +0 -197
- package/dist/commands/resource-view.js.map +0 -1
- package/dist/commands/routines.d.ts +0 -11
- package/dist/commands/routines.d.ts.map +0 -1
- package/dist/commands/routines.js +0 -590
- package/dist/commands/routines.js.map +0 -1
- package/dist/commands/rules.d.ts +0 -12
- package/dist/commands/rules.d.ts.map +0 -1
- package/dist/commands/rules.js +0 -489
- package/dist/commands/rules.js.map +0 -1
- package/dist/commands/secrets.d.ts +0 -11
- package/dist/commands/secrets.d.ts.map +0 -1
- package/dist/commands/secrets.js +0 -352
- package/dist/commands/secrets.js.map +0 -1
- package/dist/commands/sessions-picker.d.ts +0 -18
- package/dist/commands/sessions-picker.d.ts.map +0 -1
- package/dist/commands/sessions-picker.js +0 -265
- package/dist/commands/sessions-picker.js.map +0 -1
- package/dist/commands/sessions-tail.d.ts +0 -20
- package/dist/commands/sessions-tail.d.ts.map +0 -1
- package/dist/commands/sessions-tail.js +0 -236
- package/dist/commands/sessions-tail.js.map +0 -1
- package/dist/commands/sessions.d.ts +0 -18
- package/dist/commands/sessions.d.ts.map +0 -1
- package/dist/commands/sessions.js +0 -1173
- package/dist/commands/sessions.js.map +0 -1
- package/dist/commands/skills.d.ts +0 -12
- package/dist/commands/skills.d.ts.map +0 -1
- package/dist/commands/skills.js +0 -717
- package/dist/commands/skills.js.map +0 -1
- package/dist/commands/status.d.ts +0 -10
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -26
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/subagents.d.ts +0 -11
- package/dist/commands/subagents.d.ts.map +0 -1
- package/dist/commands/subagents.js +0 -361
- package/dist/commands/subagents.js.map +0 -1
- package/dist/commands/sync.d.ts +0 -11
- package/dist/commands/sync.d.ts.map +0 -1
- package/dist/commands/sync.js +0 -70
- package/dist/commands/sync.js.map +0 -1
- package/dist/commands/teams-picker.d.ts +0 -18
- package/dist/commands/teams-picker.d.ts.map +0 -1
- package/dist/commands/teams-picker.js +0 -290
- package/dist/commands/teams-picker.js.map +0 -1
- package/dist/commands/teams.d.ts +0 -18
- package/dist/commands/teams.d.ts.map +0 -1
- package/dist/commands/teams.js +0 -1144
- package/dist/commands/teams.js.map +0 -1
- package/dist/commands/utils.d.ts +0 -45
- package/dist/commands/utils.d.ts.map +0 -1
- package/dist/commands/utils.js +0 -106
- package/dist/commands/utils.js.map +0 -1
- package/dist/commands/versions.d.ts +0 -11
- package/dist/commands/versions.d.ts.map +0 -1
- package/dist/commands/versions.js +0 -701
- package/dist/commands/versions.js.map +0 -1
- package/dist/commands/view.d.ts +0 -43
- package/dist/commands/view.d.ts.map +0 -1
- package/dist/commands/view.js +0 -894
- package/dist/commands/view.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -496
- package/dist/index.js.map +0 -1
- package/dist/lib/__tests__/bugfixes.test.d.ts +0 -2
- package/dist/lib/__tests__/bugfixes.test.d.ts.map +0 -1
- package/dist/lib/__tests__/bugfixes.test.js +0 -192
- package/dist/lib/__tests__/bugfixes.test.js.map +0 -1
- package/dist/lib/__tests__/exec.test.d.ts +0 -2
- package/dist/lib/__tests__/exec.test.d.ts.map +0 -1
- package/dist/lib/__tests__/exec.test.js +0 -446
- package/dist/lib/__tests__/exec.test.js.map +0 -1
- package/dist/lib/__tests__/git-sync.test.d.ts +0 -2
- package/dist/lib/__tests__/git-sync.test.d.ts.map +0 -1
- package/dist/lib/__tests__/git-sync.test.js +0 -138
- package/dist/lib/__tests__/git-sync.test.js.map +0 -1
- package/dist/lib/__tests__/hooks.test.d.ts +0 -2
- package/dist/lib/__tests__/hooks.test.d.ts.map +0 -1
- package/dist/lib/__tests__/hooks.test.js +0 -203
- package/dist/lib/__tests__/hooks.test.js.map +0 -1
- package/dist/lib/__tests__/memory-compile.test.d.ts +0 -2
- package/dist/lib/__tests__/memory-compile.test.d.ts.map +0 -1
- package/dist/lib/__tests__/memory-compile.test.js +0 -95
- package/dist/lib/__tests__/memory-compile.test.js.map +0 -1
- package/dist/lib/__tests__/models.test.d.ts +0 -2
- package/dist/lib/__tests__/models.test.d.ts.map +0 -1
- package/dist/lib/__tests__/models.test.js +0 -239
- package/dist/lib/__tests__/models.test.js.map +0 -1
- package/dist/lib/__tests__/rotate.test.d.ts +0 -2
- package/dist/lib/__tests__/rotate.test.d.ts.map +0 -1
- package/dist/lib/__tests__/rotate.test.js +0 -80
- package/dist/lib/__tests__/rotate.test.js.map +0 -1
- package/dist/lib/__tests__/secrets-bundles.test.d.ts +0 -2
- package/dist/lib/__tests__/secrets-bundles.test.d.ts.map +0 -1
- package/dist/lib/__tests__/secrets-bundles.test.js +0 -104
- package/dist/lib/__tests__/secrets-bundles.test.js.map +0 -1
- package/dist/lib/__tests__/secrets.test.d.ts +0 -2
- package/dist/lib/__tests__/secrets.test.d.ts.map +0 -1
- package/dist/lib/__tests__/secrets.test.js +0 -90
- package/dist/lib/__tests__/secrets.test.js.map +0 -1
- package/dist/lib/__tests__/shims.test.d.ts +0 -2
- package/dist/lib/__tests__/shims.test.d.ts.map +0 -1
- package/dist/lib/__tests__/shims.test.js +0 -57
- package/dist/lib/__tests__/shims.test.js.map +0 -1
- package/dist/lib/__tests__/usage.test.d.ts +0 -2
- package/dist/lib/__tests__/usage.test.d.ts.map +0 -1
- package/dist/lib/__tests__/usage.test.js +0 -220
- package/dist/lib/__tests__/usage.test.js.map +0 -1
- package/dist/lib/__tests__/versions.test.d.ts +0 -2
- package/dist/lib/__tests__/versions.test.d.ts.map +0 -1
- package/dist/lib/__tests__/versions.test.js +0 -63
- package/dist/lib/__tests__/versions.test.js.map +0 -1
- package/dist/lib/agents.d.ts +0 -158
- package/dist/lib/agents.d.ts.map +0 -1
- package/dist/lib/agents.js +0 -1159
- package/dist/lib/agents.js.map +0 -1
- package/dist/lib/artifact-actions.d.ts +0 -27
- package/dist/lib/artifact-actions.d.ts.map +0 -1
- package/dist/lib/artifact-actions.js +0 -58
- package/dist/lib/artifact-actions.js.map +0 -1
- package/dist/lib/cloud/codex.d.ts +0 -26
- package/dist/lib/cloud/codex.d.ts.map +0 -1
- package/dist/lib/cloud/codex.js +0 -237
- package/dist/lib/cloud/codex.js.map +0 -1
- package/dist/lib/cloud/factory.d.ts +0 -32
- package/dist/lib/cloud/factory.d.ts.map +0 -1
- package/dist/lib/cloud/factory.js +0 -43
- package/dist/lib/cloud/factory.js.map +0 -1
- package/dist/lib/cloud/registry.d.ts +0 -16
- package/dist/lib/cloud/registry.d.ts.map +0 -1
- package/dist/lib/cloud/registry.js +0 -68
- package/dist/lib/cloud/registry.js.map +0 -1
- package/dist/lib/cloud/rush.d.ts +0 -37
- package/dist/lib/cloud/rush.d.ts.map +0 -1
- package/dist/lib/cloud/rush.js +0 -230
- package/dist/lib/cloud/rush.js.map +0 -1
- package/dist/lib/cloud/rush.test.d.ts +0 -2
- package/dist/lib/cloud/rush.test.d.ts.map +0 -1
- package/dist/lib/cloud/rush.test.js +0 -63
- package/dist/lib/cloud/rush.test.js.map +0 -1
- package/dist/lib/cloud/store.d.ts +0 -23
- package/dist/lib/cloud/store.d.ts.map +0 -1
- package/dist/lib/cloud/store.js +0 -116
- package/dist/lib/cloud/store.js.map +0 -1
- package/dist/lib/cloud/stream.d.ts +0 -24
- package/dist/lib/cloud/stream.d.ts.map +0 -1
- package/dist/lib/cloud/stream.js +0 -145
- package/dist/lib/cloud/stream.js.map +0 -1
- package/dist/lib/cloud/types.d.ts +0 -109
- package/dist/lib/cloud/types.d.ts.map +0 -1
- package/dist/lib/cloud/types.js +0 -33
- package/dist/lib/cloud/types.js.map +0 -1
- package/dist/lib/cloud/types.test.d.ts +0 -2
- package/dist/lib/cloud/types.test.d.ts.map +0 -1
- package/dist/lib/cloud/types.test.js +0 -41
- package/dist/lib/cloud/types.test.js.map +0 -1
- package/dist/lib/commands.d.ts +0 -141
- package/dist/lib/commands.d.ts.map +0 -1
- package/dist/lib/commands.js +0 -514
- package/dist/lib/commands.js.map +0 -1
- package/dist/lib/convert.d.ts +0 -21
- package/dist/lib/convert.d.ts.map +0 -1
- package/dist/lib/convert.js +0 -54
- package/dist/lib/convert.js.map +0 -1
- package/dist/lib/daemon.d.ts +0 -43
- package/dist/lib/daemon.d.ts.map +0 -1
- package/dist/lib/daemon.js +0 -332
- package/dist/lib/daemon.js.map +0 -1
- package/dist/lib/drive-sync.d.ts +0 -46
- package/dist/lib/drive-sync.d.ts.map +0 -1
- package/dist/lib/drive-sync.js +0 -209
- package/dist/lib/drive-sync.js.map +0 -1
- package/dist/lib/exec.d.ts +0 -101
- package/dist/lib/exec.d.ts.map +0 -1
- package/dist/lib/exec.js +0 -450
- package/dist/lib/exec.js.map +0 -1
- package/dist/lib/factory/__tests__/config.test.d.ts +0 -2
- package/dist/lib/factory/__tests__/config.test.d.ts.map +0 -1
- package/dist/lib/factory/__tests__/config.test.js +0 -128
- package/dist/lib/factory/__tests__/config.test.js.map +0 -1
- package/dist/lib/factory/config.d.ts +0 -49
- package/dist/lib/factory/config.d.ts.map +0 -1
- package/dist/lib/factory/config.js +0 -127
- package/dist/lib/factory/config.js.map +0 -1
- package/dist/lib/factory.d.ts +0 -57
- package/dist/lib/factory.d.ts.map +0 -1
- package/dist/lib/factory.js +0 -107
- package/dist/lib/factory.js.map +0 -1
- package/dist/lib/git.d.ts +0 -157
- package/dist/lib/git.d.ts.map +0 -1
- package/dist/lib/git.js +0 -647
- package/dist/lib/git.js.map +0 -1
- package/dist/lib/help.d.ts +0 -10
- package/dist/lib/help.d.ts.map +0 -1
- package/dist/lib/help.js +0 -66
- package/dist/lib/help.js.map +0 -1
- package/dist/lib/hooks.d.ts +0 -125
- package/dist/lib/hooks.d.ts.map +0 -1
- package/dist/lib/hooks.js +0 -846
- package/dist/lib/hooks.js.map +0 -1
- package/dist/lib/ledger/__tests__/local.test.d.ts +0 -2
- package/dist/lib/ledger/__tests__/local.test.d.ts.map +0 -1
- package/dist/lib/ledger/__tests__/local.test.js +0 -177
- package/dist/lib/ledger/__tests__/local.test.js.map +0 -1
- package/dist/lib/ledger/__tests__/sync.test.d.ts +0 -2
- package/dist/lib/ledger/__tests__/sync.test.d.ts.map +0 -1
- package/dist/lib/ledger/__tests__/sync.test.js +0 -117
- package/dist/lib/ledger/__tests__/sync.test.js.map +0 -1
- package/dist/lib/ledger/index.d.ts +0 -18
- package/dist/lib/ledger/index.d.ts.map +0 -1
- package/dist/lib/ledger/index.js +0 -32
- package/dist/lib/ledger/index.js.map +0 -1
- package/dist/lib/ledger/local.d.ts +0 -22
- package/dist/lib/ledger/local.d.ts.map +0 -1
- package/dist/lib/ledger/local.js +0 -333
- package/dist/lib/ledger/local.js.map +0 -1
- package/dist/lib/ledger/r2.d.ts +0 -41
- package/dist/lib/ledger/r2.d.ts.map +0 -1
- package/dist/lib/ledger/r2.js +0 -335
- package/dist/lib/ledger/r2.js.map +0 -1
- package/dist/lib/ledger/sync.d.ts +0 -33
- package/dist/lib/ledger/sync.d.ts.map +0 -1
- package/dist/lib/ledger/sync.js +0 -106
- package/dist/lib/ledger/sync.js.map +0 -1
- package/dist/lib/ledger/types.d.ts +0 -100
- package/dist/lib/ledger/types.d.ts.map +0 -1
- package/dist/lib/ledger/types.js +0 -21
- package/dist/lib/ledger/types.js.map +0 -1
- package/dist/lib/manifest.d.ts +0 -14
- package/dist/lib/manifest.d.ts.map +0 -1
- package/dist/lib/manifest.js +0 -48
- package/dist/lib/manifest.js.map +0 -1
- package/dist/lib/markdown.d.ts +0 -5
- package/dist/lib/markdown.d.ts.map +0 -1
- package/dist/lib/markdown.js +0 -17
- package/dist/lib/markdown.js.map +0 -1
- package/dist/lib/mcp.d.ts +0 -64
- package/dist/lib/mcp.d.ts.map +0 -1
- package/dist/lib/mcp.js +0 -327
- package/dist/lib/mcp.js.map +0 -1
- package/dist/lib/memory-compile.d.ts +0 -65
- package/dist/lib/memory-compile.d.ts.map +0 -1
- package/dist/lib/memory-compile.js +0 -174
- package/dist/lib/memory-compile.js.map +0 -1
- package/dist/lib/memory.d.ts +0 -64
- package/dist/lib/memory.d.ts.map +0 -1
- package/dist/lib/memory.js +0 -275
- package/dist/lib/memory.js.map +0 -1
- package/dist/lib/models.d.ts +0 -98
- package/dist/lib/models.d.ts.map +0 -1
- package/dist/lib/models.js +0 -728
- package/dist/lib/models.js.map +0 -1
- package/dist/lib/permissions.d.ts +0 -227
- package/dist/lib/permissions.d.ts.map +0 -1
- package/dist/lib/permissions.js +0 -1071
- package/dist/lib/permissions.js.map +0 -1
- package/dist/lib/picker.d.ts +0 -27
- package/dist/lib/picker.d.ts.map +0 -1
- package/dist/lib/picker.js +0 -110
- package/dist/lib/picker.js.map +0 -1
- package/dist/lib/plugins.d.ts +0 -80
- package/dist/lib/plugins.d.ts.map +0 -1
- package/dist/lib/plugins.js +0 -556
- package/dist/lib/plugins.js.map +0 -1
- package/dist/lib/profiles-keychain.d.ts +0 -11
- package/dist/lib/profiles-keychain.d.ts.map +0 -1
- package/dist/lib/profiles-keychain.js +0 -14
- package/dist/lib/profiles-keychain.js.map +0 -1
- package/dist/lib/profiles-presets.d.ts +0 -25
- package/dist/lib/profiles-presets.d.ts.map +0 -1
- package/dist/lib/profiles-presets.js +0 -104
- package/dist/lib/profiles-presets.js.map +0 -1
- package/dist/lib/profiles.d.ts +0 -70
- package/dist/lib/profiles.d.ts.map +0 -1
- package/dist/lib/profiles.js +0 -145
- package/dist/lib/profiles.js.map +0 -1
- package/dist/lib/pty-client.d.ts +0 -23
- package/dist/lib/pty-client.d.ts.map +0 -1
- package/dist/lib/pty-client.js +0 -181
- package/dist/lib/pty-client.js.map +0 -1
- package/dist/lib/pty-server.d.ts +0 -21
- package/dist/lib/pty-server.d.ts.map +0 -1
- package/dist/lib/pty-server.js +0 -427
- package/dist/lib/pty-server.js.map +0 -1
- package/dist/lib/registry.d.ts +0 -45
- package/dist/lib/registry.d.ts.map +0 -1
- package/dist/lib/registry.js +0 -220
- package/dist/lib/registry.js.map +0 -1
- package/dist/lib/resources.d.ts +0 -55
- package/dist/lib/resources.d.ts.map +0 -1
- package/dist/lib/resources.js +0 -103
- package/dist/lib/resources.js.map +0 -1
- package/dist/lib/rotate.d.ts +0 -58
- package/dist/lib/rotate.d.ts.map +0 -1
- package/dist/lib/rotate.js +0 -93
- package/dist/lib/rotate.js.map +0 -1
- package/dist/lib/routines.d.ts +0 -99
- package/dist/lib/routines.d.ts.map +0 -1
- package/dist/lib/routines.js +0 -352
- package/dist/lib/routines.js.map +0 -1
- package/dist/lib/runner.d.ts +0 -26
- package/dist/lib/runner.d.ts.map +0 -1
- package/dist/lib/runner.js +0 -325
- package/dist/lib/runner.js.map +0 -1
- package/dist/lib/sandbox.d.ts +0 -26
- package/dist/lib/sandbox.d.ts.map +0 -1
- package/dist/lib/sandbox.js +0 -218
- package/dist/lib/sandbox.js.map +0 -1
- package/dist/lib/scheduler.d.ts +0 -26
- package/dist/lib/scheduler.d.ts.map +0 -1
- package/dist/lib/scheduler.js +0 -77
- package/dist/lib/scheduler.js.map +0 -1
- package/dist/lib/secrets-bundles.d.ts +0 -38
- package/dist/lib/secrets-bundles.d.ts.map +0 -1
- package/dist/lib/secrets-bundles.js +0 -176
- package/dist/lib/secrets-bundles.js.map +0 -1
- package/dist/lib/secrets.d.ts +0 -53
- package/dist/lib/secrets.d.ts.map +0 -1
- package/dist/lib/secrets.js +0 -140
- package/dist/lib/secrets.js.map +0 -1
- package/dist/lib/session/__tests__/db.test.d.ts +0 -2
- package/dist/lib/session/__tests__/db.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/db.test.js +0 -54
- package/dist/lib/session/__tests__/db.test.js.map +0 -1
- package/dist/lib/session/__tests__/discover.test.d.ts +0 -2
- package/dist/lib/session/__tests__/discover.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/discover.test.js +0 -63
- package/dist/lib/session/__tests__/discover.test.js.map +0 -1
- package/dist/lib/session/__tests__/prompt.test.d.ts +0 -2
- package/dist/lib/session/__tests__/prompt.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/prompt.test.js +0 -44
- package/dist/lib/session/__tests__/prompt.test.js.map +0 -1
- package/dist/lib/session/__tests__/render.test.d.ts +0 -2
- package/dist/lib/session/__tests__/render.test.d.ts.map +0 -1
- package/dist/lib/session/__tests__/render.test.js +0 -602
- package/dist/lib/session/__tests__/render.test.js.map +0 -1
- package/dist/lib/session/active.d.ts +0 -44
- package/dist/lib/session/active.d.ts.map +0 -1
- package/dist/lib/session/active.js +0 -379
- package/dist/lib/session/active.js.map +0 -1
- package/dist/lib/session/artifacts.d.ts +0 -15
- package/dist/lib/session/artifacts.d.ts.map +0 -1
- package/dist/lib/session/artifacts.js +0 -86
- package/dist/lib/session/artifacts.js.map +0 -1
- package/dist/lib/session/db.d.ts +0 -140
- package/dist/lib/session/db.d.ts.map +0 -1
- package/dist/lib/session/db.js +0 -599
- package/dist/lib/session/db.js.map +0 -1
- package/dist/lib/session/discover.d.ts +0 -72
- package/dist/lib/session/discover.d.ts.map +0 -1
- package/dist/lib/session/discover.js +0 -1315
- package/dist/lib/session/discover.js.map +0 -1
- package/dist/lib/session/parse.d.ts +0 -34
- package/dist/lib/session/parse.d.ts.map +0 -1
- package/dist/lib/session/parse.js +0 -663
- package/dist/lib/session/parse.js.map +0 -1
- package/dist/lib/session/prompt.d.ts +0 -13
- package/dist/lib/session/prompt.d.ts.map +0 -1
- package/dist/lib/session/prompt.js +0 -79
- package/dist/lib/session/prompt.js.map +0 -1
- package/dist/lib/session/prompt.test.d.ts +0 -2
- package/dist/lib/session/prompt.test.d.ts.map +0 -1
- package/dist/lib/session/prompt.test.js +0 -57
- package/dist/lib/session/prompt.test.js.map +0 -1
- package/dist/lib/session/render.d.ts +0 -103
- package/dist/lib/session/render.d.ts.map +0 -1
- package/dist/lib/session/render.js +0 -798
- package/dist/lib/session/render.js.map +0 -1
- package/dist/lib/session/team-filter.d.ts +0 -35
- package/dist/lib/session/team-filter.d.ts.map +0 -1
- package/dist/lib/session/team-filter.js +0 -75
- package/dist/lib/session/team-filter.js.map +0 -1
- package/dist/lib/session/team-filter.test.d.ts +0 -2
- package/dist/lib/session/team-filter.test.d.ts.map +0 -1
- package/dist/lib/session/team-filter.test.js +0 -157
- package/dist/lib/session/team-filter.test.js.map +0 -1
- package/dist/lib/session/types.d.ts +0 -84
- package/dist/lib/session/types.d.ts.map +0 -1
- package/dist/lib/session/types.js +0 -11
- package/dist/lib/session/types.js.map +0 -1
- package/dist/lib/shims.d.ts +0 -272
- package/dist/lib/shims.d.ts.map +0 -1
- package/dist/lib/shims.js +0 -1322
- package/dist/lib/shims.js.map +0 -1
- package/dist/lib/skills.d.ts +0 -142
- package/dist/lib/skills.d.ts.map +0 -1
- package/dist/lib/skills.js +0 -791
- package/dist/lib/skills.js.map +0 -1
- package/dist/lib/state.d.ts +0 -87
- package/dist/lib/state.d.ts.map +0 -1
- package/dist/lib/state.js +0 -333
- package/dist/lib/state.js.map +0 -1
- package/dist/lib/subagents.d.ts +0 -84
- package/dist/lib/subagents.d.ts.map +0 -1
- package/dist/lib/subagents.js +0 -410
- package/dist/lib/subagents.js.map +0 -1
- package/dist/lib/teams/__tests__/oracle.test.d.ts +0 -2
- package/dist/lib/teams/__tests__/oracle.test.d.ts.map +0 -1
- package/dist/lib/teams/__tests__/oracle.test.js +0 -89
- package/dist/lib/teams/__tests__/oracle.test.js.map +0 -1
- package/dist/lib/teams/__tests__/supervisor.test.d.ts +0 -2
- package/dist/lib/teams/__tests__/supervisor.test.d.ts.map +0 -1
- package/dist/lib/teams/__tests__/supervisor.test.js +0 -179
- package/dist/lib/teams/__tests__/supervisor.test.js.map +0 -1
- package/dist/lib/teams/agents.d.ts +0 -247
- package/dist/lib/teams/agents.d.ts.map +0 -1
- package/dist/lib/teams/agents.js +0 -1244
- package/dist/lib/teams/agents.js.map +0 -1
- package/dist/lib/teams/api.d.ts +0 -91
- package/dist/lib/teams/api.d.ts.map +0 -1
- package/dist/lib/teams/api.js +0 -239
- package/dist/lib/teams/api.js.map +0 -1
- package/dist/lib/teams/cloud.d.ts +0 -11
- package/dist/lib/teams/cloud.d.ts.map +0 -1
- package/dist/lib/teams/cloud.js +0 -169
- package/dist/lib/teams/cloud.js.map +0 -1
- package/dist/lib/teams/debug.d.ts +0 -8
- package/dist/lib/teams/debug.d.ts.map +0 -1
- package/dist/lib/teams/debug.js +0 -12
- package/dist/lib/teams/debug.js.map +0 -1
- package/dist/lib/teams/file_ops.d.ts +0 -13
- package/dist/lib/teams/file_ops.d.ts.map +0 -1
- package/dist/lib/teams/file_ops.js +0 -66
- package/dist/lib/teams/file_ops.js.map +0 -1
- package/dist/lib/teams/index.d.ts +0 -16
- package/dist/lib/teams/index.d.ts.map +0 -1
- package/dist/lib/teams/index.js +0 -15
- package/dist/lib/teams/index.js.map +0 -1
- package/dist/lib/teams/oracle.d.ts +0 -20
- package/dist/lib/teams/oracle.d.ts.map +0 -1
- package/dist/lib/teams/oracle.js +0 -59
- package/dist/lib/teams/oracle.js.map +0 -1
- package/dist/lib/teams/parsers.d.ts +0 -9
- package/dist/lib/teams/parsers.d.ts.map +0 -1
- package/dist/lib/teams/parsers.js +0 -837
- package/dist/lib/teams/parsers.js.map +0 -1
- package/dist/lib/teams/persistence.d.ts +0 -43
- package/dist/lib/teams/persistence.d.ts.map +0 -1
- package/dist/lib/teams/persistence.js +0 -299
- package/dist/lib/teams/persistence.js.map +0 -1
- package/dist/lib/teams/ralph.d.ts +0 -8
- package/dist/lib/teams/ralph.d.ts.map +0 -1
- package/dist/lib/teams/ralph.js +0 -59
- package/dist/lib/teams/ralph.js.map +0 -1
- package/dist/lib/teams/registry.d.ts +0 -18
- package/dist/lib/teams/registry.d.ts.map +0 -1
- package/dist/lib/teams/registry.js +0 -68
- package/dist/lib/teams/registry.js.map +0 -1
- package/dist/lib/teams/summarizer.d.ts +0 -73
- package/dist/lib/teams/summarizer.d.ts.map +0 -1
- package/dist/lib/teams/summarizer.js +0 -780
- package/dist/lib/teams/summarizer.js.map +0 -1
- package/dist/lib/teams/supervisor.d.ts +0 -49
- package/dist/lib/teams/supervisor.d.ts.map +0 -1
- package/dist/lib/teams/supervisor.js +0 -74
- package/dist/lib/teams/supervisor.js.map +0 -1
- package/dist/lib/template.d.ts +0 -27
- package/dist/lib/template.d.ts.map +0 -1
- package/dist/lib/template.js +0 -60
- package/dist/lib/template.js.map +0 -1
- package/dist/lib/types.d.ts +0 -331
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js +0 -29
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/usage.d.ts +0 -105
- package/dist/lib/usage.d.ts.map +0 -1
- package/dist/lib/usage.js +0 -686
- package/dist/lib/usage.js.map +0 -1
- package/dist/lib/versions.d.ts +0 -253
- package/dist/lib/versions.d.ts.map +0 -1
- package/dist/lib/versions.js +0 -1796
- package/dist/lib/versions.js.map +0 -1
- package/scripts/rebuild-sqlite.sh +0 -46
package/dist/lib/hooks.js
DELETED
|
@@ -1,846 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook management -- discovery, registration, and syncing of event hooks.
|
|
3
|
-
*
|
|
4
|
-
* Hooks are shell scripts in ~/.agents/hooks/ that fire on agent events
|
|
5
|
-
* (tool calls, session start, etc.). Each hook directory contains a manifest
|
|
6
|
-
* (agents.yaml) declaring events, matchers, and timeout. This module handles
|
|
7
|
-
* parsing those manifests, registering hooks into agent-native settings files,
|
|
8
|
-
* and syncing them across version switches.
|
|
9
|
-
*/
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import * as yaml from 'yaml';
|
|
13
|
-
import * as TOML from 'smol-toml';
|
|
14
|
-
import { AGENTS, HOOKS_CAPABLE_AGENTS } from './agents.js';
|
|
15
|
-
import { getAgentsDir, getHooksDir as getCentralHooksDir, getProjectAgentsDir } from './state.js';
|
|
16
|
-
import { getEffectiveHome, getVersionHomePath, listInstalledVersions } from './versions.js';
|
|
17
|
-
const SCRIPT_EXTENSIONS = new Set([
|
|
18
|
-
'.sh',
|
|
19
|
-
'.bash',
|
|
20
|
-
'.zsh',
|
|
21
|
-
'.py',
|
|
22
|
-
'.js',
|
|
23
|
-
'.ts',
|
|
24
|
-
'.mjs',
|
|
25
|
-
'.cjs',
|
|
26
|
-
'.rb',
|
|
27
|
-
'.pl',
|
|
28
|
-
'.ps1',
|
|
29
|
-
'.cmd',
|
|
30
|
-
'.bat',
|
|
31
|
-
]);
|
|
32
|
-
function isExecutable(mode) {
|
|
33
|
-
return (mode & 0o111) !== 0;
|
|
34
|
-
}
|
|
35
|
-
function getHooksDir(agentId) {
|
|
36
|
-
const agent = AGENTS[agentId];
|
|
37
|
-
const home = getEffectiveHome(agentId);
|
|
38
|
-
return path.join(home, `.${agentId}`, agent.hooksDir);
|
|
39
|
-
}
|
|
40
|
-
function getProjectHooksDirs(agentId, cwd) {
|
|
41
|
-
const agent = AGENTS[agentId];
|
|
42
|
-
const dirs = [];
|
|
43
|
-
const projectAgentsDir = getProjectAgentsDir(cwd);
|
|
44
|
-
if (projectAgentsDir) {
|
|
45
|
-
dirs.push(path.join(projectAgentsDir, 'hooks'));
|
|
46
|
-
}
|
|
47
|
-
dirs.push(path.join(cwd, `.${agentId}`, agent.hooksDir));
|
|
48
|
-
return dirs;
|
|
49
|
-
}
|
|
50
|
-
function ensureDir(dir) {
|
|
51
|
-
if (!fs.existsSync(dir)) {
|
|
52
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function removeHookFiles(dir, name) {
|
|
56
|
-
if (!fs.existsSync(dir)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const files = fs.readdirSync(dir);
|
|
60
|
-
for (const file of files) {
|
|
61
|
-
const ext = path.extname(file);
|
|
62
|
-
const base = path.basename(file, ext);
|
|
63
|
-
if (base === name) {
|
|
64
|
-
const fullPath = path.join(dir, file);
|
|
65
|
-
const stat = fs.statSync(fullPath);
|
|
66
|
-
if (stat.isFile()) {
|
|
67
|
-
fs.unlinkSync(fullPath);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function listHookEntriesFromDir(dir) {
|
|
73
|
-
if (!fs.existsSync(dir)) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
const files = [];
|
|
77
|
-
for (const file of fs.readdirSync(dir)) {
|
|
78
|
-
const fullPath = path.join(dir, file);
|
|
79
|
-
const stat = fs.statSync(fullPath);
|
|
80
|
-
if (!stat.isFile())
|
|
81
|
-
continue;
|
|
82
|
-
const ext = path.extname(file);
|
|
83
|
-
const base = path.basename(file, ext);
|
|
84
|
-
files.push({
|
|
85
|
-
name: file,
|
|
86
|
-
base,
|
|
87
|
-
ext,
|
|
88
|
-
fullPath,
|
|
89
|
-
isExec: isExecutable(stat.mode),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const grouped = new Map();
|
|
93
|
-
for (const file of files) {
|
|
94
|
-
const list = grouped.get(file.base) || [];
|
|
95
|
-
list.push(file);
|
|
96
|
-
grouped.set(file.base, list);
|
|
97
|
-
}
|
|
98
|
-
const entries = [];
|
|
99
|
-
for (const [base, group] of grouped) {
|
|
100
|
-
group.sort((a, b) => a.name.localeCompare(b.name));
|
|
101
|
-
const script = group.find((f) => f.isExec) ||
|
|
102
|
-
group.find((f) => SCRIPT_EXTENSIONS.has(f.ext.toLowerCase())) ||
|
|
103
|
-
group[0];
|
|
104
|
-
if (!script)
|
|
105
|
-
continue;
|
|
106
|
-
const data = group.find((f) => f !== script);
|
|
107
|
-
entries.push({
|
|
108
|
-
name: base,
|
|
109
|
-
scriptPath: script.fullPath,
|
|
110
|
-
dataFile: data ? data.fullPath : undefined,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
114
|
-
return entries;
|
|
115
|
-
}
|
|
116
|
-
function buildHookMap(entries) {
|
|
117
|
-
const map = new Map();
|
|
118
|
-
for (const entry of entries) {
|
|
119
|
-
map.set(entry.name, entry);
|
|
120
|
-
}
|
|
121
|
-
return map;
|
|
122
|
-
}
|
|
123
|
-
function copyHook(entry, targetDir) {
|
|
124
|
-
ensureDir(targetDir);
|
|
125
|
-
removeHookFiles(targetDir, entry.name);
|
|
126
|
-
const scriptTarget = path.join(targetDir, path.basename(entry.scriptPath));
|
|
127
|
-
fs.copyFileSync(entry.scriptPath, scriptTarget);
|
|
128
|
-
const scriptStat = fs.statSync(entry.scriptPath);
|
|
129
|
-
fs.chmodSync(scriptTarget, scriptStat.mode);
|
|
130
|
-
if (entry.dataFile) {
|
|
131
|
-
const dataTarget = path.join(targetDir, path.basename(entry.dataFile));
|
|
132
|
-
fs.copyFileSync(entry.dataFile, dataTarget);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Check if a hook exists for an agent.
|
|
137
|
-
*/
|
|
138
|
-
export function hookExists(agentId, hookName) {
|
|
139
|
-
const agent = AGENTS[agentId];
|
|
140
|
-
if (!agent.supportsHooks) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
const hooksDir = getHooksDir(agentId);
|
|
144
|
-
if (!fs.existsSync(hooksDir)) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
const files = fs.readdirSync(hooksDir);
|
|
148
|
-
return files.some((file) => {
|
|
149
|
-
const ext = path.extname(file);
|
|
150
|
-
const baseName = path.basename(file, ext);
|
|
151
|
-
return baseName === hookName && SCRIPT_EXTENSIONS.has(ext);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Normalize content for comparison (trim, normalize line endings).
|
|
156
|
-
*/
|
|
157
|
-
function normalizeContent(content) {
|
|
158
|
-
return content.replace(/\r\n/g, '\n').trim();
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Get the installed hook entry for an agent.
|
|
162
|
-
*/
|
|
163
|
-
function getInstalledHookEntry(agentId, hookName) {
|
|
164
|
-
const hooksDir = getHooksDir(agentId);
|
|
165
|
-
const entries = listHookEntriesFromDir(hooksDir);
|
|
166
|
-
return entries.find((e) => e.name === hookName) || null;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Check if installed hook content matches source hook content.
|
|
170
|
-
* Compares both script file and data file (if present).
|
|
171
|
-
*/
|
|
172
|
-
export function hookContentMatches(agentId, hookName, sourceEntry) {
|
|
173
|
-
const agent = AGENTS[agentId];
|
|
174
|
-
if (!agent.supportsHooks) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
const installedEntry = getInstalledHookEntry(agentId, hookName);
|
|
178
|
-
if (!installedEntry) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
const installedScript = fs.readFileSync(installedEntry.scriptPath, 'utf-8');
|
|
183
|
-
const sourceScript = fs.readFileSync(sourceEntry.scriptPath, 'utf-8');
|
|
184
|
-
if (normalizeContent(installedScript) !== normalizeContent(sourceScript)) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
const hasInstalledData = !!installedEntry.dataFile;
|
|
188
|
-
const hasSourceData = !!sourceEntry.dataFile;
|
|
189
|
-
if (hasInstalledData !== hasSourceData) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
if (hasInstalledData && hasSourceData) {
|
|
193
|
-
const installedData = fs.readFileSync(installedEntry.dataFile, 'utf-8');
|
|
194
|
-
const sourceData = fs.readFileSync(sourceEntry.dataFile, 'utf-8');
|
|
195
|
-
if (normalizeContent(installedData) !== normalizeContent(sourceData)) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
export function listInstalledHooksWithScope(agentId, cwd = process.cwd(), options) {
|
|
206
|
-
const agent = AGENTS[agentId];
|
|
207
|
-
if (!agent.supportsHooks) {
|
|
208
|
-
return [];
|
|
209
|
-
}
|
|
210
|
-
const results = [];
|
|
211
|
-
const seen = new Set();
|
|
212
|
-
const addHook = (hook, scope, agentId) => {
|
|
213
|
-
if (seen.has(hook.name))
|
|
214
|
-
return;
|
|
215
|
-
results.push({
|
|
216
|
-
name: hook.name,
|
|
217
|
-
path: hook.scriptPath,
|
|
218
|
-
dataFile: hook.dataFile,
|
|
219
|
-
scope,
|
|
220
|
-
agent: agentId,
|
|
221
|
-
});
|
|
222
|
-
seen.add(hook.name);
|
|
223
|
-
};
|
|
224
|
-
// Project-scoped hooks (project .agents overrides agent-specific dirs)
|
|
225
|
-
const projectDirs = getProjectHooksDirs(agentId, cwd);
|
|
226
|
-
for (const dir of projectDirs) {
|
|
227
|
-
const projectHooks = listHookEntriesFromDir(dir);
|
|
228
|
-
for (const hook of projectHooks) {
|
|
229
|
-
addHook(hook, 'project', agentId);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// User-scoped hooks (version-aware when home is provided)
|
|
233
|
-
const home = options?.home || getEffectiveHome(agentId);
|
|
234
|
-
const userDir = path.join(home, `.${agentId}`, agent.hooksDir);
|
|
235
|
-
const userHooks = listHookEntriesFromDir(userDir);
|
|
236
|
-
for (const hook of userHooks) {
|
|
237
|
-
addHook(hook, 'user', agentId);
|
|
238
|
-
}
|
|
239
|
-
return results;
|
|
240
|
-
}
|
|
241
|
-
export async function installHooks(source, agents, options = {}) {
|
|
242
|
-
const installed = [];
|
|
243
|
-
const errors = [];
|
|
244
|
-
const scope = options.scope || 'user';
|
|
245
|
-
const cwd = process.cwd();
|
|
246
|
-
const hooksDir = path.join(source, 'hooks');
|
|
247
|
-
const hooks = listHookEntriesFromDir(hooksDir);
|
|
248
|
-
const uniqueAgents = Array.from(new Set(agents));
|
|
249
|
-
for (const agentId of uniqueAgents) {
|
|
250
|
-
const agent = AGENTS[agentId];
|
|
251
|
-
if (!agent || !agent.supportsHooks) {
|
|
252
|
-
errors.push(`${agentId}:Agent does not support hooks`);
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
const targetDir = scope === 'project' ? getProjectHooksDirs(agentId, cwd)[0] : getHooksDir(agentId);
|
|
256
|
-
for (const entry of hooks) {
|
|
257
|
-
try {
|
|
258
|
-
copyHook(entry, targetDir);
|
|
259
|
-
installed.push(`${entry.name}:${agentId}`);
|
|
260
|
-
}
|
|
261
|
-
catch (err) {
|
|
262
|
-
errors.push(`${entry.name}:${agentId}:${err.message}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return { installed, errors };
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Path to the hooks dir of a specific version home (not the active one).
|
|
270
|
-
*/
|
|
271
|
-
export function getVersionHooksDir(agent, version) {
|
|
272
|
-
const home = getVersionHomePath(agent, version);
|
|
273
|
-
return path.join(home, `.${agent}`, AGENTS[agent].hooksDir);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* List hook entries in a specific version home.
|
|
277
|
-
*/
|
|
278
|
-
export function listHooksInVersionHome(agent, version) {
|
|
279
|
-
return listHookEntriesFromDir(getVersionHooksDir(agent, version));
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Check if a hook installed in a specific version matches central content.
|
|
283
|
-
*/
|
|
284
|
-
function versionHookMatches(agent, version, hookName) {
|
|
285
|
-
const central = listHookEntriesFromDir(getCentralHooksDir()).find((e) => e.name === hookName);
|
|
286
|
-
if (!central)
|
|
287
|
-
return false;
|
|
288
|
-
const installed = listHooksInVersionHome(agent, version).find((e) => e.name === hookName);
|
|
289
|
-
if (!installed)
|
|
290
|
-
return false;
|
|
291
|
-
try {
|
|
292
|
-
if (normalizeContent(fs.readFileSync(installed.scriptPath, 'utf-8')) !==
|
|
293
|
-
normalizeContent(fs.readFileSync(central.scriptPath, 'utf-8'))) {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
if (!!installed.dataFile !== !!central.dataFile)
|
|
297
|
-
return false;
|
|
298
|
-
if (installed.dataFile && central.dataFile) {
|
|
299
|
-
if (normalizeContent(fs.readFileSync(installed.dataFile, 'utf-8')) !==
|
|
300
|
-
normalizeContent(fs.readFileSync(central.dataFile, 'utf-8'))) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Compare a version home's hooks against central. Returns the reconciliation diff.
|
|
312
|
-
*/
|
|
313
|
-
export function diffVersionHooks(agent, version) {
|
|
314
|
-
const central = new Set(listHookEntriesFromDir(getCentralHooksDir()).map((e) => e.name));
|
|
315
|
-
const installed = new Set(listHooksInVersionHome(agent, version).map((e) => e.name));
|
|
316
|
-
const toAdd = [];
|
|
317
|
-
const toUpdate = [];
|
|
318
|
-
const matched = [];
|
|
319
|
-
const orphans = [];
|
|
320
|
-
for (const name of central) {
|
|
321
|
-
if (!installed.has(name)) {
|
|
322
|
-
toAdd.push(name);
|
|
323
|
-
}
|
|
324
|
-
else if (!versionHookMatches(agent, version, name)) {
|
|
325
|
-
toUpdate.push(name);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
matched.push(name);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
for (const name of installed) {
|
|
332
|
-
if (!central.has(name))
|
|
333
|
-
orphans.push(name);
|
|
334
|
-
}
|
|
335
|
-
return { agent, version, toAdd: toAdd.sort(), toUpdate: toUpdate.sort(), matched, orphans: orphans.sort() };
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Install a single hook from central into a specific version home.
|
|
339
|
-
*/
|
|
340
|
-
export function installHookToVersion(agent, version, hookName) {
|
|
341
|
-
const central = listHookEntriesFromDir(getCentralHooksDir()).find((e) => e.name === hookName);
|
|
342
|
-
if (!central) {
|
|
343
|
-
return { success: false, error: `Hook '${hookName}' not found in central` };
|
|
344
|
-
}
|
|
345
|
-
const targetDir = getVersionHooksDir(agent, version);
|
|
346
|
-
try {
|
|
347
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
348
|
-
copyHook(central, targetDir);
|
|
349
|
-
}
|
|
350
|
-
catch (err) {
|
|
351
|
-
return { success: false, error: err.message };
|
|
352
|
-
}
|
|
353
|
-
return { success: true };
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Remove a single hook (script + data file) from a specific version home.
|
|
357
|
-
*/
|
|
358
|
-
export function removeHookFromVersion(agent, version, hookName) {
|
|
359
|
-
try {
|
|
360
|
-
removeHookFiles(getVersionHooksDir(agent, version), hookName);
|
|
361
|
-
}
|
|
362
|
-
catch (err) {
|
|
363
|
-
return { success: false, error: err.message };
|
|
364
|
-
}
|
|
365
|
-
return { success: true };
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Iterate all (agent, version) pairs that support hooks and are installed,
|
|
369
|
-
* optionally scoped to a single agent/version.
|
|
370
|
-
*/
|
|
371
|
-
export function iterHooksCapableVersions(filter) {
|
|
372
|
-
const pairs = [];
|
|
373
|
-
const hookAgents = HOOKS_CAPABLE_AGENTS;
|
|
374
|
-
const agents = filter?.agent ? [filter.agent] : hookAgents;
|
|
375
|
-
for (const agent of agents) {
|
|
376
|
-
if (!hookAgents.includes(agent))
|
|
377
|
-
continue;
|
|
378
|
-
const versions = listInstalledVersions(agent);
|
|
379
|
-
for (const version of versions) {
|
|
380
|
-
if (filter?.version && filter.version !== version)
|
|
381
|
-
continue;
|
|
382
|
-
pairs.push({ agent, version });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return pairs;
|
|
386
|
-
}
|
|
387
|
-
export async function removeHook(name, agents) {
|
|
388
|
-
const removed = [];
|
|
389
|
-
const errors = [];
|
|
390
|
-
const uniqueAgents = Array.from(new Set(agents));
|
|
391
|
-
for (const agentId of uniqueAgents) {
|
|
392
|
-
const agent = AGENTS[agentId];
|
|
393
|
-
if (!agent || !agent.supportsHooks) {
|
|
394
|
-
errors.push(`${agentId}:Agent does not support hooks`);
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
const dir = getHooksDir(agentId);
|
|
399
|
-
const filesBefore = fs.existsSync(dir) ? fs.readdirSync(dir) : [];
|
|
400
|
-
removeHookFiles(dir, name);
|
|
401
|
-
const filesAfter = fs.existsSync(dir) ? fs.readdirSync(dir) : [];
|
|
402
|
-
if (filesBefore.length !== filesAfter.length) {
|
|
403
|
-
removed.push(`${name}:${agentId}`);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
catch (err) {
|
|
407
|
-
errors.push(`${name}:${agentId}:${err.message}`);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return { removed, errors };
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Get detailed info about a hook from central storage.
|
|
414
|
-
*/
|
|
415
|
-
export function getHookInfo(name) {
|
|
416
|
-
const centralDir = getCentralHooksDir();
|
|
417
|
-
const hookPath = path.join(centralDir, name);
|
|
418
|
-
if (!fs.existsSync(hookPath)) {
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
// Read hook content - it could be a file or directory
|
|
422
|
-
let content = '';
|
|
423
|
-
const stat = fs.statSync(hookPath);
|
|
424
|
-
if (stat.isFile()) {
|
|
425
|
-
content = fs.readFileSync(hookPath, 'utf-8');
|
|
426
|
-
}
|
|
427
|
-
else if (stat.isDirectory()) {
|
|
428
|
-
// For directory hooks, list the files
|
|
429
|
-
const files = fs.readdirSync(hookPath);
|
|
430
|
-
content = `Directory hook containing:\n${files.map((f) => ` - ${f}`).join('\n')}`;
|
|
431
|
-
}
|
|
432
|
-
return {
|
|
433
|
-
name,
|
|
434
|
-
path: hookPath,
|
|
435
|
-
content,
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
export function discoverHooksFromRepo(repoPath) {
|
|
439
|
-
const hooksDir = path.join(repoPath, 'hooks');
|
|
440
|
-
return listHookEntriesFromDir(hooksDir).map((h) => h.name);
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Get the source hook entry from repo.
|
|
444
|
-
*/
|
|
445
|
-
export function getSourceHookEntry(repoPath, hookName) {
|
|
446
|
-
const hooksDir = path.join(repoPath, 'hooks');
|
|
447
|
-
const entries = listHookEntriesFromDir(hooksDir);
|
|
448
|
-
return entries.find((e) => e.name === hookName) || null;
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Install hooks to central ~/.agents/hooks/ directory.
|
|
452
|
-
* Shims will symlink this to per-agent directories for synced agents.
|
|
453
|
-
*/
|
|
454
|
-
export async function installHooksCentrally(source) {
|
|
455
|
-
const installed = [];
|
|
456
|
-
const errors = [];
|
|
457
|
-
const centralDir = getCentralHooksDir();
|
|
458
|
-
if (!fs.existsSync(centralDir)) {
|
|
459
|
-
fs.mkdirSync(centralDir, { recursive: true });
|
|
460
|
-
}
|
|
461
|
-
// Collect all hooks from shared directory
|
|
462
|
-
const sharedDir = path.join(source, 'hooks');
|
|
463
|
-
const sharedHooks = listHookEntriesFromDir(sharedDir);
|
|
464
|
-
for (const entry of sharedHooks) {
|
|
465
|
-
try {
|
|
466
|
-
copyHook(entry, centralDir);
|
|
467
|
-
installed.push(entry.name);
|
|
468
|
-
}
|
|
469
|
-
catch (err) {
|
|
470
|
-
errors.push(`${entry.name}: ${err.message}`);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return { installed, errors };
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* List hooks from central ~/.agents/hooks/ directory.
|
|
477
|
-
*/
|
|
478
|
-
export function listCentralHooks() {
|
|
479
|
-
return listHookEntriesFromDir(getCentralHooksDir());
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Parse ~/.agents/hooks.yaml manifest.
|
|
483
|
-
* Returns hook definitions with lifecycle event metadata.
|
|
484
|
-
*/
|
|
485
|
-
export function parseHookManifest() {
|
|
486
|
-
const manifestPath = path.join(getAgentsDir(), 'hooks.yaml');
|
|
487
|
-
if (!fs.existsSync(manifestPath)) {
|
|
488
|
-
return {};
|
|
489
|
-
}
|
|
490
|
-
try {
|
|
491
|
-
const content = fs.readFileSync(manifestPath, 'utf-8');
|
|
492
|
-
const parsed = yaml.parse(content);
|
|
493
|
-
return parsed || {};
|
|
494
|
-
}
|
|
495
|
-
catch {
|
|
496
|
-
return {};
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
// Codex events that support a matcher field (matches tool name or session type).
|
|
500
|
-
// UserPromptSubmit and Stop never include a matcher.
|
|
501
|
-
const CODEX_MATCHER_EVENTS = new Set(['PreToolUse', 'PostToolUse', 'SessionStart']);
|
|
502
|
-
/**
|
|
503
|
-
* Register hooks as lifecycle events in an agent's config.
|
|
504
|
-
* Reads hooks.yaml manifest, merges into the agent's config file(s).
|
|
505
|
-
* Only manages hooks whose command paths are under ~/.agents/hooks/.
|
|
506
|
-
* Does not remove user-added hooks.
|
|
507
|
-
*
|
|
508
|
-
* @param agentsDirOverride - Override the agents dir (used in tests to inject a temp path).
|
|
509
|
-
*/
|
|
510
|
-
export function registerHooksToSettings(agentId, versionHome, hookManifest, agentsDirOverride) {
|
|
511
|
-
const manifest = hookManifest || parseHookManifest();
|
|
512
|
-
if (Object.keys(manifest).length === 0) {
|
|
513
|
-
return { registered: [], errors: [] };
|
|
514
|
-
}
|
|
515
|
-
const agentsDir = agentsDirOverride ?? getAgentsDir();
|
|
516
|
-
if (agentId === 'claude') {
|
|
517
|
-
return registerHooksForClaude(versionHome, manifest, agentsDir);
|
|
518
|
-
}
|
|
519
|
-
if (agentId === 'codex') {
|
|
520
|
-
return registerHooksForCodex(versionHome, manifest, agentsDir);
|
|
521
|
-
}
|
|
522
|
-
if (agentId === 'gemini') {
|
|
523
|
-
return registerHooksForGemini(versionHome, manifest, agentsDir);
|
|
524
|
-
}
|
|
525
|
-
return { registered: [], errors: [] };
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Gemini has no native UserPromptSubmit event — map it to BeforeAgent,
|
|
529
|
-
* the closest lifecycle phase that fires before the model sees the prompt.
|
|
530
|
-
* Note: gemini's BeforeAgent can only APPEND via additionalContext — it
|
|
531
|
-
* cannot replace the prompt. The hook script branches on caller to emit
|
|
532
|
-
* the correct protocol.
|
|
533
|
-
*/
|
|
534
|
-
const GEMINI_EVENT_MAP = {
|
|
535
|
-
UserPromptSubmit: 'BeforeAgent',
|
|
536
|
-
};
|
|
537
|
-
function registerHooksForClaude(versionHome, manifest, agentsDir) {
|
|
538
|
-
const registered = [];
|
|
539
|
-
const errors = [];
|
|
540
|
-
const configDir = path.join(versionHome, '.claude');
|
|
541
|
-
const settingsPath = path.join(configDir, 'settings.json');
|
|
542
|
-
let config = {};
|
|
543
|
-
if (fs.existsSync(settingsPath)) {
|
|
544
|
-
try {
|
|
545
|
-
config = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
546
|
-
}
|
|
547
|
-
catch {
|
|
548
|
-
errors.push('Failed to parse settings.json');
|
|
549
|
-
return { registered, errors };
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
if (!config.hooks || typeof config.hooks !== 'object') {
|
|
553
|
-
config.hooks = {};
|
|
554
|
-
}
|
|
555
|
-
const hooks = config.hooks;
|
|
556
|
-
// Build set of all command paths the current manifest will register.
|
|
557
|
-
// Used to garbage-collect stale entries left behind after hook renames.
|
|
558
|
-
const managedHooksPrefix = path.join(agentsDir, 'hooks') + path.sep;
|
|
559
|
-
const currentManifestPaths = new Set();
|
|
560
|
-
for (const hookDef of Object.values(manifest)) {
|
|
561
|
-
if (hookDef.agents && !hookDef.agents.includes('claude'))
|
|
562
|
-
continue;
|
|
563
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
564
|
-
continue;
|
|
565
|
-
currentManifestPaths.add(path.join(agentsDir, 'hooks', hookDef.script));
|
|
566
|
-
}
|
|
567
|
-
// Remove stale entries: any hook command under ~/.agents/hooks/ that isn't
|
|
568
|
-
// in the current manifest is a leftover from a renamed/deleted hook script.
|
|
569
|
-
for (const eventEntries of Object.values(hooks)) {
|
|
570
|
-
if (!Array.isArray(eventEntries))
|
|
571
|
-
continue;
|
|
572
|
-
for (const group of eventEntries) {
|
|
573
|
-
if (!group.hooks)
|
|
574
|
-
continue;
|
|
575
|
-
group.hooks = group.hooks.filter((h) => !h.command.startsWith(managedHooksPrefix) || currentManifestPaths.has(h.command));
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
// Remove empty matcher groups left after cleanup
|
|
579
|
-
for (const [event, eventEntries] of Object.entries(hooks)) {
|
|
580
|
-
if (!Array.isArray(eventEntries))
|
|
581
|
-
continue;
|
|
582
|
-
hooks[event] = eventEntries.filter((g) => g.hooks && g.hooks.length > 0);
|
|
583
|
-
}
|
|
584
|
-
for (const [name, hookDef] of Object.entries(manifest)) {
|
|
585
|
-
if (hookDef.agents && !hookDef.agents.includes('claude'))
|
|
586
|
-
continue;
|
|
587
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
588
|
-
continue;
|
|
589
|
-
const commandPath = path.join(agentsDir, 'hooks', hookDef.script);
|
|
590
|
-
if (!fs.existsSync(commandPath)) {
|
|
591
|
-
errors.push(`${name}: script not found at ${commandPath}`);
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
for (const event of hookDef.events) {
|
|
595
|
-
if (!hooks[event]) {
|
|
596
|
-
hooks[event] = [];
|
|
597
|
-
}
|
|
598
|
-
const eventEntries = hooks[event];
|
|
599
|
-
const matcher = hookDef.matcher || '';
|
|
600
|
-
const timeout = hookDef.timeout || 600;
|
|
601
|
-
let matcherGroup = eventEntries.find((e) => (e.matcher || '') === matcher);
|
|
602
|
-
if (!matcherGroup) {
|
|
603
|
-
matcherGroup = { matcher, hooks: [] };
|
|
604
|
-
eventEntries.push(matcherGroup);
|
|
605
|
-
}
|
|
606
|
-
if (!matcherGroup.hooks) {
|
|
607
|
-
matcherGroup.hooks = [];
|
|
608
|
-
}
|
|
609
|
-
const existingIdx = matcherGroup.hooks.findIndex((h) => h.command === commandPath);
|
|
610
|
-
const hookEntry = { type: 'command', command: commandPath, timeout };
|
|
611
|
-
if (existingIdx >= 0) {
|
|
612
|
-
matcherGroup.hooks[existingIdx] = hookEntry;
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
matcherGroup.hooks.push(hookEntry);
|
|
616
|
-
}
|
|
617
|
-
registered.push(`${name} -> ${event}`);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
try {
|
|
621
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
622
|
-
fs.writeFileSync(settingsPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
623
|
-
}
|
|
624
|
-
catch (err) {
|
|
625
|
-
errors.push(`Failed to write settings.json: ${err.message}`);
|
|
626
|
-
}
|
|
627
|
-
return { registered, errors };
|
|
628
|
-
}
|
|
629
|
-
function registerHooksForCodex(versionHome, manifest, agentsDir) {
|
|
630
|
-
const registered = [];
|
|
631
|
-
const errors = [];
|
|
632
|
-
const configDir = path.join(versionHome, '.codex');
|
|
633
|
-
const hooksPath = path.join(configDir, 'hooks.json');
|
|
634
|
-
const configPath = path.join(configDir, 'config.toml');
|
|
635
|
-
// Read existing hooks.json — must have top-level "hooks" wrapper key
|
|
636
|
-
let hooksFile = { hooks: {} };
|
|
637
|
-
if (fs.existsSync(hooksPath)) {
|
|
638
|
-
try {
|
|
639
|
-
const existing = JSON.parse(fs.readFileSync(hooksPath, 'utf-8'));
|
|
640
|
-
if (existing &&
|
|
641
|
-
typeof existing === 'object' &&
|
|
642
|
-
!Array.isArray(existing) &&
|
|
643
|
-
existing.hooks &&
|
|
644
|
-
typeof existing.hooks === 'object') {
|
|
645
|
-
hooksFile = existing;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
catch {
|
|
649
|
-
errors.push('Failed to parse hooks.json');
|
|
650
|
-
return { registered, errors };
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
// Build set of current manifest command paths for codex to GC stale entries
|
|
654
|
-
const managedHooksPrefix = path.join(agentsDir, 'hooks') + path.sep;
|
|
655
|
-
const currentManifestPaths = new Set();
|
|
656
|
-
for (const hookDef of Object.values(manifest)) {
|
|
657
|
-
if (hookDef.agents && !hookDef.agents.includes('codex'))
|
|
658
|
-
continue;
|
|
659
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
660
|
-
continue;
|
|
661
|
-
currentManifestPaths.add(path.join(agentsDir, 'hooks', hookDef.script));
|
|
662
|
-
}
|
|
663
|
-
// Remove stale entries from all event groups
|
|
664
|
-
for (const eventGroups of Object.values(hooksFile.hooks)) {
|
|
665
|
-
for (const group of eventGroups) {
|
|
666
|
-
if (!group.hooks)
|
|
667
|
-
continue;
|
|
668
|
-
group.hooks = group.hooks.filter((h) => !h.command.startsWith(managedHooksPrefix) || currentManifestPaths.has(h.command));
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
for (const [event, eventGroups] of Object.entries(hooksFile.hooks)) {
|
|
672
|
-
hooksFile.hooks[event] = eventGroups.filter((g) => g.hooks && g.hooks.length > 0);
|
|
673
|
-
}
|
|
674
|
-
for (const [name, hookDef] of Object.entries(manifest)) {
|
|
675
|
-
if (hookDef.agents && !hookDef.agents.includes('codex'))
|
|
676
|
-
continue;
|
|
677
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
678
|
-
continue;
|
|
679
|
-
const commandPath = path.join(agentsDir, 'hooks', hookDef.script);
|
|
680
|
-
if (!fs.existsSync(commandPath)) {
|
|
681
|
-
errors.push(`${name}: script not found at ${commandPath}`);
|
|
682
|
-
continue;
|
|
683
|
-
}
|
|
684
|
-
const timeout = hookDef.timeout || 600;
|
|
685
|
-
for (const event of hookDef.events) {
|
|
686
|
-
if (!hooksFile.hooks[event]) {
|
|
687
|
-
hooksFile.hooks[event] = [];
|
|
688
|
-
}
|
|
689
|
-
const eventGroups = hooksFile.hooks[event];
|
|
690
|
-
// PreToolUse / PostToolUse / SessionStart use a matcher field.
|
|
691
|
-
// UserPromptSubmit / Stop never include a matcher.
|
|
692
|
-
const usesMatcher = CODEX_MATCHER_EVENTS.has(event);
|
|
693
|
-
const matcherValue = usesMatcher ? (hookDef.matcher ?? '') : undefined;
|
|
694
|
-
// Find the group for this matcher (or the sole no-matcher group)
|
|
695
|
-
let group;
|
|
696
|
-
if (matcherValue !== undefined) {
|
|
697
|
-
group = eventGroups.find((g) => (g.matcher ?? '') === matcherValue);
|
|
698
|
-
if (!group) {
|
|
699
|
-
group = matcherValue ? { matcher: matcherValue, hooks: [] } : { hooks: [] };
|
|
700
|
-
eventGroups.push(group);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
else {
|
|
704
|
-
group = eventGroups.find((g) => g.matcher === undefined);
|
|
705
|
-
if (!group) {
|
|
706
|
-
group = { hooks: [] };
|
|
707
|
-
eventGroups.push(group);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
if (!group.hooks) {
|
|
711
|
-
group.hooks = [];
|
|
712
|
-
}
|
|
713
|
-
const existingIdx = group.hooks.findIndex((h) => h.command === commandPath);
|
|
714
|
-
const hookEntry = { type: 'command', command: commandPath, timeout };
|
|
715
|
-
if (existingIdx >= 0) {
|
|
716
|
-
group.hooks[existingIdx] = hookEntry;
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
group.hooks.push(hookEntry);
|
|
720
|
-
}
|
|
721
|
-
registered.push(`${name} -> ${event}`);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
if (registered.length === 0) {
|
|
725
|
-
return { registered, errors };
|
|
726
|
-
}
|
|
727
|
-
try {
|
|
728
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
729
|
-
fs.writeFileSync(hooksPath, JSON.stringify(hooksFile, null, 2), 'utf-8');
|
|
730
|
-
}
|
|
731
|
-
catch (err) {
|
|
732
|
-
errors.push(`Failed to write hooks.json: ${err.message}`);
|
|
733
|
-
return { registered, errors };
|
|
734
|
-
}
|
|
735
|
-
// Ensure [features] codex_hooks = true in config.toml
|
|
736
|
-
try {
|
|
737
|
-
let tomlConfig = {};
|
|
738
|
-
if (fs.existsSync(configPath)) {
|
|
739
|
-
try {
|
|
740
|
-
tomlConfig = TOML.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
741
|
-
}
|
|
742
|
-
catch { /* start fresh if corrupt */ }
|
|
743
|
-
}
|
|
744
|
-
if (!tomlConfig.features || typeof tomlConfig.features !== 'object') {
|
|
745
|
-
tomlConfig.features = {};
|
|
746
|
-
}
|
|
747
|
-
tomlConfig.features.codex_hooks = true;
|
|
748
|
-
fs.writeFileSync(configPath, TOML.stringify(tomlConfig), 'utf-8');
|
|
749
|
-
}
|
|
750
|
-
catch (err) {
|
|
751
|
-
errors.push(`Failed to update config.toml: ${err.message}`);
|
|
752
|
-
}
|
|
753
|
-
return { registered, errors };
|
|
754
|
-
}
|
|
755
|
-
function registerHooksForGemini(versionHome, manifest, agentsDir) {
|
|
756
|
-
const registered = [];
|
|
757
|
-
const errors = [];
|
|
758
|
-
const configDir = path.join(versionHome, '.gemini');
|
|
759
|
-
const settingsPath = path.join(configDir, 'settings.json');
|
|
760
|
-
let config = {};
|
|
761
|
-
if (fs.existsSync(settingsPath)) {
|
|
762
|
-
try {
|
|
763
|
-
config = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
764
|
-
}
|
|
765
|
-
catch {
|
|
766
|
-
errors.push('Failed to parse gemini settings.json');
|
|
767
|
-
return { registered, errors };
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
if (!config.hooks || typeof config.hooks !== 'object') {
|
|
771
|
-
config.hooks = {};
|
|
772
|
-
}
|
|
773
|
-
const hooks = config.hooks;
|
|
774
|
-
// Build set of current manifest command paths for gemini to GC stale entries
|
|
775
|
-
const managedHooksPrefix = path.join(agentsDir, 'hooks') + path.sep;
|
|
776
|
-
const currentManifestPaths = new Set();
|
|
777
|
-
for (const hookDef of Object.values(manifest)) {
|
|
778
|
-
if (hookDef.agents && !hookDef.agents.includes('gemini'))
|
|
779
|
-
continue;
|
|
780
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
781
|
-
continue;
|
|
782
|
-
currentManifestPaths.add(path.join(agentsDir, 'hooks', hookDef.script));
|
|
783
|
-
}
|
|
784
|
-
// Remove stale entries
|
|
785
|
-
for (const eventEntries of Object.values(hooks)) {
|
|
786
|
-
if (!Array.isArray(eventEntries))
|
|
787
|
-
continue;
|
|
788
|
-
for (const group of eventEntries) {
|
|
789
|
-
if (!group.hooks)
|
|
790
|
-
continue;
|
|
791
|
-
group.hooks = group.hooks.filter((h) => !h.command.startsWith(managedHooksPrefix) || currentManifestPaths.has(h.command));
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
for (const [event, eventEntries] of Object.entries(hooks)) {
|
|
795
|
-
if (!Array.isArray(eventEntries))
|
|
796
|
-
continue;
|
|
797
|
-
hooks[event] = eventEntries.filter((g) => g.hooks && g.hooks.length > 0);
|
|
798
|
-
}
|
|
799
|
-
for (const [name, hookDef] of Object.entries(manifest)) {
|
|
800
|
-
if (hookDef.agents && !hookDef.agents.includes('gemini'))
|
|
801
|
-
continue;
|
|
802
|
-
if (!hookDef.events || hookDef.events.length === 0)
|
|
803
|
-
continue;
|
|
804
|
-
const commandPath = path.join(agentsDir, 'hooks', hookDef.script);
|
|
805
|
-
if (!fs.existsSync(commandPath)) {
|
|
806
|
-
errors.push(`${name}: script not found at ${commandPath}`);
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
// Gemini timeouts are in milliseconds; manifest timeouts are seconds.
|
|
810
|
-
const timeoutMs = (hookDef.timeout || 600) * 1000;
|
|
811
|
-
for (const event of hookDef.events) {
|
|
812
|
-
const geminiEvent = GEMINI_EVENT_MAP[event] ?? event;
|
|
813
|
-
if (!hooks[geminiEvent]) {
|
|
814
|
-
hooks[geminiEvent] = [];
|
|
815
|
-
}
|
|
816
|
-
const eventEntries = hooks[geminiEvent];
|
|
817
|
-
const matcher = hookDef.matcher || '';
|
|
818
|
-
let matcherGroup = eventEntries.find((e) => (e.matcher || '') === matcher);
|
|
819
|
-
if (!matcherGroup) {
|
|
820
|
-
matcherGroup = { matcher, hooks: [] };
|
|
821
|
-
eventEntries.push(matcherGroup);
|
|
822
|
-
}
|
|
823
|
-
if (!matcherGroup.hooks) {
|
|
824
|
-
matcherGroup.hooks = [];
|
|
825
|
-
}
|
|
826
|
-
const existingIdx = matcherGroup.hooks.findIndex((h) => h.command === commandPath);
|
|
827
|
-
const hookEntry = { name, type: 'command', command: commandPath, timeout: timeoutMs };
|
|
828
|
-
if (existingIdx >= 0) {
|
|
829
|
-
matcherGroup.hooks[existingIdx] = hookEntry;
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
matcherGroup.hooks.push(hookEntry);
|
|
833
|
-
}
|
|
834
|
-
registered.push(`${name} -> ${geminiEvent}`);
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
try {
|
|
838
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
839
|
-
fs.writeFileSync(settingsPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
840
|
-
}
|
|
841
|
-
catch (err) {
|
|
842
|
-
errors.push(`Failed to write gemini settings.json: ${err.message}`);
|
|
843
|
-
}
|
|
844
|
-
return { registered, errors };
|
|
845
|
-
}
|
|
846
|
-
//# sourceMappingURL=hooks.js.map
|