rulesync 43.13.0 → 43.15.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 +5 -3
- package/dist/cli/index.cjs +5 -5
- package/dist/cli/index.js +5 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-Djgg1Lrf.cjs → import-CYrusraB.cjs} +1749 -145
- package/dist/{import-9NB0tQm3.js → import-Ch9kXISC.js} +1723 -119
- package/dist/{import-9NB0tQm3.js.map → import-Ch9kXISC.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -746,6 +746,7 @@ const subagentsProcessorToolTargetTuple = [
|
|
|
746
746
|
"omp",
|
|
747
747
|
"opencode",
|
|
748
748
|
"opencodev1",
|
|
749
|
+
"openbitfun",
|
|
749
750
|
"pool",
|
|
750
751
|
"qoder",
|
|
751
752
|
"qwencode",
|
|
@@ -806,6 +807,7 @@ const skillsProcessorToolTargetTuple = [
|
|
|
806
807
|
"omp",
|
|
807
808
|
"opencode",
|
|
808
809
|
"opencodev1",
|
|
810
|
+
"openbitfun",
|
|
809
811
|
"pi",
|
|
810
812
|
"pool",
|
|
811
813
|
"qoder",
|
|
@@ -854,6 +856,7 @@ const hooksProcessorToolTargetTuple = [
|
|
|
854
856
|
"omp",
|
|
855
857
|
"opencode",
|
|
856
858
|
"opencodev1",
|
|
859
|
+
"openbitfun",
|
|
857
860
|
"pi",
|
|
858
861
|
"pool",
|
|
859
862
|
"factorydroid",
|
|
@@ -904,6 +907,7 @@ const permissionsProcessorToolTargetTuple = [
|
|
|
904
907
|
"deepagents",
|
|
905
908
|
"devin",
|
|
906
909
|
"factorydroid",
|
|
910
|
+
"gitlabduo",
|
|
907
911
|
"goose",
|
|
908
912
|
"grokcli",
|
|
909
913
|
"hermesagent",
|
|
@@ -5563,20 +5567,57 @@ const CANONICAL_TO_BOB_EVENT_NAMES = {
|
|
|
5563
5567
|
stop: "Stop"
|
|
5564
5568
|
};
|
|
5565
5569
|
/**
|
|
5566
|
-
* Hook events
|
|
5570
|
+
* Hook events rulesync emits for IBM Bob from the shared `hooks` block.
|
|
5567
5571
|
*
|
|
5568
5572
|
* Bob reads `hooks` from `.bob/settings.json` (project) and
|
|
5569
5573
|
* `~/.bob/settings/settings.json` (user) in the Claude-Code shape and fires
|
|
5570
|
-
* seven events: SessionStart, UserPromptSubmit, PreToolUse,
|
|
5571
|
-
* PreCompact, PostCompact and Stop (Bob IDE and Bob Shell list
|
|
5572
|
-
* seven). Handlers are `command` or `http` hooks.
|
|
5573
|
-
*
|
|
5574
|
-
*
|
|
5574
|
+
* seven documented events: SessionStart, UserPromptSubmit, PreToolUse,
|
|
5575
|
+
* PostToolUse, PreCompact, PostCompact and Stop (Bob IDE and Bob Shell list
|
|
5576
|
+
* the same seven). Handlers are `command` or `http` hooks. Bob Shell 2.1.0
|
|
5577
|
+
* adds more events; see {@link BOB_OPT_IN_HOOK_EVENTS} for why they are not
|
|
5578
|
+
* emitted from the shared block.
|
|
5575
5579
|
*
|
|
5576
5580
|
* @see https://bob.ibm.com/docs/shell/configuration/lifecycle-hooks
|
|
5577
5581
|
* @see https://bob.ibm.com/docs/ide/configuration/lifecycle-hooks
|
|
5578
5582
|
*/
|
|
5579
5583
|
const BOB_HOOK_EVENTS = eventsOf(CANONICAL_TO_BOB_EVENT_NAMES);
|
|
5584
|
+
/**
|
|
5585
|
+
* The {@link BOB_HOOK_EVENTS} whose `matcher` regex Bob applies: the tool name
|
|
5586
|
+
* on PreToolUse / PostToolUse, `source` on SessionStart and `trigger` on
|
|
5587
|
+
* PreCompact / PostCompact. UserPromptSubmit and Stop have no matchable value.
|
|
5588
|
+
*/
|
|
5589
|
+
const BOB_MATCHER_HOOK_EVENTS = BOB_HOOK_EVENTS.filter((event) => event !== "beforeSubmitPrompt" && event !== "stop");
|
|
5590
|
+
/**
|
|
5591
|
+
* Canonical events that Bob Shell 2.1.0 (`@ibm/bob` on npm, 2026-11-09) can
|
|
5592
|
+
* fire under the native name given here, next to the override-only
|
|
5593
|
+
* `PermissionResolved`. They are not on the lifecycle-hooks pages yet.
|
|
5594
|
+
*
|
|
5595
|
+
* They are deliberately not emitted from the shared `hooks` block: Bob Shell
|
|
5596
|
+
* before 2.1.0 validates the `hooks` object strictly against the seven
|
|
5597
|
+
* documented keys, and on any unknown key it ignores that settings file's
|
|
5598
|
+
* whole `hooks` block (PreToolUse guards included). Writing them must
|
|
5599
|
+
* therefore be an explicit opt-in under the `bob.hooks` override block, by
|
|
5600
|
+
* their native name, which is emitted verbatim and imported back there.
|
|
5601
|
+
*
|
|
5602
|
+
* @see https://registry.npmjs.org/@ibm/bob/-/bob-2.1.0.tgz
|
|
5603
|
+
*/
|
|
5604
|
+
const BOB_OPT_IN_HOOK_EVENTS = {
|
|
5605
|
+
sessionEnd: "SessionEnd",
|
|
5606
|
+
permissionRequest: "PermissionRequest",
|
|
5607
|
+
notification: "Notification"
|
|
5608
|
+
};
|
|
5609
|
+
/**
|
|
5610
|
+
* Every native event key Bob Shell 2.1.0's strict hooks schema accepts: the
|
|
5611
|
+
* seven documented events, the three opt-in ones and `PermissionResolved`,
|
|
5612
|
+
* which has no canonical counterpart. Any other key under `bob.hooks` is
|
|
5613
|
+
* dropped on generate, because one unknown key makes Bob ignore the file's
|
|
5614
|
+
* whole hooks block.
|
|
5615
|
+
*/
|
|
5616
|
+
const BOB_NATIVE_HOOK_EVENTS = [
|
|
5617
|
+
...Object.values(CANONICAL_TO_BOB_EVENT_NAMES),
|
|
5618
|
+
...Object.values(BOB_OPT_IN_HOOK_EVENTS),
|
|
5619
|
+
"PermissionResolved"
|
|
5620
|
+
];
|
|
5580
5621
|
const BOB_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_BOB_EVENT_NAMES);
|
|
5581
5622
|
const CANONICAL_TO_TABNINE_EVENT_NAMES = {
|
|
5582
5623
|
sessionStart: "SessionStart",
|
|
@@ -5859,17 +5900,18 @@ const CONTINUE_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_CONTINUE_EVE
|
|
|
5859
5900
|
* observers, `gateway_platform_event` and `transform_api_error_classification`.
|
|
5860
5901
|
* Shell hooks are gated on the same set.
|
|
5861
5902
|
*
|
|
5862
|
-
* Verified against the tag `v0.23.
|
|
5903
|
+
* Verified against the tag `v0.23.4`: `VALID_HOOKS` holds 50 entries, grown
|
|
5863
5904
|
* from 23 at `v2026.8.3` (v0.20.0) and 37 at `v2026.8.16` (v0.20.2) — v0.21
|
|
5864
5905
|
* added `agent_loop_stopped` and `on_room_member_activity`, v0.21.5 added
|
|
5865
5906
|
* `pre_auxiliary_call` and `post_auxiliary_call`, v0.21.6 added
|
|
5866
5907
|
* `post_gateway_admission`, `on_human_input_request` and
|
|
5867
5908
|
* `on_human_input_resolved`, v0.22.3 added `on_session_delete` and
|
|
5868
|
-
* `post_compaction`,
|
|
5869
|
-
* `post_curator_run
|
|
5909
|
+
* `post_compaction`, v0.23.1 added `on_session_open` and
|
|
5910
|
+
* `post_curator_run`, and v0.23.4 added `on_session_prompt` and
|
|
5911
|
+
* `on_session_prompt_settled`. This list holds 49 of them — see
|
|
5870
5912
|
* {@link HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS} for the exclusion.
|
|
5871
5913
|
*
|
|
5872
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.
|
|
5914
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.4/hermes_cli/plugins.py
|
|
5873
5915
|
*/
|
|
5874
5916
|
const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
5875
5917
|
"pre_tool_call",
|
|
@@ -5895,6 +5937,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5895
5937
|
"on_session_reset",
|
|
5896
5938
|
"on_session_delete",
|
|
5897
5939
|
"on_session_open",
|
|
5940
|
+
"on_session_prompt",
|
|
5941
|
+
"on_session_prompt_settled",
|
|
5898
5942
|
"on_skill_lifecycle",
|
|
5899
5943
|
"subagent_start",
|
|
5900
5944
|
"subagent_stop",
|
|
@@ -5930,8 +5974,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5930
5974
|
* rulesync only ever writes shell hooks, so these are excluded from
|
|
5931
5975
|
* {@link HERMESAGENT_NATIVE_HOOK_EVENTS} and warned about with their own message.
|
|
5932
5976
|
*
|
|
5933
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.
|
|
5934
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.
|
|
5977
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.4/hermes_cli/plugins.py — `SHELL_UNSUPPORTED_HOOKS`
|
|
5978
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.4/agent/shell_hooks.py — `_parse_hooks_block`
|
|
5935
5979
|
*/
|
|
5936
5980
|
const HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS = ["transform_api_error_classification"];
|
|
5937
5981
|
/**
|
|
@@ -5951,8 +5995,8 @@ const CANONICAL_TO_HERMESAGENT_EVENT_NAMES = {
|
|
|
5951
5995
|
/**
|
|
5952
5996
|
* Hook events supported by Hermes Agent's native Shell Hooks system.
|
|
5953
5997
|
*
|
|
5954
|
-
* Hermes validates hook events against a fixed `VALID_HOOKS` set —
|
|
5955
|
-
* of v0.23.
|
|
5998
|
+
* Hermes validates hook events against a fixed `VALID_HOOKS` set — 50 entries as
|
|
5999
|
+
* of v0.23.4 (tag `v0.23.4`); see {@link HERMESAGENT_NATIVE_HOOK_EVENTS} for the
|
|
5956
6000
|
* full list. Only the events with a clean 1:1 canonical equivalent are mapped
|
|
5957
6001
|
* here. All other native events round-trip through `hermesagent.hooks`.
|
|
5958
6002
|
* @see https://github.com/NousResearch/hermes-agent/blob/main/website/docs/user-guide/features/hooks.md
|
|
@@ -6002,6 +6046,7 @@ const HooksConfigSchema = z.looseObject({
|
|
|
6002
6046
|
amp: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6003
6047
|
factorydroid: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6004
6048
|
codexcli: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6049
|
+
openbitfun: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6005
6050
|
goose: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6006
6051
|
deepagents: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
6007
6052
|
kiro: z.optional(z.looseObject({ hooks: z.optional(hooksRecordSchema) })),
|
|
@@ -6578,6 +6623,32 @@ const CODEXCLI_HOOK_EVENTS = eventsOf(CANONICAL_TO_CODEXCLI_EVENT_NAMES);
|
|
|
6578
6623
|
*/
|
|
6579
6624
|
const CODEXCLI_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_CODEXCLI_EVENT_NAMES);
|
|
6580
6625
|
/**
|
|
6626
|
+
* Map canonical camelCase event names to OpenBitFun PascalCase. OpenBitFun
|
|
6627
|
+
* implements the Codex hook contract with Codex's event names, minus the
|
|
6628
|
+
* events it does not dispatch (`Interrupt`, `PreModelRequest`,
|
|
6629
|
+
* `PostModelRequest`).
|
|
6630
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/docs/features/agent-hooks.md
|
|
6631
|
+
*/
|
|
6632
|
+
const CANONICAL_TO_OPENBITFUN_EVENT_NAMES = {
|
|
6633
|
+
sessionStart: "SessionStart",
|
|
6634
|
+
sessionEnd: "SessionEnd",
|
|
6635
|
+
preToolUse: "PreToolUse",
|
|
6636
|
+
postToolUse: "PostToolUse",
|
|
6637
|
+
beforeSubmitPrompt: "UserPromptSubmit",
|
|
6638
|
+
stop: "Stop",
|
|
6639
|
+
permissionRequest: "PermissionRequest",
|
|
6640
|
+
subagentStart: "SubagentStart",
|
|
6641
|
+
subagentStop: "SubagentStop",
|
|
6642
|
+
preCompact: "PreCompact",
|
|
6643
|
+
postCompact: "PostCompact"
|
|
6644
|
+
};
|
|
6645
|
+
/** Hook events supported by OpenBitFun. */
|
|
6646
|
+
const OPENBITFUN_HOOK_EVENTS = eventsOf(CANONICAL_TO_OPENBITFUN_EVENT_NAMES);
|
|
6647
|
+
/**
|
|
6648
|
+
* Map OpenBitFun PascalCase event names to canonical camelCase.
|
|
6649
|
+
*/
|
|
6650
|
+
const OPENBITFUN_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_OPENBITFUN_EVENT_NAMES);
|
|
6651
|
+
/**
|
|
6581
6652
|
* Map canonical camelCase event names to Goose PascalCase.
|
|
6582
6653
|
*/
|
|
6583
6654
|
const CANONICAL_TO_GOOSE_EVENT_NAMES = {
|
|
@@ -9769,6 +9840,7 @@ const PermissionsConfigSchema = z.looseObject({
|
|
|
9769
9840
|
commandcode: z.optional(CommandcodePermissionsOverrideSchema),
|
|
9770
9841
|
lettacode: z.optional(CanonicalPermissionsOverrideSchema),
|
|
9771
9842
|
crush: z.optional(CanonicalPermissionsOverrideSchema),
|
|
9843
|
+
gitlabduo: z.optional(CanonicalPermissionsOverrideSchema),
|
|
9772
9844
|
goose: z.optional(CanonicalPermissionsOverrideSchema),
|
|
9773
9845
|
omp: z.optional(OmpPermissionsOverrideSchema),
|
|
9774
9846
|
pool: z.optional(CanonicalPermissionsOverrideSchema),
|
|
@@ -18278,6 +18350,14 @@ const GITLABDUO_DIR = join(".gitlab", "duo");
|
|
|
18278
18350
|
const GITLABDUO_RULE_FILE_NAME = "chat-rules.md";
|
|
18279
18351
|
/** MCP servers. @see https://docs.gitlab.com/user/gitlab_duo/model_context_protocol/mcp_clients/ */
|
|
18280
18352
|
const GITLABDUO_MCP_FILE_NAME = "mcp.json";
|
|
18353
|
+
/**
|
|
18354
|
+
* Settings. Only the user file `~/.gitlab/duo/settings.json` carries the
|
|
18355
|
+
* `permissions` setting rulesync writes; the project files are deliberately not
|
|
18356
|
+
* read for it.
|
|
18357
|
+
*
|
|
18358
|
+
* @see https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/blob/v10.5.0/packages/core/settings/src/definitions.ts
|
|
18359
|
+
*/
|
|
18360
|
+
const GITLABDUO_SETTINGS_FILE_NAME = "settings.json";
|
|
18281
18361
|
/** Lifecycle hooks (experiment). @see https://docs.gitlab.com/user/gitlab_duo_cli/customize/ */
|
|
18282
18362
|
const GITLABDUO_HOOKS_FILE_NAME = "hooks.json";
|
|
18283
18363
|
/** Merge request review instructions. @see https://docs.gitlab.com/user/project/merge_requests/duo_in_merge_requests/ */
|
|
@@ -28072,6 +28152,135 @@ var PiSkill = class extends ToolSkill {
|
|
|
28072
28152
|
var OmpSkill = class extends PiSkill {
|
|
28073
28153
|
static layout = OMP_LAYOUT;
|
|
28074
28154
|
};
|
|
28155
|
+
// src/constants/openbitfun-paths.ts
|
|
28156
|
+
/**
|
|
28157
|
+
* OpenBitFun configuration-layout conventions.
|
|
28158
|
+
*
|
|
28159
|
+
* OpenBitFun (formerly BitFun) keeps its project assets under a `.openbitfun/`
|
|
28160
|
+
* directory at the project root and its user assets under an OS-dependent
|
|
28161
|
+
* user root. Rules are not written here: OpenBitFun already reads the shared
|
|
28162
|
+
* `AGENTS.md` / `CLAUDE.md` / `.claude/rules/` files the `agentsmd` and
|
|
28163
|
+
* `claudecode` targets write.
|
|
28164
|
+
*
|
|
28165
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/assembly/core/src/infrastructure/app_paths/path_manager.rs
|
|
28166
|
+
*/
|
|
28167
|
+
const OPENBITFUN_DIR = ".openbitfun";
|
|
28168
|
+
const OPENBITFUN_AGENTS_DIR_NAME = "agents";
|
|
28169
|
+
const OPENBITFUN_AGENTS_DIR_PATH = join(OPENBITFUN_DIR, OPENBITFUN_AGENTS_DIR_NAME);
|
|
28170
|
+
const OPENBITFUN_SKILLS_DIR_NAME = "skills";
|
|
28171
|
+
const OPENBITFUN_SKILLS_DIR_PATH = join(OPENBITFUN_DIR, OPENBITFUN_SKILLS_DIR_NAME);
|
|
28172
|
+
const OPENBITFUN_CONFIG_DIR_NAME = "config";
|
|
28173
|
+
const OPENBITFUN_CONFIG_DIR_PATH = join(OPENBITFUN_DIR, OPENBITFUN_CONFIG_DIR_NAME);
|
|
28174
|
+
const OPENBITFUN_HOOKS_FILE_NAME = "hooks.json";
|
|
28175
|
+
const OPENBITFUN_DATA_NAMESPACE = "openbitfun";
|
|
28176
|
+
/**
|
|
28177
|
+
* OpenBitFun's user root (`dirs::config_dir()/openbitfun`), relative to the
|
|
28178
|
+
* home directory (the processor resolves the home directory through
|
|
28179
|
+
* `outputRoot`).
|
|
28180
|
+
*
|
|
28181
|
+
* - macOS: `~/Library/Application Support/openbitfun`
|
|
28182
|
+
* - Windows: `%APPDATA%\openbitfun` (`~/AppData/Roaming/openbitfun`)
|
|
28183
|
+
* - Linux and others: `~/.config/openbitfun`
|
|
28184
|
+
*
|
|
28185
|
+
* `$XDG_CONFIG_HOME` and OpenBitFun's `OPENBITFUN_USER_ROOT` override are not
|
|
28186
|
+
* followed; the default locations are assumed (a non-default `$XDG_CONFIG_HOME`
|
|
28187
|
+
* is warned about, see `warnOpenbitfunXdgOverride`).
|
|
28188
|
+
*/
|
|
28189
|
+
function openbitfunGlobalRootDir() {
|
|
28190
|
+
switch (process.platform) {
|
|
28191
|
+
case "darwin": return join("Library", "Application Support", OPENBITFUN_DATA_NAMESPACE);
|
|
28192
|
+
case "win32": return join("AppData", "Roaming", OPENBITFUN_DATA_NAMESPACE);
|
|
28193
|
+
default: return join(".config", OPENBITFUN_DATA_NAMESPACE);
|
|
28194
|
+
}
|
|
28195
|
+
}
|
|
28196
|
+
/**
|
|
28197
|
+
* OpenBitFun's user agents directory: `<user root>/agents`.
|
|
28198
|
+
*/
|
|
28199
|
+
function openbitfunGlobalAgentsDir() {
|
|
28200
|
+
return join(openbitfunGlobalRootDir(), OPENBITFUN_AGENTS_DIR_NAME);
|
|
28201
|
+
}
|
|
28202
|
+
/**
|
|
28203
|
+
* OpenBitFun's user hooks directory: `<user root>/config` (holding `hooks.json`).
|
|
28204
|
+
*/
|
|
28205
|
+
function openbitfunGlobalConfigDir() {
|
|
28206
|
+
return join(openbitfunGlobalRootDir(), OPENBITFUN_CONFIG_DIR_NAME);
|
|
28207
|
+
}
|
|
28208
|
+
/**
|
|
28209
|
+
* OpenBitFun's user skills directory (`user_skills_dir` in `path_manager.rs`).
|
|
28210
|
+
* It is not always under the user root: on Linux it lives in the data dir
|
|
28211
|
+
* (`dirs::data_local_dir()`), not the config dir.
|
|
28212
|
+
*
|
|
28213
|
+
* - macOS: `~/Library/Application Support/openbitfun/skills`
|
|
28214
|
+
* - Windows: `%APPDATA%\openbitfun\skills`
|
|
28215
|
+
* - Linux and others: `~/.local/share/openbitfun/skills`
|
|
28216
|
+
*
|
|
28217
|
+
* `$XDG_DATA_HOME` is not followed; the default location is assumed (a
|
|
28218
|
+
* non-default value is warned about, see `warnOpenbitfunXdgOverride`).
|
|
28219
|
+
*/
|
|
28220
|
+
function openbitfunGlobalSkillsDir() {
|
|
28221
|
+
switch (process.platform) {
|
|
28222
|
+
case "darwin":
|
|
28223
|
+
case "win32": return join(openbitfunGlobalRootDir(), OPENBITFUN_SKILLS_DIR_NAME);
|
|
28224
|
+
default: return join(".local", "share", OPENBITFUN_DATA_NAMESPACE, OPENBITFUN_SKILLS_DIR_NAME);
|
|
28225
|
+
}
|
|
28226
|
+
}
|
|
28227
|
+
// src/utils/openbitfun.ts
|
|
28228
|
+
const XDG_OVERRIDES = {
|
|
28229
|
+
config: {
|
|
28230
|
+
envVar: "XDG_CONFIG_HOME",
|
|
28231
|
+
defaultDir: ".config"
|
|
28232
|
+
},
|
|
28233
|
+
data: {
|
|
28234
|
+
envVar: "XDG_DATA_HOME",
|
|
28235
|
+
defaultDir: join(".local", "share")
|
|
28236
|
+
}
|
|
28237
|
+
};
|
|
28238
|
+
/**
|
|
28239
|
+
* Warn, once per run, when an XDG base directory variable moves OpenBitFun's
|
|
28240
|
+
* user tree away from where rulesync writes it in global mode.
|
|
28241
|
+
*
|
|
28242
|
+
* On Linux OpenBitFun resolves its user root through the `dirs` crate
|
|
28243
|
+
* (`dirs::config_dir()`, and `dirs::data_local_dir()` for skills), which
|
|
28244
|
+
* follows `$XDG_CONFIG_HOME` / `$XDG_DATA_HOME` when set to an absolute path.
|
|
28245
|
+
* rulesync writes global files relative to the home directory, at the XDG
|
|
28246
|
+
* default location, so a non-default value means OpenBitFun reads elsewhere.
|
|
28247
|
+
* macOS and Windows do not use these variables.
|
|
28248
|
+
*
|
|
28249
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/assembly/core/src/infrastructure/app_paths/path_manager.rs
|
|
28250
|
+
*/
|
|
28251
|
+
function warnOpenbitfunXdgOverride({ kind, logger }) {
|
|
28252
|
+
if (process.platform === "darwin" || process.platform === "win32") return;
|
|
28253
|
+
const { envVar, defaultDir } = XDG_OVERRIDES[kind];
|
|
28254
|
+
const value = process.env[envVar]?.trim();
|
|
28255
|
+
if (!value || !isAbsolute(value)) return;
|
|
28256
|
+
const defaultPath = join(getHomeDirectory(), defaultDir);
|
|
28257
|
+
if (resolve(value) === resolve(defaultPath)) return;
|
|
28258
|
+
warnOnceWithFallback(logger, `$${envVar} is set to ${value}, so OpenBitFun reads its user files from ${join(value, "openbitfun")}, but rulesync writes OpenBitFun's global files under ${join("~", defaultDir, "openbitfun")}. Move them there or unset $${envVar} for OpenBitFun.`);
|
|
28259
|
+
}
|
|
28260
|
+
// src/features/skills/openbitfun-skill.ts
|
|
28261
|
+
/**
|
|
28262
|
+
* OpenBitFun skills follow the Agent Skills layout (`<name>/SKILL.md` with
|
|
28263
|
+
* `name` and `description` frontmatter, plus optional supporting files), so
|
|
28264
|
+
* this target reuses {@link AgentsSkillsSkill} with OpenBitFun's locations:
|
|
28265
|
+
* `.openbitfun/skills/` (project) and the OS-dependent user skills directory
|
|
28266
|
+
* (global, see {@link openbitfunGlobalSkillsDir}). A project skill shadows a
|
|
28267
|
+
* user skill of the same name.
|
|
28268
|
+
*
|
|
28269
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/docs/interactive-capabilities/capabilities/feature.skills.md
|
|
28270
|
+
*/
|
|
28271
|
+
var OpenbitfunSkill = class extends AgentsSkillsSkill {
|
|
28272
|
+
static getSettablePaths({ global = false } = {}) {
|
|
28273
|
+
return { relativeDirPath: global ? openbitfunGlobalSkillsDir() : OPENBITFUN_SKILLS_DIR_PATH };
|
|
28274
|
+
}
|
|
28275
|
+
static fromRulesyncSkill(params) {
|
|
28276
|
+
if (params.global) warnOpenbitfunXdgOverride({
|
|
28277
|
+
kind: "data",
|
|
28278
|
+
logger: params.logger
|
|
28279
|
+
});
|
|
28280
|
+
return super.fromRulesyncSkill(params);
|
|
28281
|
+
}
|
|
28282
|
+
static toolTarget = "openbitfun";
|
|
28283
|
+
};
|
|
28075
28284
|
// src/constants/openclaw-paths.ts
|
|
28076
28285
|
const OPENCLAW_WORKSPACE_DIR_PATH = join(".openclaw", "workspace");
|
|
28077
28286
|
const OPENCLAW_RULE_FILE_NAME = "AGENTS.md";
|
|
@@ -30199,6 +30408,14 @@ const toolSkillFactories = /* @__PURE__ */ new Map([
|
|
|
30199
30408
|
supportsGlobal: true
|
|
30200
30409
|
}
|
|
30201
30410
|
}],
|
|
30411
|
+
["openbitfun", {
|
|
30412
|
+
class: OpenbitfunSkill,
|
|
30413
|
+
meta: {
|
|
30414
|
+
supportsProject: true,
|
|
30415
|
+
supportsSimulated: false,
|
|
30416
|
+
supportsGlobal: true
|
|
30417
|
+
}
|
|
30418
|
+
}],
|
|
30202
30419
|
["xum", {
|
|
30203
30420
|
class: XumSkill,
|
|
30204
30421
|
meta: {
|
|
@@ -36017,6 +36234,162 @@ var OmpSubagent = class extends FrontmatterMarkdownToolSubagent {
|
|
|
36017
36234
|
};
|
|
36018
36235
|
}
|
|
36019
36236
|
};
|
|
36237
|
+
// src/features/subagents/openbitfun-subagent.ts
|
|
36238
|
+
/**
|
|
36239
|
+
* The `kind` rulesync writes: a delegated subagent rather than a top-level
|
|
36240
|
+
* agent mode. It is also OpenBitFun's default when `kind` is omitted.
|
|
36241
|
+
*/
|
|
36242
|
+
const OPENBITFUN_SUBAGENT_KIND = "subagent";
|
|
36243
|
+
/**
|
|
36244
|
+
* Frontmatter of an OpenBitFun custom agent. `name` and `description` are
|
|
36245
|
+
* required; `tools` is a list or a comma-separated string. Unknown keys are
|
|
36246
|
+
* kept (looseObject), and OpenBitFun itself ignores keys it does not know.
|
|
36247
|
+
*
|
|
36248
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/custom_agent.rs
|
|
36249
|
+
*/
|
|
36250
|
+
const OpenbitfunSubagentFrontmatterSchema = z.looseObject({
|
|
36251
|
+
name: z.string(),
|
|
36252
|
+
description: z.string(),
|
|
36253
|
+
kind: z.optional(z.enum(["mode", "subagent"])),
|
|
36254
|
+
tools: z.optional(z.union([z.string(), z.array(z.string())])),
|
|
36255
|
+
model: z.optional(z.string()),
|
|
36256
|
+
readonly: z.optional(z.boolean()),
|
|
36257
|
+
review: z.optional(z.boolean())
|
|
36258
|
+
});
|
|
36259
|
+
/**
|
|
36260
|
+
* Subagent generator for OpenBitFun.
|
|
36261
|
+
*
|
|
36262
|
+
* OpenBitFun reads custom agents — Markdown with YAML frontmatter, the body
|
|
36263
|
+
* being the prompt — from `.openbitfun/agents/` (project) and
|
|
36264
|
+
* `<user root>/agents/` (user; see {@link openbitfunGlobalAgentsDir}).
|
|
36265
|
+
*
|
|
36266
|
+
* rulesync writes `name`, `description` and `kind: subagent`, then spreads the
|
|
36267
|
+
* `openbitfun` section (`kind`, `tools`, `model`, `readonly`, `review`, `id`,
|
|
36268
|
+
* `user_context_policy`, ...) on top, so a value set there wins. OpenBitFun
|
|
36269
|
+
* requires `description`, so an absent one is written as an empty string.
|
|
36270
|
+
*
|
|
36271
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/custom_agent.rs
|
|
36272
|
+
*/
|
|
36273
|
+
var OpenbitfunSubagent = class OpenbitfunSubagent extends ToolSubagent {
|
|
36274
|
+
frontmatter;
|
|
36275
|
+
body;
|
|
36276
|
+
constructor({ frontmatter, body, ...rest }) {
|
|
36277
|
+
if (rest.validate !== false) {
|
|
36278
|
+
const result = OpenbitfunSubagentFrontmatterSchema.safeParse(frontmatter);
|
|
36279
|
+
if (!result.success) throw new Error(`Invalid frontmatter in ${join(rest.relativeDirPath, rest.relativeFilePath)}: ${formatError(result.error)}`);
|
|
36280
|
+
}
|
|
36281
|
+
super({ ...rest });
|
|
36282
|
+
this.frontmatter = frontmatter;
|
|
36283
|
+
this.body = body;
|
|
36284
|
+
}
|
|
36285
|
+
static getSettablePaths({ global = false } = {}) {
|
|
36286
|
+
return { relativeDirPath: global ? openbitfunGlobalAgentsDir() : OPENBITFUN_AGENTS_DIR_PATH };
|
|
36287
|
+
}
|
|
36288
|
+
getFrontmatter() {
|
|
36289
|
+
return this.frontmatter;
|
|
36290
|
+
}
|
|
36291
|
+
getBody() {
|
|
36292
|
+
return this.body;
|
|
36293
|
+
}
|
|
36294
|
+
toRulesyncSubagent() {
|
|
36295
|
+
const { name, description, kind, ...restFields } = this.frontmatter;
|
|
36296
|
+
const openbitfunSection = {
|
|
36297
|
+
...kind !== void 0 && kind !== OPENBITFUN_SUBAGENT_KIND && { kind },
|
|
36298
|
+
...restFields
|
|
36299
|
+
};
|
|
36300
|
+
return new RulesyncSubagent({
|
|
36301
|
+
outputRoot: ".",
|
|
36302
|
+
frontmatter: {
|
|
36303
|
+
targets: ["*"],
|
|
36304
|
+
name,
|
|
36305
|
+
...description && { description },
|
|
36306
|
+
...Object.keys(openbitfunSection).length > 0 && { openbitfun: openbitfunSection }
|
|
36307
|
+
},
|
|
36308
|
+
body: this.body,
|
|
36309
|
+
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
|
|
36310
|
+
relativeFilePath: this.getRelativeFilePath(),
|
|
36311
|
+
validate: true
|
|
36312
|
+
});
|
|
36313
|
+
}
|
|
36314
|
+
static fromRulesyncSubagent({ outputRoot = process.cwd(), rulesyncSubagent, validate = true, global = false, logger }) {
|
|
36315
|
+
if (global) warnOpenbitfunXdgOverride({
|
|
36316
|
+
kind: "config",
|
|
36317
|
+
logger
|
|
36318
|
+
});
|
|
36319
|
+
const rulesyncFrontmatter = rulesyncSubagent.getFrontmatter();
|
|
36320
|
+
const openbitfunSection = this.filterToolSpecificSection(rulesyncFrontmatter.openbitfun ?? {}, ["name", "description"]);
|
|
36321
|
+
const openbitfunFrontmatter = parseGeneratedSubagentFrontmatter({
|
|
36322
|
+
schema: OpenbitfunSubagentFrontmatterSchema,
|
|
36323
|
+
frontmatter: {
|
|
36324
|
+
name: rulesyncFrontmatter.name,
|
|
36325
|
+
description: rulesyncFrontmatter.description ?? "",
|
|
36326
|
+
kind: OPENBITFUN_SUBAGENT_KIND,
|
|
36327
|
+
...openbitfunSection
|
|
36328
|
+
},
|
|
36329
|
+
toolTarget: "openbitfun",
|
|
36330
|
+
rulesyncSubagent
|
|
36331
|
+
});
|
|
36332
|
+
const body = rulesyncSubagent.getBody();
|
|
36333
|
+
return new OpenbitfunSubagent({
|
|
36334
|
+
outputRoot,
|
|
36335
|
+
frontmatter: openbitfunFrontmatter,
|
|
36336
|
+
body,
|
|
36337
|
+
relativeDirPath: this.getSettablePaths({ global }).relativeDirPath,
|
|
36338
|
+
relativeFilePath: rulesyncSubagent.getRelativeFilePath(),
|
|
36339
|
+
fileContent: stringifyFrontmatter(body, openbitfunFrontmatter),
|
|
36340
|
+
validate
|
|
36341
|
+
});
|
|
36342
|
+
}
|
|
36343
|
+
validate() {
|
|
36344
|
+
if (!this.frontmatter) return {
|
|
36345
|
+
success: true,
|
|
36346
|
+
error: null
|
|
36347
|
+
};
|
|
36348
|
+
return validateFrontmatterSchema({
|
|
36349
|
+
schema: OpenbitfunSubagentFrontmatterSchema,
|
|
36350
|
+
frontmatter: this.frontmatter,
|
|
36351
|
+
relativeDirPath: this.relativeDirPath,
|
|
36352
|
+
relativeFilePath: this.relativeFilePath
|
|
36353
|
+
});
|
|
36354
|
+
}
|
|
36355
|
+
static isTargetedByRulesyncSubagent(rulesyncSubagent) {
|
|
36356
|
+
return this.isTargetedByRulesyncSubagentDefault({
|
|
36357
|
+
rulesyncSubagent,
|
|
36358
|
+
toolTarget: "openbitfun"
|
|
36359
|
+
});
|
|
36360
|
+
}
|
|
36361
|
+
static async fromFile({ outputRoot = process.cwd(), relativeFilePath, validate = true, global = false }) {
|
|
36362
|
+
const paths = this.getSettablePaths({ global });
|
|
36363
|
+
const filePath = join(outputRoot, paths.relativeDirPath, relativeFilePath);
|
|
36364
|
+
const fileContent = await readFileContent(filePath);
|
|
36365
|
+
const { frontmatter, body } = parseFrontmatter(fileContent, filePath);
|
|
36366
|
+
const result = OpenbitfunSubagentFrontmatterSchema.safeParse(frontmatter);
|
|
36367
|
+
if (!result.success) throw new Error(`Invalid frontmatter in ${filePath}: ${formatError(result.error)}`);
|
|
36368
|
+
return new OpenbitfunSubagent({
|
|
36369
|
+
outputRoot,
|
|
36370
|
+
relativeDirPath: paths.relativeDirPath,
|
|
36371
|
+
relativeFilePath,
|
|
36372
|
+
frontmatter: result.data,
|
|
36373
|
+
body: body.trim(),
|
|
36374
|
+
fileContent,
|
|
36375
|
+
validate
|
|
36376
|
+
});
|
|
36377
|
+
}
|
|
36378
|
+
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath }) {
|
|
36379
|
+
return new OpenbitfunSubagent({
|
|
36380
|
+
outputRoot,
|
|
36381
|
+
relativeDirPath,
|
|
36382
|
+
relativeFilePath,
|
|
36383
|
+
frontmatter: {
|
|
36384
|
+
name: "",
|
|
36385
|
+
description: ""
|
|
36386
|
+
},
|
|
36387
|
+
body: "",
|
|
36388
|
+
fileContent: "",
|
|
36389
|
+
validate: false
|
|
36390
|
+
});
|
|
36391
|
+
}
|
|
36392
|
+
};
|
|
36020
36393
|
// src/features/subagents/opencodev1-subagent.ts
|
|
36021
36394
|
/**
|
|
36022
36395
|
* Subagent generator for **OpenCode V1** (OpenCode 1.x), which reads the V1
|
|
@@ -37068,8 +37441,208 @@ const VIBE_PROMPTS_DIR_PATH = join(".vibe", "prompts");
|
|
|
37068
37441
|
* @see https://github.com/mistralai/mistral-vibe/blob/v3.0.3/vibe/core/agents/models.py
|
|
37069
37442
|
*/
|
|
37070
37443
|
const VIBE_RESERVED_AGENT_NAME = "main";
|
|
37444
|
+
/**
|
|
37445
|
+
* The approval policies Vibe ships since v3.1.4. `AgentRegistry._discover`
|
|
37446
|
+
* never loads an agents-directory file named after one as an agent, whatever
|
|
37447
|
+
* its `agent_type`: from a project's `.vibe/agents/` the file is ignored with
|
|
37448
|
+
* an `approval_policy.project_override_ignored` config issue, and from
|
|
37449
|
+
* `~/.vibe/agents/` it redefines that approval policy for every session. Vibe
|
|
37450
|
+
* compares the file stem exactly (`agent.name in BUILTIN_APPROVAL_POLICIES`).
|
|
37451
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.5/vibe/core/agents/registry.py
|
|
37452
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.5/vibe/core/agents/models.py
|
|
37453
|
+
*/
|
|
37454
|
+
const VIBE_APPROVAL_POLICY_NAMES = /* @__PURE__ */ new Set([
|
|
37455
|
+
"ask",
|
|
37456
|
+
"accept-edits",
|
|
37457
|
+
"smart-approve",
|
|
37458
|
+
"auto-approve"
|
|
37459
|
+
]);
|
|
37460
|
+
function vibeAgentFileStem(relativeFilePath) {
|
|
37461
|
+
return basename(relativeFilePath).replace(/\.(md|toml)$/, "");
|
|
37462
|
+
}
|
|
37071
37463
|
function isReservedVibeAgentFileName(relativeFilePath) {
|
|
37072
|
-
return
|
|
37464
|
+
return vibeAgentFileStem(relativeFilePath).toLowerCase() === VIBE_RESERVED_AGENT_NAME;
|
|
37465
|
+
}
|
|
37466
|
+
function isVibeApprovalPolicyFileName(relativeFilePath) {
|
|
37467
|
+
return VIBE_APPROVAL_POLICY_NAMES.has(vibeAgentFileStem(relativeFilePath));
|
|
37468
|
+
}
|
|
37469
|
+
/**
|
|
37470
|
+
* The keys Vibe ignores on a custom `agent_type = "agent"` profile since
|
|
37471
|
+
* v3.1.4, listing each as a config issue: `_agent_settings` drops every
|
|
37472
|
+
* `VibeConfigSchema` field outside its `_AGENT_KEYS`, plus `safety` and
|
|
37473
|
+
* `approval_policy`, because what runs without asking belongs to the approval
|
|
37474
|
+
* policy, not to the agent. A key outside this list is kept, as Vibe keeps it:
|
|
37475
|
+
* an agent key passes, and an unknown key (a typo such as `disabled_tool`)
|
|
37476
|
+
* stays so Vibe can report it — or refuse it under `strict_config`.
|
|
37477
|
+
* Generated from the `VibeConfigSchema` fields of v3.1.5 minus `_AGENT_KEYS`.
|
|
37478
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.5/vibe/core/agents/models.py
|
|
37479
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.5/vibe/core/config/vibe_schema.py
|
|
37480
|
+
*/
|
|
37481
|
+
const VIBE_AGENT_IGNORED_KEYS = /* @__PURE__ */ new Set([
|
|
37482
|
+
"safety",
|
|
37483
|
+
"approval_policy",
|
|
37484
|
+
"catalog_model_aliases",
|
|
37485
|
+
"catalog_recommended_model",
|
|
37486
|
+
"catalog_default_model",
|
|
37487
|
+
"utility_models",
|
|
37488
|
+
"active_transcribe_model",
|
|
37489
|
+
"transcribe_providers",
|
|
37490
|
+
"transcribe_models",
|
|
37491
|
+
"active_tts_model",
|
|
37492
|
+
"tts_providers",
|
|
37493
|
+
"tts_models",
|
|
37494
|
+
"outside_workdir",
|
|
37495
|
+
"mcp_servers",
|
|
37496
|
+
"enable_connectors",
|
|
37497
|
+
"enable_mcp",
|
|
37498
|
+
"experimental_enable_document_library_connector",
|
|
37499
|
+
"experimental_enable_mistral_mcp_connector",
|
|
37500
|
+
"connectors",
|
|
37501
|
+
"agent_paths",
|
|
37502
|
+
"enabled_agents",
|
|
37503
|
+
"disabled_agents",
|
|
37504
|
+
"installed_agents",
|
|
37505
|
+
"default_agent",
|
|
37506
|
+
"default_approval_policy",
|
|
37507
|
+
"vibe_bot_max_approval_policy",
|
|
37508
|
+
"vibe_bot_local_tools",
|
|
37509
|
+
"vibe_bot_local_tool_max_bytes",
|
|
37510
|
+
"smart_approve_available",
|
|
37511
|
+
"enable_auto_approve",
|
|
37512
|
+
"enabled_plugins",
|
|
37513
|
+
"disabled_plugins",
|
|
37514
|
+
"experimental_enable_remote_plugins",
|
|
37515
|
+
"experimental_enable_registry_skills",
|
|
37516
|
+
"enable_model_catalog",
|
|
37517
|
+
"enable_builtin_models",
|
|
37518
|
+
"experimental_enable_storage_usage",
|
|
37519
|
+
"enable_pr_monitoring",
|
|
37520
|
+
"experimental_local_runtime_session_api",
|
|
37521
|
+
"experimental_target_runtime",
|
|
37522
|
+
"enable_otel",
|
|
37523
|
+
"otel_endpoint",
|
|
37524
|
+
"otel_redaction",
|
|
37525
|
+
"console_base_url",
|
|
37526
|
+
"theme",
|
|
37527
|
+
"applied_migrations",
|
|
37528
|
+
"disable_welcome_banner_animation",
|
|
37529
|
+
"disable_selection_animation",
|
|
37530
|
+
"cursor_blink",
|
|
37531
|
+
"vim_keybindings",
|
|
37532
|
+
"show_dangerous_directory_warning",
|
|
37533
|
+
"autocopy_to_clipboard",
|
|
37534
|
+
"enable_mouse_capture",
|
|
37535
|
+
"enable_sticky_prompt",
|
|
37536
|
+
"collapse_turn_details",
|
|
37537
|
+
"enable_file_autocomplete",
|
|
37538
|
+
"file_watcher_for_autocomplete",
|
|
37539
|
+
"ask_confirmation_on_exit",
|
|
37540
|
+
"displayed_workdir",
|
|
37541
|
+
"context_warnings",
|
|
37542
|
+
"voice_mode_enabled",
|
|
37543
|
+
"narrator_enabled",
|
|
37544
|
+
"show_thinking_nodes",
|
|
37545
|
+
"show_subagent_status_list",
|
|
37546
|
+
"worktree_limit",
|
|
37547
|
+
"auto_worktree",
|
|
37548
|
+
"worktree_copy_on_write",
|
|
37549
|
+
"bypass_tool_permissions",
|
|
37550
|
+
"raise_on_compaction_failure",
|
|
37551
|
+
"enable_telemetry",
|
|
37552
|
+
"managed_shell_tools_enabled",
|
|
37553
|
+
"enable_background_processes",
|
|
37554
|
+
"enable_subagents",
|
|
37555
|
+
"max_subagents",
|
|
37556
|
+
"max_concurrent_subagents",
|
|
37557
|
+
"compaction_prompt_id",
|
|
37558
|
+
"title_prompt_id",
|
|
37559
|
+
"include_commit_signature",
|
|
37560
|
+
"include_model_info",
|
|
37561
|
+
"include_project_context",
|
|
37562
|
+
"include_prompt_detail",
|
|
37563
|
+
"strict_config",
|
|
37564
|
+
"enable_update_checks",
|
|
37565
|
+
"enable_auto_update",
|
|
37566
|
+
"enable_notifications",
|
|
37567
|
+
"keep_awake",
|
|
37568
|
+
"experimental_enable_tab_status",
|
|
37569
|
+
"enable_system_trust_store",
|
|
37570
|
+
"api_timeout",
|
|
37571
|
+
"api_retry_max_elapsed_time",
|
|
37572
|
+
"max_goal_token_budget",
|
|
37573
|
+
"api_stream_idle_timeout",
|
|
37574
|
+
"agent_max_output_tokens",
|
|
37575
|
+
"compaction_max_output_tokens",
|
|
37576
|
+
"compaction_reasoning_limit_tokens",
|
|
37577
|
+
"output_limit_retries",
|
|
37578
|
+
"api_connect_timeout",
|
|
37579
|
+
"api_write_timeout",
|
|
37580
|
+
"api_pool_timeout",
|
|
37581
|
+
"vibe_base_url",
|
|
37582
|
+
"vibe_code_sessions_base_url",
|
|
37583
|
+
"log_level",
|
|
37584
|
+
"project_context",
|
|
37585
|
+
"session_logging",
|
|
37586
|
+
"experiments"
|
|
37587
|
+
]);
|
|
37588
|
+
/**
|
|
37589
|
+
* The legacy key Vibe folds into `disabled_tools` before it filters an agent
|
|
37590
|
+
* profile (`migrate_agent_profile_config`).
|
|
37591
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.5/vibe/core/agents/_migration.py
|
|
37592
|
+
*/
|
|
37593
|
+
const VIBE_LEGACY_BASE_DISABLED_KEY = "base_disabled";
|
|
37594
|
+
/** Per tool, an agent keeps only the shell timeouts and a narrowing `permission`. */
|
|
37595
|
+
const VIBE_AGENT_TOOL_KEYS = /* @__PURE__ */ new Set(["default_timeout", "max_timeout_seconds"]);
|
|
37596
|
+
const VIBE_AGENT_NARROWING_PERMISSIONS = /* @__PURE__ */ new Set(["ask", "never"]);
|
|
37597
|
+
/**
|
|
37598
|
+
* Fold a legacy `base_disabled` list into `disabled_tools` the way Vibe's
|
|
37599
|
+
* `migrate_agent_profile_config` does, so the restriction it carries is kept.
|
|
37600
|
+
*/
|
|
37601
|
+
function migrateVibeBaseDisabled(tomlObj) {
|
|
37602
|
+
const legacyDisabled = tomlObj[VIBE_LEGACY_BASE_DISABLED_KEY];
|
|
37603
|
+
if (!Array.isArray(legacyDisabled)) return tomlObj;
|
|
37604
|
+
const rest = Object.fromEntries(Object.entries(tomlObj).filter(([key]) => key !== VIBE_LEGACY_BASE_DISABLED_KEY));
|
|
37605
|
+
const disabledTools = rest.disabled_tools;
|
|
37606
|
+
return {
|
|
37607
|
+
...rest,
|
|
37608
|
+
disabled_tools: Array.isArray(disabledTools) ? [.../* @__PURE__ */ new Set([...disabledTools, ...legacyDisabled])] : legacyDisabled
|
|
37609
|
+
};
|
|
37610
|
+
}
|
|
37611
|
+
/**
|
|
37612
|
+
* Drop the settings Vibe ignores on an `agent_type = "agent"` profile, so the
|
|
37613
|
+
* generated file does not pretend to grant what Vibe refuses. Mirrors Vibe's
|
|
37614
|
+
* `_agent_settings`; returns the kept TOML object and the dotted keys that
|
|
37615
|
+
* were dropped.
|
|
37616
|
+
*/
|
|
37617
|
+
function stripVibeAgentIgnoredSettings(tomlObj) {
|
|
37618
|
+
const kept = {};
|
|
37619
|
+
const dropped = [];
|
|
37620
|
+
for (const [key, value] of Object.entries(migrateVibeBaseDisabled(tomlObj))) {
|
|
37621
|
+
if (VIBE_AGENT_IGNORED_KEYS.has(key)) {
|
|
37622
|
+
dropped.push(key);
|
|
37623
|
+
continue;
|
|
37624
|
+
}
|
|
37625
|
+
if (key !== "tools" || typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
37626
|
+
kept[key] = value;
|
|
37627
|
+
continue;
|
|
37628
|
+
}
|
|
37629
|
+
const tools = {};
|
|
37630
|
+
for (const [tool, settings] of Object.entries(value)) {
|
|
37631
|
+
if (typeof settings !== "object" || settings === null || Array.isArray(settings)) {
|
|
37632
|
+
dropped.push(`tools.${tool}`);
|
|
37633
|
+
continue;
|
|
37634
|
+
}
|
|
37635
|
+
const own = {};
|
|
37636
|
+
for (const [setting, settingValue] of Object.entries(settings)) if (VIBE_AGENT_TOOL_KEYS.has(setting) || setting === "permission" && VIBE_AGENT_NARROWING_PERMISSIONS.has(settingValue)) own[setting] = settingValue;
|
|
37637
|
+
else dropped.push(`tools.${tool}.${setting}`);
|
|
37638
|
+
if (Object.keys(own).length > 0) tools[tool] = own;
|
|
37639
|
+
}
|
|
37640
|
+
if (Object.keys(tools).length > 0) kept.tools = tools;
|
|
37641
|
+
}
|
|
37642
|
+
return {
|
|
37643
|
+
kept,
|
|
37644
|
+
dropped: dropped.toSorted()
|
|
37645
|
+
};
|
|
37073
37646
|
}
|
|
37074
37647
|
/**
|
|
37075
37648
|
* Vibe resolves a `system_prompt_id` by file name, and
|
|
@@ -37149,7 +37722,7 @@ var VibeSubagent = class VibeSubagent extends ToolSubagent {
|
|
|
37149
37722
|
validate: true
|
|
37150
37723
|
});
|
|
37151
37724
|
}
|
|
37152
|
-
static fromRulesyncSubagent({ outputRoot = process.cwd(), rulesyncSubagent, validate = true, global = false }) {
|
|
37725
|
+
static fromRulesyncSubagent({ outputRoot = process.cwd(), rulesyncSubagent, validate = true, global = false, logger }) {
|
|
37153
37726
|
const frontmatter = rulesyncSubagent.getFrontmatter();
|
|
37154
37727
|
const rawSection = frontmatter.vibe ?? {};
|
|
37155
37728
|
const vibeSection = this.filterToolSpecificSection(rawSection, [
|
|
@@ -37167,7 +37740,13 @@ var VibeSubagent = class VibeSubagent extends ToolSubagent {
|
|
|
37167
37740
|
...vibeSection,
|
|
37168
37741
|
...promptBody ? { system_prompt_id: slug } : {}
|
|
37169
37742
|
};
|
|
37170
|
-
|
|
37743
|
+
let finalToml = tomlObj;
|
|
37744
|
+
if (tomlObj.agent_type === "agent") {
|
|
37745
|
+
const { kept, dropped } = stripVibeAgentIgnoredSettings(tomlObj);
|
|
37746
|
+
if (dropped.length > 0) logger?.warn(`Vibe subagent ${rulesyncSubagent.getRelativeFilePath()}: dropped ${dropped.map((key) => `'${key}'`).join(", ")}, which Vibe v3.1.4+ ignores on an agent_type = "agent" profile and reports as a config issue. What runs without asking belongs to the approval policy: set default_approval_policy and [tools.*] in config.toml, or use agent_type = "subagent".`);
|
|
37747
|
+
finalToml = kept;
|
|
37748
|
+
}
|
|
37749
|
+
const body = smolToml.stringify(finalToml);
|
|
37171
37750
|
const paths = this.getSettablePaths({ global });
|
|
37172
37751
|
const relativeFilePath = rulesyncSubagent.getRelativeFilePath().replace(/\.md$/, ".toml");
|
|
37173
37752
|
return new VibeSubagent({
|
|
@@ -37188,7 +37767,10 @@ var VibeSubagent = class VibeSubagent extends ToolSubagent {
|
|
|
37188
37767
|
* with a warning.
|
|
37189
37768
|
*
|
|
37190
37769
|
* A subagent named `main` is skipped with a warning: Vibe reserves that name
|
|
37191
|
-
* for hook matching and does not load an agent file called `main.toml`.
|
|
37770
|
+
* for hook matching and does not load an agent file called `main.toml`. So is
|
|
37771
|
+
* one named after an approval policy (`ask`, `accept-edits`, `smart-approve`,
|
|
37772
|
+
* `auto-approve`): Vibe ignores such a file in a project and treats it as a
|
|
37773
|
+
* redefinition of that policy in `~/.vibe/agents/`, never as an agent.
|
|
37192
37774
|
*/
|
|
37193
37775
|
static fromRulesyncSubagents({ rulesyncSubagents, outputRoot = process.cwd(), global = false, logger }) {
|
|
37194
37776
|
return rulesyncSubagents.flatMap((rulesyncSubagent) => {
|
|
@@ -37197,11 +37779,17 @@ var VibeSubagent = class VibeSubagent extends ToolSubagent {
|
|
|
37197
37779
|
logger?.warn(`Skipping Vibe subagent ${sourcePath}: Vibe reserves the agent name '${VIBE_RESERVED_AGENT_NAME}' for hook matching and does not load an agent file named '${VIBE_RESERVED_AGENT_NAME}'. Rename the subagent file.`);
|
|
37198
37780
|
return [];
|
|
37199
37781
|
}
|
|
37782
|
+
if (isVibeApprovalPolicyFileName(sourcePath)) {
|
|
37783
|
+
const policy = vibeAgentFileStem(sourcePath);
|
|
37784
|
+
logger?.warn(`Skipping Vibe subagent ${sourcePath}: '${policy}' is a Vibe approval policy name (v3.1.4+), so Vibe never loads an agent file of that name — a project's .vibe/agents/ file is ignored and a ~/.vibe/agents/ file redefines the approval policy instead. Rename the subagent file.`);
|
|
37785
|
+
return [];
|
|
37786
|
+
}
|
|
37200
37787
|
const agentFile = VibeSubagent.fromRulesyncSubagent({
|
|
37201
37788
|
outputRoot,
|
|
37202
37789
|
relativeDirPath: VibeSubagent.getSettablePaths({ global }).relativeDirPath,
|
|
37203
37790
|
rulesyncSubagent,
|
|
37204
|
-
global
|
|
37791
|
+
global,
|
|
37792
|
+
logger
|
|
37205
37793
|
});
|
|
37206
37794
|
const promptBody = rulesyncSubagent.getBody();
|
|
37207
37795
|
if (!promptBody) return [agentFile];
|
|
@@ -37277,6 +37865,22 @@ var VibeSubagent = class VibeSubagent extends ToolSubagent {
|
|
|
37277
37865
|
if (typeof promptId !== "string" || promptId === "" || /[\\/]/.test(promptId)) return;
|
|
37278
37866
|
return await readFileContentOrNull(join(outputRoot, VIBE_PROMPTS_DIR_PATH, `${promptId}.md`)) ?? void 0;
|
|
37279
37867
|
}
|
|
37868
|
+
/**
|
|
37869
|
+
* A file in `.vibe/agents/` named after an approval policy is not an agent:
|
|
37870
|
+
* in `~/.vibe/agents/` it is the user's override of that policy (often a
|
|
37871
|
+
* narrower one), and in a project Vibe ignores it. It is therefore neither
|
|
37872
|
+
* imported as a subagent (with a warning) nor swept as an orphan, since
|
|
37873
|
+
* deleting a narrowing override would fall back to the broader builtin.
|
|
37874
|
+
*/
|
|
37875
|
+
static async isFileOwned({ relativeFilePath, forDeletion = false, logger }) {
|
|
37876
|
+
if (!isVibeApprovalPolicyFileName(relativeFilePath)) return true;
|
|
37877
|
+
if (!forDeletion) logger?.warn(`Skipping Vibe agent file ${relativeFilePath}: '${vibeAgentFileStem(relativeFilePath)}' is a Vibe approval policy name (v3.1.4+), so the file overrides that approval policy rather than defining an agent, and it is not imported as a subagent.`);
|
|
37878
|
+
return false;
|
|
37879
|
+
}
|
|
37880
|
+
/** Never delete an approval-policy override; see {@link VibeSubagent.isFileOwned}. */
|
|
37881
|
+
isDeletable() {
|
|
37882
|
+
return this.promptFile || !isVibeApprovalPolicyFileName(this.getRelativeFilePath());
|
|
37883
|
+
}
|
|
37280
37884
|
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath, global = false }) {
|
|
37281
37885
|
return new VibeSubagent({
|
|
37282
37886
|
outputRoot,
|
|
@@ -38166,6 +38770,15 @@ const toolSubagentFactories = /* @__PURE__ */ new Map([
|
|
|
38166
38770
|
filePattern: "*.toml"
|
|
38167
38771
|
}
|
|
38168
38772
|
}],
|
|
38773
|
+
["openbitfun", {
|
|
38774
|
+
class: OpenbitfunSubagent,
|
|
38775
|
+
meta: {
|
|
38776
|
+
supportsProject: true,
|
|
38777
|
+
supportsSimulated: false,
|
|
38778
|
+
supportsGlobal: true,
|
|
38779
|
+
filePattern: "*.md"
|
|
38780
|
+
}
|
|
38781
|
+
}],
|
|
38169
38782
|
["xum", {
|
|
38170
38783
|
class: XumSubagent,
|
|
38171
38784
|
meta: {
|
|
@@ -38450,7 +39063,9 @@ var SubagentsProcessor = class extends FeatureProcessor {
|
|
|
38450
39063
|
const ownership = await Promise.all(subagentFilePaths.map((path) => factory.class.isFileOwned({
|
|
38451
39064
|
outputRoot: rootOutputRoot,
|
|
38452
39065
|
relativeDirPath: dirPath,
|
|
38453
|
-
relativeFilePath: toRelativeFilePath(path)
|
|
39066
|
+
relativeFilePath: toRelativeFilePath(path),
|
|
39067
|
+
forDeletion,
|
|
39068
|
+
logger: this.logger
|
|
38454
39069
|
})));
|
|
38455
39070
|
ownedFilePaths = subagentFilePaths.filter((_, index) => ownership[index]);
|
|
38456
39071
|
}
|
|
@@ -44765,7 +45380,7 @@ const TOOL_DISPLAY = [
|
|
|
44765
45380
|
},
|
|
44766
45381
|
{
|
|
44767
45382
|
key: "firebender",
|
|
44768
|
-
label: "Firebender",
|
|
45383
|
+
label: "Firebender ⚠️",
|
|
44769
45384
|
group: "ai"
|
|
44770
45385
|
},
|
|
44771
45386
|
{
|
|
@@ -44783,6 +45398,11 @@ const TOOL_DISPLAY = [
|
|
|
44783
45398
|
label: "OpenClaw",
|
|
44784
45399
|
group: "ai"
|
|
44785
45400
|
},
|
|
45401
|
+
{
|
|
45402
|
+
key: "openbitfun",
|
|
45403
|
+
label: "OpenBitFun",
|
|
45404
|
+
group: "ai"
|
|
45405
|
+
},
|
|
44786
45406
|
{
|
|
44787
45407
|
key: "mimocode",
|
|
44788
45408
|
label: "MiMo Code",
|
|
@@ -46479,10 +47099,18 @@ var MimocodeRule = class extends OpenCodeRule {
|
|
|
46479
47099
|
* from the working directory to the `.git` boundary and loads one instruction
|
|
46480
47100
|
* file per directory level, preferring `AGENTS.md` over `CLAUDE.md` when both
|
|
46481
47101
|
* exist. rulesync emits the project-root `AGENTS.md` (the same shared root file
|
|
46482
|
-
* the agentsmd/codexcli targets write). Muse Code
|
|
46483
|
-
*
|
|
46484
|
-
* (
|
|
46485
|
-
*
|
|
47102
|
+
* the agentsmd/codexcli targets write). Muse Code also loads machine-wide user
|
|
47103
|
+
* rules; since 1.4.23 its changelog names `~/.claude/CLAUDE.md` as that file
|
|
47104
|
+
* (the filename of the alternative under Muse's own config directory is not
|
|
47105
|
+
* published). `~/.claude/CLAUDE.md` is exactly what the `claudecode` target
|
|
47106
|
+
* writes in global mode, so no global scope is supported here: emitting the
|
|
47107
|
+
* same file from two targets would make the result depend on target order.
|
|
47108
|
+
* `rulesync generate --targets claudecode --global` feeds Muse Code's user
|
|
47109
|
+
* rules instead, but only for the root rule (global non-root rules go to
|
|
47110
|
+
* `~/.claude/rules/*.md`, which Muse Code is not documented to read) and only
|
|
47111
|
+
* for rules that target `claudecode`. (Verified against the official docs:
|
|
47112
|
+
* https://dev.meta.ai/docs/muse-code/configuration and
|
|
47113
|
+
* https://dev.meta.ai/docs/muse-code/changelog)
|
|
46486
47114
|
*
|
|
46487
47115
|
* rulesync's topic-based non-root rules have no project subdirectory to map
|
|
46488
47116
|
* onto, so their bodies are folded into the single root `AGENTS.md` by the
|
|
@@ -50897,9 +51525,10 @@ const AmpCheckFrontmatterSchema = z.looseObject({
|
|
|
50897
51525
|
* Amp reads code review checks as Markdown files with YAML frontmatter,
|
|
50898
51526
|
* scoped to the project (`.agents/checks/`) and user-wide (`~/.config/amp/checks/`;
|
|
50899
51527
|
* Amp also reads `~/.config/agents/checks/`, which rulesync does not write).
|
|
50900
|
-
*
|
|
50901
|
-
* `@amp/review-checks` plugin
|
|
50902
|
-
* this format
|
|
51528
|
+
* Amp has since removed `amp review` and deprecated project-defined checks
|
|
51529
|
+
* in `.agents/checks/`, together with the `@amp/review-checks` plugin that runs
|
|
51530
|
+
* them. rulesync keeps writing this format because Goose discovers the same
|
|
51531
|
+
* `.agents/checks/` directory and existing setups may still load the plugin.
|
|
50903
51532
|
* @see https://ampcode.com/docs/review
|
|
50904
51533
|
*/
|
|
50905
51534
|
var AmpCheck = class extends ToolCheck {
|
|
@@ -56478,9 +57107,12 @@ var SettingsJsonHooks = class extends ToolHooks {
|
|
|
56478
57107
|
const config = rulesyncHooks.getJson();
|
|
56479
57108
|
const generatedHooks = canonicalToToolHooks({
|
|
56480
57109
|
config,
|
|
56481
|
-
toolOverrideHooks:
|
|
56482
|
-
|
|
56483
|
-
|
|
57110
|
+
toolOverrideHooks: knownOverrideHooks({
|
|
57111
|
+
hooks: overrideHooksOf({
|
|
57112
|
+
config,
|
|
57113
|
+
overrideKey: this.getSpec().overrideKey
|
|
57114
|
+
}),
|
|
57115
|
+
spec: this.getSpec()
|
|
56484
57116
|
}),
|
|
56485
57117
|
converterConfig: this.getConverterConfig(),
|
|
56486
57118
|
logger
|
|
@@ -56543,6 +57175,16 @@ var SettingsJsonHooks = class extends ToolHooks {
|
|
|
56543
57175
|
}
|
|
56544
57176
|
};
|
|
56545
57177
|
/**
|
|
57178
|
+
* The override hooks the tool can take: all of them, unless the spec lists
|
|
57179
|
+
* {@link SettingsJsonHooksSpec.knownOverrideEvents}, in which case only those
|
|
57180
|
+
* native names and the canonical supported events are kept.
|
|
57181
|
+
*/
|
|
57182
|
+
function knownOverrideHooks({ hooks, spec }) {
|
|
57183
|
+
if (hooks === void 0 || spec.knownOverrideEvents === void 0) return hooks;
|
|
57184
|
+
const known = /* @__PURE__ */ new Set([...spec.converterConfig.supportedEvents, ...spec.knownOverrideEvents]);
|
|
57185
|
+
return Object.fromEntries(Object.entries(hooks).filter(([event]) => known.has(event)));
|
|
57186
|
+
}
|
|
57187
|
+
/**
|
|
56546
57188
|
* The `hooks` map of a tool's override block (`config.<overrideKey>.hooks`),
|
|
56547
57189
|
* or `undefined` when the block states none. The schema keeps every override
|
|
56548
57190
|
* block loose, so the lookup goes through the record form.
|
|
@@ -56556,7 +57198,6 @@ function overrideHooksOf({ config, overrideKey }) {
|
|
|
56556
57198
|
const hooks = override.hooks;
|
|
56557
57199
|
return isPlainObject(hooks) ? hooks : void 0;
|
|
56558
57200
|
}
|
|
56559
|
-
// src/features/hooks/bob-hooks.ts
|
|
56560
57201
|
const BOB_SPEC = {
|
|
56561
57202
|
displayName: "Bob",
|
|
56562
57203
|
overrideKey: "bob",
|
|
@@ -56565,11 +57206,12 @@ const BOB_SPEC = {
|
|
|
56565
57206
|
canonicalToToolEventNames: CANONICAL_TO_BOB_EVENT_NAMES,
|
|
56566
57207
|
toolToCanonicalEventNames: BOB_TO_CANONICAL_EVENT_NAMES,
|
|
56567
57208
|
projectDirVar: "",
|
|
56568
|
-
noMatcherEvents:
|
|
57209
|
+
noMatcherEvents: new Set(BOB_HOOK_EVENTS.filter((event) => !BOB_MATCHER_HOOK_EVENTS.includes(event))),
|
|
56569
57210
|
supportedHookTypes: /* @__PURE__ */ new Set(["command", "http"]),
|
|
56570
57211
|
importedHookTypeAliases: { https: "http" },
|
|
56571
57212
|
wildcardMatcherMeansAll: true
|
|
56572
|
-
}
|
|
57213
|
+
},
|
|
57214
|
+
knownOverrideEvents: BOB_NATIVE_HOOK_EVENTS
|
|
56573
57215
|
};
|
|
56574
57216
|
/**
|
|
56575
57217
|
* IBM Bob lifecycle hooks.
|
|
@@ -57436,7 +58078,7 @@ function describeRejectedHandler(handler) {
|
|
|
57436
58078
|
* MCP hooks are skipped with a startup warning). Matcher groups left without
|
|
57437
58079
|
* handlers are removed. https://learn.chatgpt.com/docs/hooks
|
|
57438
58080
|
*/
|
|
57439
|
-
function filterCodexHandlers({ hooks, logger }) {
|
|
58081
|
+
function filterCodexHandlers({ hooks, toolLabel, describeRejected, logger }) {
|
|
57440
58082
|
const result = {};
|
|
57441
58083
|
const skippedSessionEndTools = [];
|
|
57442
58084
|
for (const [eventName, groups] of Object.entries(hooks)) {
|
|
@@ -57448,9 +58090,9 @@ function filterCodexHandlers({ hooks, logger }) {
|
|
|
57448
58090
|
continue;
|
|
57449
58091
|
}
|
|
57450
58092
|
const handlers = entry.hooks.filter((handler) => {
|
|
57451
|
-
const reason =
|
|
58093
|
+
const reason = describeRejected(handler);
|
|
57452
58094
|
if (reason !== void 0) {
|
|
57453
|
-
logger?.warn(`Skipping a "${String(handler.type)}" hook on
|
|
58095
|
+
logger?.warn(`Skipping a "${String(handler.type)}" hook on ${toolLabel} "${eventName}": ${reason}.`);
|
|
57454
58096
|
return false;
|
|
57455
58097
|
}
|
|
57456
58098
|
if (eventName === "SessionEnd" && handler.type === "mcp_tool") skippedSessionEndTools.push(`${String(handler.server)}/${String(handler.tool)}`);
|
|
@@ -57467,6 +58109,56 @@ function filterCodexHandlers({ hooks, logger }) {
|
|
|
57467
58109
|
return result;
|
|
57468
58110
|
}
|
|
57469
58111
|
/**
|
|
58112
|
+
* Generate the content of a Codex-shaped `hooks.json` (`{ hooks: { <Event>:
|
|
58113
|
+
* [matcher groups] } }`) at `relativeDirPath/relativeFilePath`. Shared by the
|
|
58114
|
+
* Codex CLI target and tools that read the same document (OpenBitFun), which
|
|
58115
|
+
* differ only in where the file lives, which events and handler types they
|
|
58116
|
+
* run, and which rulesync override section they read.
|
|
58117
|
+
*/
|
|
58118
|
+
async function buildCodexStyleHooksFile({ outputRoot, relativeDirPath, relativeFilePath, rulesyncHooks, toolOverrideHooks, converterConfig, toolLabel, describeRejected = describeRejectedHandler, preserveUnowned, logger }) {
|
|
58119
|
+
const merged = mergeGeneratedHookLists({
|
|
58120
|
+
existingContent: await readFileContentOrNull(join(outputRoot, relativeDirPath, relativeFilePath)) ?? "",
|
|
58121
|
+
generatedHooks: filterCodexHandlers({
|
|
58122
|
+
hooks: canonicalToToolHooks({
|
|
58123
|
+
config: rulesyncHooks.getJson(),
|
|
58124
|
+
toolOverrideHooks,
|
|
58125
|
+
converterConfig,
|
|
58126
|
+
logger
|
|
58127
|
+
}),
|
|
58128
|
+
toolLabel,
|
|
58129
|
+
describeRejected,
|
|
58130
|
+
logger
|
|
58131
|
+
}),
|
|
58132
|
+
shape: "matcher-groups",
|
|
58133
|
+
preserveUnowned,
|
|
58134
|
+
previouslyOwned: preserveUnowned ? await readPreviouslyOwnedHooks({
|
|
58135
|
+
outputRoot,
|
|
58136
|
+
relativeDirPath
|
|
58137
|
+
}) : void 0,
|
|
58138
|
+
logger
|
|
58139
|
+
});
|
|
58140
|
+
return {
|
|
58141
|
+
fileContent: JSON.stringify({ hooks: merged.hooks }, null, 2),
|
|
58142
|
+
owned: merged.owned
|
|
58143
|
+
};
|
|
58144
|
+
}
|
|
58145
|
+
/**
|
|
58146
|
+
* Convert the parsed content of a Codex-shaped `hooks.json` back to the
|
|
58147
|
+
* rulesync hooks JSON, with tool-only hooks under `overrideKey`.
|
|
58148
|
+
*/
|
|
58149
|
+
function codexStyleHooksToRulesyncContent({ parsed, converterConfig, overrideKey, logger }) {
|
|
58150
|
+
const hooks = toolHooksToCanonical({
|
|
58151
|
+
hooks: parsed.hooks,
|
|
58152
|
+
converterConfig,
|
|
58153
|
+
logger
|
|
58154
|
+
});
|
|
58155
|
+
return JSON.stringify(buildImportedHooksConfig({
|
|
58156
|
+
logger,
|
|
58157
|
+
hooks,
|
|
58158
|
+
overrideKey
|
|
58159
|
+
}), null, 2);
|
|
58160
|
+
}
|
|
58161
|
+
/**
|
|
57470
58162
|
* Build the content for `.codex/config.toml`, cleaning up the deprecated `codex_hooks` key.
|
|
57471
58163
|
* Reads the existing file (if any), parses TOML, and returns the content without writing to
|
|
57472
58164
|
* disk. The caller is responsible for writing via the normal write phase.
|
|
@@ -57538,51 +58230,37 @@ var CodexcliHooks = class CodexcliHooks extends ToolHooks {
|
|
|
57538
58230
|
}
|
|
57539
58231
|
static async fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false, preserveUnowned = false, logger }) {
|
|
57540
58232
|
const paths = CodexcliHooks.getSettablePaths({ global });
|
|
57541
|
-
const
|
|
57542
|
-
|
|
57543
|
-
|
|
57544
|
-
|
|
57545
|
-
|
|
57546
|
-
|
|
57547
|
-
|
|
57548
|
-
|
|
57549
|
-
converterConfig: CODEXCLI_CONVERTER_CONFIG,
|
|
57550
|
-
logger
|
|
57551
|
-
}),
|
|
57552
|
-
logger
|
|
57553
|
-
}),
|
|
57554
|
-
shape: "matcher-groups",
|
|
58233
|
+
const { fileContent, owned } = await buildCodexStyleHooksFile({
|
|
58234
|
+
outputRoot,
|
|
58235
|
+
relativeDirPath: paths.relativeDirPath,
|
|
58236
|
+
relativeFilePath: paths.relativeFilePath,
|
|
58237
|
+
rulesyncHooks,
|
|
58238
|
+
toolOverrideHooks: rulesyncHooks.getJson().codexcli?.hooks,
|
|
58239
|
+
converterConfig: CODEXCLI_CONVERTER_CONFIG,
|
|
58240
|
+
toolLabel: "Codex CLI",
|
|
57555
58241
|
preserveUnowned,
|
|
57556
|
-
previouslyOwned: preserveUnowned ? await readPreviouslyOwnedHooks({
|
|
57557
|
-
outputRoot,
|
|
57558
|
-
relativeDirPath: paths.relativeDirPath
|
|
57559
|
-
}) : void 0,
|
|
57560
58242
|
logger
|
|
57561
58243
|
});
|
|
57562
|
-
const fileContent = JSON.stringify({ hooks: merged.hooks }, null, 2);
|
|
57563
58244
|
return new CodexcliHooks({
|
|
57564
58245
|
outputRoot,
|
|
57565
58246
|
relativeDirPath: paths.relativeDirPath,
|
|
57566
58247
|
relativeFilePath: paths.relativeFilePath,
|
|
57567
58248
|
fileContent,
|
|
57568
|
-
ownedHookRefs: preserveUnowned ?
|
|
58249
|
+
ownedHookRefs: preserveUnowned ? owned : void 0,
|
|
57569
58250
|
validate
|
|
57570
58251
|
});
|
|
57571
58252
|
}
|
|
57572
58253
|
toRulesyncHooks({ logger } = {}) {
|
|
57573
|
-
const
|
|
57574
|
-
|
|
57575
|
-
|
|
57576
|
-
|
|
57577
|
-
|
|
58254
|
+
const parsed = this.parseFileContentOrThrow({
|
|
58255
|
+
displayName: "Codex CLI",
|
|
58256
|
+
parse: (fileContent) => JSON.parse(fileContent)
|
|
58257
|
+
});
|
|
58258
|
+
return this.toRulesyncHooksDefault({ fileContent: codexStyleHooksToRulesyncContent({
|
|
58259
|
+
parsed,
|
|
57578
58260
|
converterConfig: CODEXCLI_CONVERTER_CONFIG,
|
|
58261
|
+
overrideKey: "codexcli",
|
|
57579
58262
|
logger
|
|
57580
|
-
});
|
|
57581
|
-
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
57582
|
-
logger,
|
|
57583
|
-
hooks,
|
|
57584
|
-
overrideKey: "codexcli"
|
|
57585
|
-
}), null, 2) });
|
|
58263
|
+
}) });
|
|
57586
58264
|
}
|
|
57587
58265
|
static supportsPreserveUnowned() {
|
|
57588
58266
|
return true;
|
|
@@ -59984,7 +60662,7 @@ function canonicalToHermesHooks({ config, toolOverrideHooks, logger }) {
|
|
|
59984
60662
|
for (const [nativeEvent, definitions] of Object.entries(toolOverrideHooks ?? {})) {
|
|
59985
60663
|
if (HERMESAGENT_CANONICAL_EVENTS.has(nativeEvent)) continue;
|
|
59986
60664
|
if (HERMESAGENT_SHELL_UNSUPPORTED_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is Python-plugin-only; Hermes Agent refuses it for shell hooks, so the generated entry will never run.`);
|
|
59987
|
-
else if (!HERMESAGENT_NATIVE_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is not documented by Hermes Agent v0.23.
|
|
60665
|
+
else if (!HERMESAGENT_NATIVE_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is not documented by Hermes Agent v0.23.4; preserving it for forward compatibility.`);
|
|
59988
60666
|
setHermesHookEntries({
|
|
59989
60667
|
result,
|
|
59990
60668
|
event: nativeEvent,
|
|
@@ -60661,7 +61339,9 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60661
61339
|
* hook denies it:
|
|
60662
61340
|
* - exit code 2 → deny, with the command's stderr as the reason;
|
|
60663
61341
|
* - exit code 0 with JSON stdout whose `hookSpecificOutput.permissionDecision`
|
|
60664
|
-
* is `"deny"` → deny, with `permissionDecisionReason` as the reason;
|
|
61342
|
+
* is `"deny"` → deny, with `permissionDecisionReason` as the reason; when it
|
|
61343
|
+
* sets no `permissionDecision`, the deprecated top-level `decision: "block"`
|
|
61344
|
+
* that Claude Code still honors denies too, with `reason` as the reason;
|
|
60665
61345
|
* - exit code 0 otherwise → allow;
|
|
60666
61346
|
* - any other non-zero exit → deny too, with stderr or the exit code;
|
|
60667
61347
|
* - more than 1 MiB of stdout → deny, without parsing it;
|
|
@@ -60696,12 +61376,13 @@ const PRE_TOOL_USE_RESULT_HELPER_LINES = [
|
|
|
60696
61376
|
" } catch {",
|
|
60697
61377
|
" return;",
|
|
60698
61378
|
" }",
|
|
60699
|
-
"
|
|
60700
|
-
"
|
|
61379
|
+
" if (!parsed || typeof parsed !== \"object\") return;",
|
|
61380
|
+
" const specific = parsed.hookSpecificOutput;",
|
|
61381
|
+
" const hasDecision = typeof specific === \"object\" && specific !== null && specific.permissionDecision !== undefined;",
|
|
61382
|
+
" const reason = hasDecision ? specific.permissionDecisionReason : parsed.reason;",
|
|
61383
|
+
" if (hasDecision ? specific.permissionDecision === \"deny\" : parsed.decision === \"block\") {",
|
|
60701
61384
|
" throw new Error(",
|
|
60702
|
-
" (typeof
|
|
60703
|
-
" sanitizeBlockReason(specific.permissionDecisionReason)) ||",
|
|
60704
|
-
" \"Blocked by a preToolUse hook.\",",
|
|
61385
|
+
" (typeof reason === \"string\" && sanitizeBlockReason(reason)) || \"Blocked by a preToolUse hook.\",",
|
|
60705
61386
|
" );",
|
|
60706
61387
|
" }",
|
|
60707
61388
|
" return;",
|
|
@@ -62477,11 +63158,123 @@ const PI_SETTLE_BLOCKING_EVENT = "agent_before_settle";
|
|
|
62477
63158
|
* @see https://github.com/can1357/oh-my-pi/blob/fa5ff4a3a977a28b93d025f4cf50f046e019f18c/packages/coding-agent/src/session/agent-session.ts
|
|
62478
63159
|
*/
|
|
62479
63160
|
const OMP_SESSION_STOP_BLOCKING_EVENT = "session_stop";
|
|
63161
|
+
/**
|
|
63162
|
+
* Pi's `resolveToCwd` (`core/tools/path-utils.ts`), which calls
|
|
63163
|
+
* `resolvePath(path, cwd, { normalizeUnicodeSpaces: true, stripAtPrefix: true })`
|
|
63164
|
+
* from `utils/paths.ts`: Unicode spaces become plain spaces, a leading `@` is
|
|
63165
|
+
* dropped, on Windows Git Bash / WSL drive paths are converted, `~` is
|
|
63166
|
+
* expanded, a `file://` URL is converted, and the result is resolved against
|
|
63167
|
+
* cwd. Pi has no URL passthrough, so any other `scheme://` text is a relative
|
|
63168
|
+
* path too.
|
|
63169
|
+
*
|
|
63170
|
+
* @see https://github.com/earendil-works/pi/blob/v1.6.0/packages/coding-agent/src/utils/paths.ts
|
|
63171
|
+
*/
|
|
63172
|
+
const PI_PATH_RESOLVER_LINES = [
|
|
63173
|
+
"function absoluteToolPath(path: unknown, cwd: string): unknown {",
|
|
63174
|
+
" if (typeof path !== \"string\") return path;",
|
|
63175
|
+
" let normalized = path.replace(/[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g, \" \");",
|
|
63176
|
+
" if (normalized.startsWith(\"@\")) normalized = normalized.slice(1);",
|
|
63177
|
+
" if (process.platform === \"win32\" && normalized.startsWith(\"/\") && !normalized.startsWith(\"//\") && !normalized.includes(\"\\\\\")) {",
|
|
63178
|
+
" const drive = normalized.match(/^\\/(?:mnt\\/|cygdrive\\/)?([a-z])(?:\\/(.*))?$/i);",
|
|
63179
|
+
" if (drive?.[1]) normalized = `${drive[1].toUpperCase()}:\\\\${drive[2]?.replaceAll(\"/\", \"\\\\\") ?? \"\"}`;",
|
|
63180
|
+
" }",
|
|
63181
|
+
" if (normalized === \"~\") normalized = homedir();",
|
|
63182
|
+
" else if (normalized.startsWith(\"~/\") || (process.platform === \"win32\" && normalized.startsWith(\"~\\\\\"))) {",
|
|
63183
|
+
" normalized = joinPath(homedir(), normalized.slice(2));",
|
|
63184
|
+
" } else if (/^file:\\/\\//.test(normalized)) {",
|
|
63185
|
+
" try {",
|
|
63186
|
+
" normalized = fileURLToPath(normalized);",
|
|
63187
|
+
" } catch {",
|
|
63188
|
+
" return path;",
|
|
63189
|
+
" }",
|
|
63190
|
+
" }",
|
|
63191
|
+
" return resolvePath(cwd, normalized);",
|
|
63192
|
+
"}"
|
|
63193
|
+
];
|
|
63194
|
+
/**
|
|
63195
|
+
* oh-my-pi's `resolveToCwd` (`tools/path-utils.ts`): `expandPath` strips a
|
|
63196
|
+
* stray leading `:` before a path shape, strips a leading `@` only before an
|
|
63197
|
+
* absolute path, `~` or an internal URL, turns Unicode spaces into plain
|
|
63198
|
+
* spaces, converts a `file://` URL and expands `~`; an internal URL is not a
|
|
63199
|
+
* filesystem path, a bare root (`/`) is the workspace root, and anything else
|
|
63200
|
+
* is resolved against cwd. Windows drive-alias handling is not mirrored.
|
|
63201
|
+
*
|
|
63202
|
+
* @see https://github.com/can1357/oh-my-pi/blob/76b7d843d59bc83cc40cd5decadc89dc808a14e6/packages/coding-agent/src/tools/path-utils.ts
|
|
63203
|
+
*/
|
|
63204
|
+
const OMP_PATH_RESOLVER_LINES = [
|
|
63205
|
+
`const INTERNAL_URL_SCHEME = /^(?:${[
|
|
63206
|
+
"skill",
|
|
63207
|
+
"rule",
|
|
63208
|
+
"memory",
|
|
63209
|
+
"out",
|
|
63210
|
+
"agent",
|
|
63211
|
+
"history",
|
|
63212
|
+
"local",
|
|
63213
|
+
"proc",
|
|
63214
|
+
"cfg",
|
|
63215
|
+
"ssh",
|
|
63216
|
+
"security",
|
|
63217
|
+
"vault",
|
|
63218
|
+
"issue",
|
|
63219
|
+
"pr",
|
|
63220
|
+
"mr",
|
|
63221
|
+
"mcp",
|
|
63222
|
+
"omp",
|
|
63223
|
+
"help",
|
|
63224
|
+
"attachment",
|
|
63225
|
+
"conflict"
|
|
63226
|
+
].join("|")}):\\/\\/?/i;`,
|
|
63227
|
+
"",
|
|
63228
|
+
"function absoluteToolPath(path: unknown, cwd: string): unknown {",
|
|
63229
|
+
" if (typeof path !== \"string\") return path;",
|
|
63230
|
+
" let normalized = /^:(?=[/\\\\~]|\\.\\.?[/\\\\]|[A-Za-z]:)/.test(path) ? path.slice(1) : path;",
|
|
63231
|
+
" if (normalized.startsWith(\"@\")) {",
|
|
63232
|
+
" const rest = normalized.slice(1);",
|
|
63233
|
+
" if (rest.startsWith(\"/\") || rest === \"~\" || rest.startsWith(\"~/\") || win32Path.isAbsolute(rest) || INTERNAL_URL_SCHEME.test(rest)) {",
|
|
63234
|
+
" normalized = rest;",
|
|
63235
|
+
" }",
|
|
63236
|
+
" }",
|
|
63237
|
+
" normalized = normalized.replace(/[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g, \" \");",
|
|
63238
|
+
" if (normalized.toLowerCase().startsWith(\"file://\")) {",
|
|
63239
|
+
" try {",
|
|
63240
|
+
" normalized = fileURLToPath(normalized);",
|
|
63241
|
+
" } catch {",
|
|
63242
|
+
" // oh-my-pi keeps an unconvertible `file://` text as written.",
|
|
63243
|
+
" }",
|
|
63244
|
+
" }",
|
|
63245
|
+
" if (normalized === \"~\") normalized = homedir();",
|
|
63246
|
+
" else if (normalized.startsWith(\"~/\")) normalized = joinPath(homedir(), normalized.slice(2));",
|
|
63247
|
+
" if (INTERNAL_URL_SCHEME.test(normalized)) return normalized;",
|
|
63248
|
+
" if (/^\\/+$/.test(normalized)) return resolvePath(cwd);",
|
|
63249
|
+
" return resolvePath(cwd, normalized);",
|
|
63250
|
+
"}"
|
|
63251
|
+
];
|
|
63252
|
+
/**
|
|
63253
|
+
* Tool names both Pi and oh-my-pi share with a canonical counterpart. Pi's
|
|
63254
|
+
* `powershell` tool is deliberately left out: Rulesync has no canonical name
|
|
63255
|
+
* for it, so it keeps its own.
|
|
63256
|
+
*/
|
|
63257
|
+
const SHARED_CANONICAL_TOOL_NAMES = {
|
|
63258
|
+
bash: "Bash",
|
|
63259
|
+
read: "Read",
|
|
63260
|
+
write: "Write",
|
|
63261
|
+
edit: "Edit",
|
|
63262
|
+
grep: "Grep"
|
|
63263
|
+
};
|
|
62480
63264
|
const PI_EXTENSION_DIALECT = {
|
|
62481
63265
|
overrideKey: "pi",
|
|
62482
63266
|
typesPackage: "@earendil-works/pi-coding-agent",
|
|
62483
63267
|
promptPassLine: "return { action: \"continue\" };",
|
|
62484
|
-
promptCancelLine: "return { action: \"handled\" };"
|
|
63268
|
+
promptCancelLine: "return { action: \"handled\" };",
|
|
63269
|
+
toolNames: {
|
|
63270
|
+
...SHARED_CANONICAL_TOOL_NAMES,
|
|
63271
|
+
find: "Glob"
|
|
63272
|
+
},
|
|
63273
|
+
editTextKeys: {
|
|
63274
|
+
old: "oldText",
|
|
63275
|
+
new: "newText"
|
|
63276
|
+
},
|
|
63277
|
+
pathResolverLines: PI_PATH_RESOLVER_LINES
|
|
62485
63278
|
};
|
|
62486
63279
|
/**
|
|
62487
63280
|
* oh-my-pi's `emitInput` stops at the first result with `handled` set and
|
|
@@ -62493,7 +63286,16 @@ const OMP_EXTENSION_DIALECT = {
|
|
|
62493
63286
|
overrideKey: "omp",
|
|
62494
63287
|
typesPackage: "@oh-my-pi/pi-coding-agent",
|
|
62495
63288
|
promptPassLine: "return {};",
|
|
62496
|
-
promptCancelLine: "return { handled: true };"
|
|
63289
|
+
promptCancelLine: "return { handled: true };",
|
|
63290
|
+
toolNames: {
|
|
63291
|
+
...SHARED_CANONICAL_TOOL_NAMES,
|
|
63292
|
+
glob: "Glob"
|
|
63293
|
+
},
|
|
63294
|
+
editTextKeys: {
|
|
63295
|
+
old: "old_string",
|
|
63296
|
+
new: "new_string"
|
|
63297
|
+
},
|
|
63298
|
+
pathResolverLines: OMP_PATH_RESOLVER_LINES
|
|
62497
63299
|
};
|
|
62498
63300
|
const PI_BLOCKING_MODE_BY_EVENT = {
|
|
62499
63301
|
[PI_BLOCKING_EVENT]: "tool",
|
|
@@ -62517,7 +63319,284 @@ function failureLinesByMode(dialect) {
|
|
|
62517
63319
|
};
|
|
62518
63320
|
}
|
|
62519
63321
|
/**
|
|
62520
|
-
*
|
|
63322
|
+
* Canonical events whose command receives Claude Code's JSON input for the
|
|
63323
|
+
* event on stdin, mapped to its `hook_event_name`; every other command gets an
|
|
63324
|
+
* empty stdin, as in the OpenCode-style plugin (`STDIN_PAYLOADS` in
|
|
63325
|
+
* `opencode-style-generator.ts`). All three ride on Pi's tool events, whose
|
|
63326
|
+
* `event.toolName`, `event.toolCallId` and `event.input` the payload is built
|
|
63327
|
+
* from. A payload is serialized lazily, once per invocation, by the first
|
|
63328
|
+
* handler that runs.
|
|
63329
|
+
*
|
|
63330
|
+
* @see https://github.com/earendil-works/pi/blob/v1.6.0/packages/coding-agent/docs/extensions.md#tool_call
|
|
63331
|
+
* @see https://code.claude.com/docs/en/hooks
|
|
63332
|
+
*/
|
|
63333
|
+
const STDIN_PAYLOAD_EVENTS = {
|
|
63334
|
+
preToolUse: "PreToolUse",
|
|
63335
|
+
postToolUse: "PostToolUse",
|
|
63336
|
+
postToolUseFailure: "PostToolUseFailure"
|
|
63337
|
+
};
|
|
63338
|
+
/**
|
|
63339
|
+
* The fields each payload adds to the tool call's own (`session_id`, `cwd`,
|
|
63340
|
+
* `hook_event_name`, `tool_name`, `tool_input`, `tool_use_id`), as TypeScript
|
|
63341
|
+
* object entries evaluated against the `tool_result` event.
|
|
63342
|
+
*/
|
|
63343
|
+
const STDIN_PAYLOAD_EXTRA_FIELDS = {
|
|
63344
|
+
PreToolUse: "",
|
|
63345
|
+
PostToolUse: "tool_response: { content: event.content, details: event.details }",
|
|
63346
|
+
PostToolUseFailure: "error: toolResultText(event.content)"
|
|
63347
|
+
};
|
|
63348
|
+
/**
|
|
63349
|
+
* Helpers emitted when a handler receives a stdin payload or tests a matcher.
|
|
63350
|
+
*
|
|
63351
|
+
* `claudeToolName` maps the dialect's built-in tool names to the canonical
|
|
63352
|
+
* Claude Code names Rulesync uses elsewhere (`bash` → `Bash`, ...). MCP tools
|
|
63353
|
+
* are already named `mcp__<server>__<tool>` by Pi, and other tools keep their
|
|
63354
|
+
* own name.
|
|
63355
|
+
*
|
|
63356
|
+
* `claudeToolInput` passes the tool's arguments through, except for the file
|
|
63357
|
+
* tools: `path` becomes Claude Code's absolute `file_path`, resolved against
|
|
63358
|
+
* the session cwd the way Pi's `resolveToCwd` does, and on Pi each `edits`
|
|
63359
|
+
* entry's `oldText` / `newText` becomes `old_string` / `new_string` (oh-my-pi
|
|
63360
|
+
* already uses those, see `editTextKeys`). When the call has no top-level
|
|
63361
|
+
* `old_string` / `new_string`, every edit's text is joined into them, as
|
|
63362
|
+
* Claude Code's `Edit` input carries, so a guard reading those sees every
|
|
63363
|
+
* change. The mapped keys are written last and any same-named key the model
|
|
63364
|
+
* added is dropped, so an extra argument (Pi's schemas allow them) cannot make
|
|
63365
|
+
* a guard check a different file or text than the one the tool acts on.
|
|
63366
|
+
*/
|
|
63367
|
+
function buildToolPayloadHelperLines(dialect) {
|
|
63368
|
+
return [
|
|
63369
|
+
`const CLAUDE_TOOL_NAMES: Record<string, string> = ${JSON.stringify(dialect.toolNames)};`,
|
|
63370
|
+
"",
|
|
63371
|
+
"function claudeToolName(toolName: string): string {",
|
|
63372
|
+
" return Object.hasOwn(CLAUDE_TOOL_NAMES, toolName) ? (CLAUDE_TOOL_NAMES[toolName] ?? toolName) : toolName;",
|
|
63373
|
+
"}",
|
|
63374
|
+
"",
|
|
63375
|
+
"function matchesTool(matcher: RegExp, toolName: string): boolean {",
|
|
63376
|
+
" return matcher.test(toolName) || matcher.test(claudeToolName(toolName));",
|
|
63377
|
+
"}",
|
|
63378
|
+
"",
|
|
63379
|
+
...dialect.pathResolverLines,
|
|
63380
|
+
"",
|
|
63381
|
+
`const EDIT_TEXT_KEYS = ${JSON.stringify(dialect.editTextKeys)};`,
|
|
63382
|
+
"const CLAUDE_EDIT_TEXT_KEYS = EDIT_TEXT_KEYS.old === \"old_string\";",
|
|
63383
|
+
"",
|
|
63384
|
+
"function claudeEditEntry(edit: unknown): unknown {",
|
|
63385
|
+
" if (CLAUDE_EDIT_TEXT_KEYS || !edit || typeof edit !== \"object\") return edit;",
|
|
63386
|
+
" const {",
|
|
63387
|
+
" [EDIT_TEXT_KEYS.old]: oldText,",
|
|
63388
|
+
" [EDIT_TEXT_KEYS.new]: newText,",
|
|
63389
|
+
" old_string: _old,",
|
|
63390
|
+
" new_string: _new,",
|
|
63391
|
+
" ...others",
|
|
63392
|
+
" } = edit as Record<string, unknown>;",
|
|
63393
|
+
" return { ...others, old_string: oldText, new_string: newText };",
|
|
63394
|
+
"}",
|
|
63395
|
+
"",
|
|
63396
|
+
"function joinedEditText(edits: unknown[], key: string): string | undefined {",
|
|
63397
|
+
" const texts = edits",
|
|
63398
|
+
" .map((edit: unknown) => (edit as Record<string, unknown> | null)?.[key])",
|
|
63399
|
+
" .filter((text): text is string => typeof text === \"string\");",
|
|
63400
|
+
" return texts.length > 0 ? texts.join(\"\\n\") : undefined;",
|
|
63401
|
+
"}",
|
|
63402
|
+
"",
|
|
63403
|
+
"function claudeToolInput(toolName: string, input: unknown, cwd: string): unknown {",
|
|
63404
|
+
" if (![\"read\", \"write\", \"edit\"].includes(toolName)) return input;",
|
|
63405
|
+
" if (!input || typeof input !== \"object\" || Array.isArray(input)) return input;",
|
|
63406
|
+
" const { path, file_path: _filePath, ...rest } = input as Record<string, unknown>;",
|
|
63407
|
+
" if (!CLAUDE_EDIT_TEXT_KEYS) {",
|
|
63408
|
+
" delete rest.old_string;",
|
|
63409
|
+
" delete rest.new_string;",
|
|
63410
|
+
" }",
|
|
63411
|
+
" // The raw `path` stays, so a guard can check what the model wrote too.",
|
|
63412
|
+
" const claudeInput: Record<string, unknown> = { ...rest, path, file_path: absoluteToolPath(path, cwd) };",
|
|
63413
|
+
" if (!Array.isArray(rest.edits)) return claudeInput;",
|
|
63414
|
+
" const edits = rest.edits.map(claudeEditEntry);",
|
|
63415
|
+
" return {",
|
|
63416
|
+
" ...claudeInput,",
|
|
63417
|
+
" edits,",
|
|
63418
|
+
" old_string: claudeInput.old_string ?? joinedEditText(edits, \"old_string\"),",
|
|
63419
|
+
" new_string: claudeInput.new_string ?? joinedEditText(edits, \"new_string\"),",
|
|
63420
|
+
" };",
|
|
63421
|
+
"}",
|
|
63422
|
+
"",
|
|
63423
|
+
"function toolResultText(content: unknown): string {",
|
|
63424
|
+
" if (!Array.isArray(content)) return \"\";",
|
|
63425
|
+
" return content",
|
|
63426
|
+
" .map((block: unknown) => {",
|
|
63427
|
+
" const part = block as { type?: unknown; text?: unknown } | null;",
|
|
63428
|
+
" return part?.type === \"text\" && typeof part.text === \"string\" ? part.text : \"\";",
|
|
63429
|
+
" })",
|
|
63430
|
+
" .filter(Boolean)",
|
|
63431
|
+
" .join(\"\\n\");",
|
|
63432
|
+
"}",
|
|
63433
|
+
"",
|
|
63434
|
+
"type ToolHookEvent = { toolName: string; toolCallId?: string; input?: unknown };",
|
|
63435
|
+
"",
|
|
63436
|
+
"function toolHookInput(",
|
|
63437
|
+
" hookEventName: string,",
|
|
63438
|
+
" event: ToolHookEvent,",
|
|
63439
|
+
" ctx: ExtensionContext | undefined,",
|
|
63440
|
+
" extra: Record<string, unknown> = {},",
|
|
63441
|
+
"): string {",
|
|
63442
|
+
" const cwd = ctx?.cwd ?? process.cwd();",
|
|
63443
|
+
" return JSON.stringify({",
|
|
63444
|
+
" session_id: ctx?.sessionManager?.getSessionId?.(),",
|
|
63445
|
+
" cwd,",
|
|
63446
|
+
" hook_event_name: hookEventName,",
|
|
63447
|
+
" tool_name: claudeToolName(event.toolName),",
|
|
63448
|
+
" tool_input: claudeToolInput(event.toolName, event.input, cwd),",
|
|
63449
|
+
" tool_use_id: event.toolCallId,",
|
|
63450
|
+
" ...extra,",
|
|
63451
|
+
" });",
|
|
63452
|
+
"}"
|
|
63453
|
+
];
|
|
63454
|
+
}
|
|
63455
|
+
/**
|
|
63456
|
+
* Helpers emitted alongside `tool_call` handlers. A command that exits 0 may
|
|
63457
|
+
* still decide the call the way Claude Code reads a `PreToolUse` hook's JSON
|
|
63458
|
+
* stdout: `hookSpecificOutput.permissionDecision` `"deny"` or `"ask"` (with
|
|
63459
|
+
* `permissionDecisionReason`) or, when no `permissionDecision` is given, the
|
|
63460
|
+
* deprecated top-level `decision: "block"` (with `reason`). Output that is not
|
|
63461
|
+
* such JSON allows the call, so hooks that print plain text keep working. The
|
|
63462
|
+
* deny side is the OpenCode-style plugin's `__rulesyncEnforcePreToolUseResult`
|
|
63463
|
+
* contract, plus the deprecated form Claude Code still honors.
|
|
63464
|
+
*
|
|
63465
|
+
* Pi has no permission prompt of its own, so `"ask"` is put to the user with
|
|
63466
|
+
* `ctx.ui.confirm` when a UI is attached, and denies the call when none is (print
|
|
63467
|
+
* and JSON modes) or the dialog fails: a hook asking for a human must not pass
|
|
63468
|
+
* silently.
|
|
63469
|
+
*/
|
|
63470
|
+
const TOOL_DECISION_HELPER_LINES = [
|
|
63471
|
+
"type ToolHookDecision = { kind: \"deny\" | \"ask\"; reason: string };",
|
|
63472
|
+
"",
|
|
63473
|
+
"function toolHookDecision(stdout: string): ToolHookDecision | undefined {",
|
|
63474
|
+
" let parsed: unknown;",
|
|
63475
|
+
" try {",
|
|
63476
|
+
" parsed = JSON.parse(stdout);",
|
|
63477
|
+
" } catch {",
|
|
63478
|
+
" return undefined;",
|
|
63479
|
+
" }",
|
|
63480
|
+
" if (!parsed || typeof parsed !== \"object\") return undefined;",
|
|
63481
|
+
" const output = parsed as { decision?: unknown; reason?: unknown; hookSpecificOutput?: unknown };",
|
|
63482
|
+
" const specific = output.hookSpecificOutput as",
|
|
63483
|
+
" | { permissionDecision?: unknown; permissionDecisionReason?: unknown }",
|
|
63484
|
+
" | null",
|
|
63485
|
+
" | undefined;",
|
|
63486
|
+
" const hasDecision = typeof specific === \"object\" && specific !== null && specific.permissionDecision !== undefined;",
|
|
63487
|
+
" const decision = hasDecision ? specific?.permissionDecision : output.decision === \"block\" ? \"deny\" : undefined;",
|
|
63488
|
+
" if (decision !== \"deny\" && decision !== \"ask\") return undefined;",
|
|
63489
|
+
" const reason = hasDecision ? specific?.permissionDecisionReason : output.reason;",
|
|
63490
|
+
" return {",
|
|
63491
|
+
" kind: decision,",
|
|
63492
|
+
" reason:",
|
|
63493
|
+
" (typeof reason === \"string\" && sanitizeBlockReason(reason)) ||",
|
|
63494
|
+
" (decision === \"ask\" ? \"A preToolUse hook asked for confirmation.\" : \"Blocked by a preToolUse hook.\"),",
|
|
63495
|
+
" };",
|
|
63496
|
+
"}",
|
|
63497
|
+
"",
|
|
63498
|
+
"async function allowsToolCall(",
|
|
63499
|
+
" decision: ToolHookDecision,",
|
|
63500
|
+
" ctx: ExtensionContext | undefined,",
|
|
63501
|
+
"): Promise<boolean> {",
|
|
63502
|
+
" if (decision.kind !== \"ask\" || !ctx?.hasUI) return false;",
|
|
63503
|
+
" try {",
|
|
63504
|
+
" return await ctx.ui.confirm(\"Allow this tool call?\", decision.reason);",
|
|
63505
|
+
" } catch {",
|
|
63506
|
+
" return false;",
|
|
63507
|
+
" }",
|
|
63508
|
+
"}"
|
|
63509
|
+
];
|
|
63510
|
+
/**
|
|
63511
|
+
* Runs a hook command through the platform shell with `input` as its stdin
|
|
63512
|
+
* (empty when the event has no payload, so a command that reads stdin never
|
|
63513
|
+
* waits on Pi's own), bounded by the hook's `timeout` in seconds (Claude
|
|
63514
|
+
* Code's default of 600 when unset, as in the OpenCode-style plugin). A stdin
|
|
63515
|
+
* the command never reads is not an error.
|
|
63516
|
+
*
|
|
63517
|
+
* The command runs in its own process group (except on Windows), so a command
|
|
63518
|
+
* past its timeout is killed together with everything it started, and the
|
|
63519
|
+
* call rejects with a `HookTimeoutError` right away rather than waiting for a
|
|
63520
|
+
* descendant still holding its output open. Like `promisify(exec)`, which
|
|
63521
|
+
* earlier versions used, a non-zero exit rejects with an error carrying
|
|
63522
|
+
* `code`, `stdout` and `stderr`, and more than 1 MiB on either stream rejects
|
|
63523
|
+
* and kills the command.
|
|
63524
|
+
*
|
|
63525
|
+
* A detached group does not get the terminal's Ctrl+C, so the extension
|
|
63526
|
+
* kills every command still running on `session_shutdown`, after the other
|
|
63527
|
+
* handlers (including a `sessionEnd` hook's) have run: Pi awaits them in
|
|
63528
|
+
* registration order. A Pi process killed outright never fires it, and since
|
|
63529
|
+
* the timeout timer lives in that process too, its commands then keep running
|
|
63530
|
+
* with no deadline until they exit on their own.
|
|
63531
|
+
*/
|
|
63532
|
+
const RUN_HELPER_LINES = [
|
|
63533
|
+
"const MAX_HOOK_OUTPUT_LENGTH = 1024 * 1024;",
|
|
63534
|
+
"",
|
|
63535
|
+
"class HookTimeoutError extends Error {}",
|
|
63536
|
+
"",
|
|
63537
|
+
"// Kills of the commands still running, for `session_shutdown`.",
|
|
63538
|
+
"const runningHookCommands = new Set<() => void>();",
|
|
63539
|
+
"",
|
|
63540
|
+
"function run(",
|
|
63541
|
+
" command: string,",
|
|
63542
|
+
" { input = \"\", seconds }: { input?: string; seconds: number },",
|
|
63543
|
+
"): Promise<{ stdout: string; stderr: string }> {",
|
|
63544
|
+
" return new Promise((resolve, reject) => {",
|
|
63545
|
+
" const detached = process.platform !== \"win32\";",
|
|
63546
|
+
" const child = spawn(command, { shell: true, detached, windowsHide: true });",
|
|
63547
|
+
" const output = { stdout: \"\", stderr: \"\" };",
|
|
63548
|
+
" let settled = false;",
|
|
63549
|
+
" const finish = (error?: Error) => {",
|
|
63550
|
+
" if (settled) return;",
|
|
63551
|
+
" settled = true;",
|
|
63552
|
+
" clearTimeout(timer);",
|
|
63553
|
+
" runningHookCommands.delete(killTree);",
|
|
63554
|
+
" if (error) reject(error);",
|
|
63555
|
+
" else resolve(output);",
|
|
63556
|
+
" };",
|
|
63557
|
+
" const killTree = () => {",
|
|
63558
|
+
" try {",
|
|
63559
|
+
" if (detached && child.pid !== undefined) process.kill(-child.pid, \"SIGKILL\");",
|
|
63560
|
+
" else child.kill(\"SIGKILL\");",
|
|
63561
|
+
" } catch {",
|
|
63562
|
+
" // Already gone.",
|
|
63563
|
+
" }",
|
|
63564
|
+
" child.stdout?.destroy();",
|
|
63565
|
+
" child.stderr?.destroy();",
|
|
63566
|
+
" };",
|
|
63567
|
+
" runningHookCommands.add(killTree);",
|
|
63568
|
+
" const timer = setTimeout(() => {",
|
|
63569
|
+
" killTree();",
|
|
63570
|
+
" finish(new HookTimeoutError(`Hook command timed out after ${seconds} seconds.`));",
|
|
63571
|
+
" }, seconds * 1000);",
|
|
63572
|
+
" for (const stream of [\"stdout\", \"stderr\"] as const) {",
|
|
63573
|
+
" child[stream]?.setEncoding(\"utf8\");",
|
|
63574
|
+
" child[stream]?.on(\"data\", (chunk: string) => {",
|
|
63575
|
+
" output[stream] += chunk;",
|
|
63576
|
+
" if (output[stream].length <= MAX_HOOK_OUTPUT_LENGTH) return;",
|
|
63577
|
+
" killTree();",
|
|
63578
|
+
" finish(new Error(`Hook command wrote more than 1 MiB to ${stream}.`));",
|
|
63579
|
+
" });",
|
|
63580
|
+
" }",
|
|
63581
|
+
" child.on(\"error\", (error) => finish(error));",
|
|
63582
|
+
" child.on(\"close\", (code, signal) => {",
|
|
63583
|
+
" if (code === 0) return finish();",
|
|
63584
|
+
" finish(",
|
|
63585
|
+
" Object.assign(new Error(`Command failed: ${command}`), {",
|
|
63586
|
+
" code,",
|
|
63587
|
+
" signal,",
|
|
63588
|
+
" stdout: output.stdout,",
|
|
63589
|
+
" stderr: output.stderr,",
|
|
63590
|
+
" }),",
|
|
63591
|
+
" );",
|
|
63592
|
+
" });",
|
|
63593
|
+
" child.stdin?.on(\"error\", () => {});",
|
|
63594
|
+
" child.stdin?.end(input);",
|
|
63595
|
+
" });",
|
|
63596
|
+
"}"
|
|
63597
|
+
];
|
|
63598
|
+
/**
|
|
63599
|
+
* Helper emitted alongside blocking handlers. `run` rejects on a
|
|
62521
63600
|
* non-zero exit with an error carrying `stdout` / `stderr` / `code`, so the
|
|
62522
63601
|
* reason is derived from the rejection rather than from a resolved exit code.
|
|
62523
63602
|
* A command that could not be run at all (spawn failure, `maxBuffer` overflow)
|
|
@@ -62621,7 +63700,9 @@ function collectPiHandlers({ effectiveHooks, eventMap }) {
|
|
|
62621
63700
|
handlers.push({
|
|
62622
63701
|
command: def.command,
|
|
62623
63702
|
matcher: def.matcher ? def.matcher : void 0,
|
|
62624
|
-
onlyOnError: PI_ERROR_GATED_CANONICAL_EVENTS.has(canonicalEvent)
|
|
63703
|
+
onlyOnError: PI_ERROR_GATED_CANONICAL_EVENTS.has(canonicalEvent),
|
|
63704
|
+
...hookTimingOf(def),
|
|
63705
|
+
...PI_TOOL_EVENTS.has(piEvent) && STDIN_PAYLOAD_EVENTS[canonicalEvent] ? { payload: STDIN_PAYLOAD_EVENTS[canonicalEvent] } : {}
|
|
62625
63706
|
});
|
|
62626
63707
|
}
|
|
62627
63708
|
if (handlers.length > 0) {
|
|
@@ -62636,22 +63717,63 @@ function buildCommandLines({ handler, usesToolName, blocking, dialect }) {
|
|
|
62636
63717
|
const lines = [];
|
|
62637
63718
|
const conditions = [];
|
|
62638
63719
|
if (handler.onlyOnError) conditions.push("event.isError");
|
|
62639
|
-
if (usesToolName && handler.matcher) conditions.push(`new RegExp(${matcherToEmbeddedLiteral(handler.matcher)})
|
|
63720
|
+
if (usesToolName && handler.matcher) conditions.push(`matchesTool(new RegExp(${matcherToEmbeddedLiteral(handler.matcher)}), event.toolName)`);
|
|
62640
63721
|
const gated = conditions.length > 0;
|
|
62641
63722
|
const indent = gated ? " " : " ";
|
|
62642
|
-
const
|
|
63723
|
+
const options = [...handler.payload ? [`input: ${payloadAccessorName(handler.payload)}()`] : [], `seconds: ${handler.timeout}`];
|
|
63724
|
+
const runCall = `run(${JSON.stringify(handler.command)}, { ${options.join(", ")} })`;
|
|
62643
63725
|
if (gated) lines.push(` if (${conditions.join(" && ")}) {`);
|
|
62644
63726
|
const onFailure = failureLinesByMode(dialect)[blocking];
|
|
62645
|
-
if (
|
|
63727
|
+
if (blocking === "tool") {
|
|
62646
63728
|
lines.push(`${indent}try {`);
|
|
62647
|
-
lines.push(`${indent} await
|
|
63729
|
+
lines.push(`${indent} const decision = toolHookDecision((await ${runCall}).stdout);`);
|
|
63730
|
+
lines.push(`${indent} if (decision && !(await allowsToolCall(decision, ctx))) return { block: true, reason: decision.reason };`);
|
|
63731
|
+
lines.push(`${indent}} catch (error) {`);
|
|
63732
|
+
if (handler.failClosed === false) {
|
|
63733
|
+
lines.push(`${indent} if (error instanceof HookTimeoutError) {`);
|
|
63734
|
+
lines.push(`${indent} console.error("[rulesync-hooks] preToolUse hook timed out");`);
|
|
63735
|
+
lines.push(`${indent} } else {`);
|
|
63736
|
+
for (const line of onFailure) lines.push(`${indent} ${line}`);
|
|
63737
|
+
lines.push(`${indent} }`);
|
|
63738
|
+
} else for (const line of onFailure) lines.push(`${indent} ${line}`);
|
|
63739
|
+
lines.push(`${indent}}`);
|
|
63740
|
+
} else if (onFailure.length > 0) {
|
|
63741
|
+
lines.push(`${indent}try {`);
|
|
63742
|
+
lines.push(`${indent} await ${runCall};`);
|
|
62648
63743
|
lines.push(`${indent}} catch (error) {`);
|
|
62649
63744
|
for (const line of onFailure) lines.push(`${indent} ${line}`);
|
|
62650
63745
|
lines.push(`${indent}}`);
|
|
62651
|
-
} else lines.push(`${indent}await
|
|
63746
|
+
} else lines.push(`${indent}await ${runCall};`);
|
|
62652
63747
|
if (gated) lines.push(" }");
|
|
62653
63748
|
return lines;
|
|
62654
63749
|
}
|
|
63750
|
+
/** The per-invocation closure a handler calls for its serialized payload. */
|
|
63751
|
+
function payloadAccessorName(hookEventName) {
|
|
63752
|
+
return `${hookEventName.charAt(0).toLowerCase()}${hookEventName.slice(1)}Input`;
|
|
63753
|
+
}
|
|
63754
|
+
/** Lazily serialized payloads the handlers of one subscription use. */
|
|
63755
|
+
function buildPayloadLines(handlers) {
|
|
63756
|
+
const payloads = [...new Set(handlers.flatMap((h) => h.payload ? [h.payload] : []))];
|
|
63757
|
+
const lines = [];
|
|
63758
|
+
for (const payload of payloads) {
|
|
63759
|
+
const accessor = payloadAccessorName(payload);
|
|
63760
|
+
const extra = STDIN_PAYLOAD_EXTRA_FIELDS[payload] ?? "";
|
|
63761
|
+
const extraArgument = extra ? `, { ${extra} }` : "";
|
|
63762
|
+
lines.push(` let ${accessor}Cache: string | undefined;`);
|
|
63763
|
+
lines.push(` const ${accessor} = () => (${accessor}Cache ??= toolHookInput(${JSON.stringify(payload)}, event, ctx${extraArgument}));`);
|
|
63764
|
+
}
|
|
63765
|
+
return lines;
|
|
63766
|
+
}
|
|
63767
|
+
/**
|
|
63768
|
+
* The handler's parameter list. `ctx` is the second handler argument, so the
|
|
63769
|
+
* prompt gate and the payload builders (which read the session id and cwd)
|
|
63770
|
+
* name both.
|
|
63771
|
+
*/
|
|
63772
|
+
function handlerParams({ handlers, readsEvent, isPromptGate }) {
|
|
63773
|
+
const usesPayload = handlers.some((h) => h.payload);
|
|
63774
|
+
if (isPromptGate || usesPayload) return "event, ctx";
|
|
63775
|
+
return readsEvent || handlers.some((h) => h.onlyOnError) ? "event" : "";
|
|
63776
|
+
}
|
|
62655
63777
|
function buildSubscriptionLines(handlerGroups, dialect) {
|
|
62656
63778
|
const lines = [];
|
|
62657
63779
|
for (const [piEvent, handlers] of Object.entries(handlerGroups)) {
|
|
@@ -62661,13 +63783,17 @@ function buildSubscriptionLines(handlerGroups, dialect) {
|
|
|
62661
63783
|
const isSessionStopGate = blocking === "sessionStop";
|
|
62662
63784
|
const collectsStopFailures = isSettleGate || isSessionStopGate;
|
|
62663
63785
|
const usesToolName = PI_TOOL_EVENTS.has(piEvent) && handlers.some((h) => h.matcher);
|
|
62664
|
-
const usesErrorFlag = handlers.some((h) => h.onlyOnError);
|
|
62665
63786
|
const gatesOnAssistant = PI_ASSISTANT_MESSAGE_EVENTS.has(piEvent);
|
|
62666
|
-
const params =
|
|
63787
|
+
const params = handlerParams({
|
|
63788
|
+
handlers,
|
|
63789
|
+
readsEvent: usesToolName || gatesOnAssistant || collectsStopFailures,
|
|
63790
|
+
isPromptGate
|
|
63791
|
+
});
|
|
62667
63792
|
lines.push(` pi.on(${JSON.stringify(piEvent)}, async (${params}) => {`);
|
|
62668
63793
|
if (gatesOnAssistant) lines.push(` if (event.message.role !== "assistant") return;`);
|
|
62669
63794
|
if (isPromptGate) lines.push(` if (event.source === "extension") ${dialect.promptPassLine}`);
|
|
62670
63795
|
if (collectsStopFailures) lines.push(" const stopHookFailures: unknown[] = [];");
|
|
63796
|
+
lines.push(...buildPayloadLines(handlers));
|
|
62671
63797
|
for (const handler of handlers) lines.push(...buildCommandLines({
|
|
62672
63798
|
handler,
|
|
62673
63799
|
usesToolName,
|
|
@@ -62703,6 +63829,10 @@ function buildSubscriptionLines(handlerGroups, dialect) {
|
|
|
62703
63829
|
}
|
|
62704
63830
|
return lines;
|
|
62705
63831
|
}
|
|
63832
|
+
/** Whether a handler belongs to a tool event, where its matcher is tested. */
|
|
63833
|
+
function handlerGroupHasToolEvent(handlerGroups, handler) {
|
|
63834
|
+
return Object.entries(handlerGroups).some(([piEvent, handlers]) => PI_TOOL_EVENTS.has(piEvent) && handlers.includes(handler));
|
|
63835
|
+
}
|
|
62706
63836
|
/**
|
|
62707
63837
|
* Generate the rulesync-owned Pi extension (a TypeScript module with a
|
|
62708
63838
|
* default-export factory receiving Pi's ExtensionAPI) that subscribes to the
|
|
@@ -62717,6 +63847,12 @@ function buildSubscriptionLines(handlerGroups, dialect) {
|
|
|
62717
63847
|
* command's output as feedback.
|
|
62718
63848
|
* `postToolUse` and `postToolUseFailure` share Pi's `tool_result` event; the
|
|
62719
63849
|
* latter's commands run only when `event.isError` is set.
|
|
63850
|
+
* Commands on the tool events receive Claude Code's hook input on stdin (see
|
|
63851
|
+
* `STDIN_PAYLOAD_EVENTS`), and a tool matcher is tested against both Pi's tool
|
|
63852
|
+
* name and its canonical Claude Code name. On `tool_call`, a command that exits
|
|
63853
|
+
* 0 with a JSON deny decision also denies the call, and one past its `timeout`
|
|
63854
|
+
* denies it unless the hook sets `failClosed: false`, mirroring the
|
|
63855
|
+
* OpenCode-style plugin.
|
|
62720
63856
|
*
|
|
62721
63857
|
* @see https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/extensions.md
|
|
62722
63858
|
*/
|
|
@@ -62736,7 +63872,9 @@ function generatePiExtensionCode({ config, supportedEvents, eventMap, dialect =
|
|
|
62736
63872
|
const hasPromptGate = Boolean(handlerGroups[PI_PROMPT_BLOCKING_EVENT]);
|
|
62737
63873
|
const hasSettleGate = Boolean(handlerGroups[PI_SETTLE_BLOCKING_EVENT]);
|
|
62738
63874
|
const hasSessionStopGate = Boolean(handlerGroups[OMP_SESSION_STOP_BLOCKING_EVENT]);
|
|
62739
|
-
const
|
|
63875
|
+
const needsToolHelpers = Object.values(handlerGroups).flat().some((h) => h.payload || h.matcher && handlerGroupHasToolEvent(handlerGroups, h));
|
|
63876
|
+
const hasToolGate = Boolean(handlerGroups[PI_BLOCKING_EVENT]);
|
|
63877
|
+
const needsBlockReasonHelper = hasToolGate || hasPromptGate || hasSettleGate || hasSessionStopGate;
|
|
62740
63878
|
const lines = ["// Generated by rulesync. Do not edit manually."];
|
|
62741
63879
|
if (subscriptionLines.length === 0) {
|
|
62742
63880
|
lines.push("export default function () {}");
|
|
@@ -62746,34 +63884,33 @@ function generatePiExtensionCode({ config, supportedEvents, eventMap, dialect =
|
|
|
62746
63884
|
const importedTypes = [
|
|
62747
63885
|
...hasSettleGate ? ["AgentBeforeSettleEvent", "AgentBeforeSettleEventResult"] : [],
|
|
62748
63886
|
"ExtensionAPI",
|
|
62749
|
-
...hasPromptGate ? ["ExtensionContext"] : []
|
|
63887
|
+
...hasPromptGate || needsToolHelpers ? ["ExtensionContext"] : []
|
|
62750
63888
|
].join(", ");
|
|
62751
|
-
lines.push("import {
|
|
62752
|
-
|
|
63889
|
+
lines.push("import { spawn } from \"node:child_process\";");
|
|
63890
|
+
if (needsToolHelpers) {
|
|
63891
|
+
lines.push("import { homedir } from \"node:os\";");
|
|
63892
|
+
lines.push(dialect.pathResolverLines === OMP_PATH_RESOLVER_LINES ? "import { join as joinPath, resolve as resolvePath, win32 as win32Path } from \"node:path\";" : "import { join as joinPath, resolve as resolvePath } from \"node:path\";");
|
|
63893
|
+
lines.push("import { fileURLToPath } from \"node:url\";");
|
|
63894
|
+
}
|
|
62753
63895
|
lines.push("");
|
|
62754
63896
|
lines.push(`import type { ${importedTypes} } from ${JSON.stringify(dialect.typesPackage)};`);
|
|
62755
63897
|
lines.push("");
|
|
62756
|
-
|
|
62757
|
-
|
|
62758
|
-
|
|
62759
|
-
|
|
62760
|
-
|
|
62761
|
-
|
|
62762
|
-
|
|
62763
|
-
|
|
62764
|
-
|
|
62765
|
-
|
|
62766
|
-
if (hasSettleGate || hasSessionStopGate) {
|
|
62767
|
-
lines.push(...STOP_HOOK_BLOCK_HELPER_LINES);
|
|
62768
|
-
lines.push("");
|
|
62769
|
-
}
|
|
62770
|
-
if (hasSettleGate) {
|
|
62771
|
-
lines.push(...STOP_HOOK_HELPER_LINES);
|
|
62772
|
-
lines.push("");
|
|
62773
|
-
}
|
|
63898
|
+
const helperBlocks = [
|
|
63899
|
+
[true, RUN_HELPER_LINES],
|
|
63900
|
+
[needsBlockReasonHelper, BLOCK_REASON_HELPER_LINES],
|
|
63901
|
+
[hasToolGate, TOOL_DECISION_HELPER_LINES],
|
|
63902
|
+
[needsToolHelpers, needsToolHelpers ? buildToolPayloadHelperLines(dialect) : []],
|
|
63903
|
+
[hasPromptGate, PROMPT_GATE_HELPER_LINES],
|
|
63904
|
+
[hasSettleGate || hasSessionStopGate, STOP_HOOK_BLOCK_HELPER_LINES],
|
|
63905
|
+
[hasSettleGate, STOP_HOOK_HELPER_LINES]
|
|
63906
|
+
];
|
|
63907
|
+
for (const [included, block] of helperBlocks) if (included) lines.push(...block, "");
|
|
62774
63908
|
lines.push("export default function (pi: ExtensionAPI) {");
|
|
62775
63909
|
if (hasSettleGate) lines.push(" let stopHookContinued = false;");
|
|
62776
63910
|
lines.push(...subscriptionLines);
|
|
63911
|
+
lines.push(" pi.on(\"session_shutdown\", async () => {");
|
|
63912
|
+
lines.push(" for (const kill of [...runningHookCommands]) kill();");
|
|
63913
|
+
lines.push(" });");
|
|
62777
63914
|
lines.push("}");
|
|
62778
63915
|
lines.push("");
|
|
62779
63916
|
return lines.join("\n");
|
|
@@ -62836,6 +63973,162 @@ var OmpHooks = class OmpHooks extends ToolHooks {
|
|
|
62836
63973
|
});
|
|
62837
63974
|
}
|
|
62838
63975
|
};
|
|
63976
|
+
// src/features/hooks/openbitfun-hooks.ts
|
|
63977
|
+
/**
|
|
63978
|
+
* Canonical (Claude Code) tool names whose OpenBitFun runtime name differs.
|
|
63979
|
+
* OpenBitFun's shell tool is `ExecCommand`; its own Claude-dialect skill hook
|
|
63980
|
+
* adapter maps `Bash` onto it, with the shell command in `tool_input.cmd`.
|
|
63981
|
+
* `Read`, `Write`, `Edit`, `Glob`, `Grep`, `WebFetch`, `WebSearch`, `Skill` and
|
|
63982
|
+
* `LS` share their names, so they need no entry.
|
|
63983
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/skills/hooks.rs
|
|
63984
|
+
*/
|
|
63985
|
+
const CANONICAL_TO_OPENBITFUN_TOOL_NAMES = { Bash: "ExecCommand" };
|
|
63986
|
+
const OPENBITFUN_TO_CANONICAL_TOOL_NAMES = Object.fromEntries(Object.entries(CANONICAL_TO_OPENBITFUN_TOOL_NAMES).map(([canonical, tool]) => [tool, canonical]));
|
|
63987
|
+
/**
|
|
63988
|
+
* OpenBitFun's built-in tool names (the default custom-agent tool sets in
|
|
63989
|
+
* `custom_agent.rs`, plus `LS`). Capitalized matcher names outside this set
|
|
63990
|
+
* are warned about on events that gate a tool call.
|
|
63991
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/custom_agent.rs
|
|
63992
|
+
*/
|
|
63993
|
+
const OPENBITFUN_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
63994
|
+
"Read",
|
|
63995
|
+
"Glob",
|
|
63996
|
+
"Grep",
|
|
63997
|
+
"LS",
|
|
63998
|
+
"Write",
|
|
63999
|
+
"Edit",
|
|
64000
|
+
"Delete",
|
|
64001
|
+
"ExecCommand",
|
|
64002
|
+
"WriteStdin",
|
|
64003
|
+
"ExecControl",
|
|
64004
|
+
"AgentSpawn",
|
|
64005
|
+
"AgentFork",
|
|
64006
|
+
"AgentSendInput",
|
|
64007
|
+
"AgentControl",
|
|
64008
|
+
"AgentList",
|
|
64009
|
+
"AgentWait",
|
|
64010
|
+
"ListModels",
|
|
64011
|
+
"Skill",
|
|
64012
|
+
"WebSearch",
|
|
64013
|
+
"WebFetch"
|
|
64014
|
+
]);
|
|
64015
|
+
/**
|
|
64016
|
+
* Events whose hooks can deny a tool call, so a matcher that never matches
|
|
64017
|
+
* makes the guard fail open. The keys are canonical names, or OpenBitFun's own
|
|
64018
|
+
* names when the hook comes from the `openbitfun.hooks` override block.
|
|
64019
|
+
*/
|
|
64020
|
+
const TOOL_GATING_EVENTS = /* @__PURE__ */ new Set([
|
|
64021
|
+
"preToolUse",
|
|
64022
|
+
"permissionRequest",
|
|
64023
|
+
"PreToolUse",
|
|
64024
|
+
"PermissionRequest"
|
|
64025
|
+
]);
|
|
64026
|
+
function canonicalToOpenbitfunMatcher({ matcher, eventName, warn }) {
|
|
64027
|
+
const translated = replaceMatcherNames(matcher, CANONICAL_TO_OPENBITFUN_TOOL_NAMES);
|
|
64028
|
+
if (TOOL_GATING_EVENTS.has(eventName)) {
|
|
64029
|
+
const unknown = capitalizedMatcherNames(translated).filter((name) => !OPENBITFUN_TOOL_NAMES.has(name));
|
|
64030
|
+
if (unknown.length > 0) warn(`${unknown.map((name) => quoteValueForWarning(name)).join(", ")} in the "${eventName}" matcher ${quoteValueForWarning(matcher)} is not an OpenBitFun built-in tool, so it is written as-is and will likely never match there, and the hook will not run for that tool.`);
|
|
64031
|
+
}
|
|
64032
|
+
return translated;
|
|
64033
|
+
}
|
|
64034
|
+
function openbitfunToCanonicalMatcher(matcher) {
|
|
64035
|
+
return replaceMatcherNames(matcher, OPENBITFUN_TO_CANONICAL_TOOL_NAMES);
|
|
64036
|
+
}
|
|
64037
|
+
/**
|
|
64038
|
+
* Why OpenBitFun would skip a generated handler, or `undefined` when it runs
|
|
64039
|
+
* it. OpenBitFun's `parse_handler` treats a command handler whose `timeout` is
|
|
64040
|
+
* not a positive integer as invalid and skips that handler.
|
|
64041
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/native_hooks/settings.rs
|
|
64042
|
+
*/
|
|
64043
|
+
function describeRejectedOpenbitfunHandler(handler) {
|
|
64044
|
+
const { timeout } = handler;
|
|
64045
|
+
if (timeout !== void 0 && (typeof timeout !== "number" || !Number.isSafeInteger(timeout) || timeout <= 0)) return `its "timeout" ${JSON.stringify(timeout) ?? String(timeout)} is not a positive integer, so OpenBitFun would skip it as invalid`;
|
|
64046
|
+
}
|
|
64047
|
+
/**
|
|
64048
|
+
* OpenBitFun implements the Codex hook contract: the same `hooks.json`
|
|
64049
|
+
* document, handler fields and matcher semantics (regexes anchored to the
|
|
64050
|
+
* whole tool name). It differs in the events it dispatches, in running only
|
|
64051
|
+
* `type: "command"` handlers (`prompt` and `agent` handlers are parsed but
|
|
64052
|
+
* skipped), in its runtime tool names (`ExecCommand` for `Bash`), and in the
|
|
64053
|
+
* handler fields it reads: `command`, `commandWindows`, `timeout` and
|
|
64054
|
+
* `statusMessage` only, so Codex's `async` and `additionalContextLimit` are
|
|
64055
|
+
* not forwarded.
|
|
64056
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/docs/features/agent-hooks.md
|
|
64057
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/src/crates/execution/agent-runtime/src/native_hooks/settings.rs
|
|
64058
|
+
*/
|
|
64059
|
+
const OPENBITFUN_CONVERTER_CONFIG = {
|
|
64060
|
+
...CODEXCLI_CONVERTER_CONFIG,
|
|
64061
|
+
supportedEvents: OPENBITFUN_HOOK_EVENTS,
|
|
64062
|
+
canonicalToToolEventNames: CANONICAL_TO_OPENBITFUN_EVENT_NAMES,
|
|
64063
|
+
toolToCanonicalEventNames: OPENBITFUN_TO_CANONICAL_EVENT_NAMES,
|
|
64064
|
+
supportedHookTypes: /* @__PURE__ */ new Set(["command"]),
|
|
64065
|
+
numberPassthroughFields: [],
|
|
64066
|
+
booleanPassthroughFields: [],
|
|
64067
|
+
matcherTranslation: {
|
|
64068
|
+
toTool: canonicalToOpenbitfunMatcher,
|
|
64069
|
+
toCanonical: openbitfunToCanonicalMatcher
|
|
64070
|
+
}
|
|
64071
|
+
};
|
|
64072
|
+
/**
|
|
64073
|
+
* Hooks generator for OpenBitFun: a Codex-shaped `hooks.json` at
|
|
64074
|
+
* `.openbitfun/config/hooks.json` (project) and `<user root>/config/hooks.json`
|
|
64075
|
+
* (global; see {@link openbitfunGlobalConfigDir}). Both layers are additive.
|
|
64076
|
+
*
|
|
64077
|
+
* Project hooks are off by default in OpenBitFun: they only run once the
|
|
64078
|
+
* `app.hooks.project_hooks_enabled` setting is turned on.
|
|
64079
|
+
*
|
|
64080
|
+
* @see https://github.com/openBitFun/OpenBitFun/blob/main/docs/features/agent-hooks.md
|
|
64081
|
+
*/
|
|
64082
|
+
var OpenbitfunHooks = class OpenbitfunHooks extends ToolHooks {
|
|
64083
|
+
static getSettablePaths({ global = false } = {}) {
|
|
64084
|
+
return {
|
|
64085
|
+
relativeDirPath: global ? openbitfunGlobalConfigDir() : OPENBITFUN_CONFIG_DIR_PATH,
|
|
64086
|
+
relativeFilePath: OPENBITFUN_HOOKS_FILE_NAME
|
|
64087
|
+
};
|
|
64088
|
+
}
|
|
64089
|
+
static async fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false, preserveUnowned = false, logger }) {
|
|
64090
|
+
if (global) warnOpenbitfunXdgOverride({
|
|
64091
|
+
kind: "config",
|
|
64092
|
+
logger
|
|
64093
|
+
});
|
|
64094
|
+
const paths = OpenbitfunHooks.getSettablePaths({ global });
|
|
64095
|
+
const { fileContent, owned } = await buildCodexStyleHooksFile({
|
|
64096
|
+
outputRoot,
|
|
64097
|
+
relativeDirPath: paths.relativeDirPath,
|
|
64098
|
+
relativeFilePath: paths.relativeFilePath,
|
|
64099
|
+
rulesyncHooks,
|
|
64100
|
+
toolOverrideHooks: rulesyncHooks.getJson().openbitfun?.hooks,
|
|
64101
|
+
converterConfig: OPENBITFUN_CONVERTER_CONFIG,
|
|
64102
|
+
toolLabel: "OpenBitFun",
|
|
64103
|
+
describeRejected: describeRejectedOpenbitfunHandler,
|
|
64104
|
+
preserveUnowned,
|
|
64105
|
+
logger
|
|
64106
|
+
});
|
|
64107
|
+
return new OpenbitfunHooks({
|
|
64108
|
+
outputRoot,
|
|
64109
|
+
relativeDirPath: paths.relativeDirPath,
|
|
64110
|
+
relativeFilePath: paths.relativeFilePath,
|
|
64111
|
+
fileContent,
|
|
64112
|
+
ownedHookRefs: preserveUnowned ? owned : void 0,
|
|
64113
|
+
validate
|
|
64114
|
+
});
|
|
64115
|
+
}
|
|
64116
|
+
toRulesyncHooks({ logger } = {}) {
|
|
64117
|
+
const parsed = this.parseFileContentOrThrow({
|
|
64118
|
+
displayName: "OpenBitFun",
|
|
64119
|
+
parse: (fileContent) => JSON.parse(fileContent)
|
|
64120
|
+
});
|
|
64121
|
+
return this.toRulesyncHooksDefault({ fileContent: codexStyleHooksToRulesyncContent({
|
|
64122
|
+
parsed,
|
|
64123
|
+
converterConfig: OPENBITFUN_CONVERTER_CONFIG,
|
|
64124
|
+
overrideKey: "openbitfun",
|
|
64125
|
+
logger
|
|
64126
|
+
}) });
|
|
64127
|
+
}
|
|
64128
|
+
static supportsPreserveUnowned() {
|
|
64129
|
+
return true;
|
|
64130
|
+
}
|
|
64131
|
+
};
|
|
62839
64132
|
// src/features/hooks/opencodev1-hooks.ts
|
|
62840
64133
|
/**
|
|
62841
64134
|
* Hooks generator for **OpenCode V1** (OpenCode 1.x). OpenCode 2.x does not
|
|
@@ -64916,6 +66209,16 @@ const toolHooksFactories = /* @__PURE__ */ new Map([
|
|
|
64916
66209
|
...converterCapabilities(CODEXCLI_CONVERTER_CONFIG),
|
|
64917
66210
|
supportsMatcher: true
|
|
64918
66211
|
}],
|
|
66212
|
+
["openbitfun", {
|
|
66213
|
+
class: OpenbitfunHooks,
|
|
66214
|
+
meta: {
|
|
66215
|
+
supportsProject: true,
|
|
66216
|
+
supportsGlobal: true,
|
|
66217
|
+
supportsImport: true
|
|
66218
|
+
},
|
|
66219
|
+
...converterCapabilities(OPENBITFUN_CONVERTER_CONFIG),
|
|
66220
|
+
supportsMatcher: true
|
|
66221
|
+
}],
|
|
64919
66222
|
["commandcode", {
|
|
64920
66223
|
class: CommandcodeHooks,
|
|
64921
66224
|
meta: {
|
|
@@ -65198,7 +66501,13 @@ const toolHooksFactories = /* @__PURE__ */ new Map([
|
|
|
65198
66501
|
},
|
|
65199
66502
|
...converterCapabilities(BobHooks.getConverterConfig()),
|
|
65200
66503
|
supportsMatcher: true,
|
|
65201
|
-
matcherEvents:
|
|
66504
|
+
matcherEvents: BOB_MATCHER_HOOK_EVENTS,
|
|
66505
|
+
dropsUnknownOverrideEvents: true,
|
|
66506
|
+
overrideOnlyEvents: BOB_NATIVE_HOOK_EVENTS,
|
|
66507
|
+
overrideOptIn: {
|
|
66508
|
+
events: BOB_OPT_IN_HOOK_EVENTS,
|
|
66509
|
+
note: "They need Bob Shell 2.1.0 or later, and an older Bob Shell ignores the whole hooks block of a settings file that names them."
|
|
66510
|
+
}
|
|
65202
66511
|
}],
|
|
65203
66512
|
["continue", {
|
|
65204
66513
|
class: ContinueHooks,
|
|
@@ -65524,12 +66833,26 @@ var HooksProcessor = class extends FeatureProcessor {
|
|
|
65524
66833
|
...overrideHooks
|
|
65525
66834
|
};
|
|
65526
66835
|
{
|
|
65527
|
-
const
|
|
66836
|
+
const optInEvents = factory.overrideOptIn?.events ?? {};
|
|
66837
|
+
const isOptIn = (e) => Object.hasOwn(optInEvents, e);
|
|
66838
|
+
const overrideKeys = new Set(Object.keys(overrideHooks));
|
|
66839
|
+
const skippedEvents = unsupportedEventNames({
|
|
65528
66840
|
factory,
|
|
65529
66841
|
sharedHooks,
|
|
65530
66842
|
effectiveHooks
|
|
65531
66843
|
});
|
|
66844
|
+
const skipped = skippedEvents.filter((e) => !isOptIn(e));
|
|
66845
|
+
const optIn = skippedEvents.filter(isOptIn).filter((e) => Object.hasOwn(sharedHooks, e) && !overrideKeys.has(optInEvents[e] ?? ""));
|
|
66846
|
+
const misnamed = skippedEvents.filter(isOptIn).filter((e) => overrideKeys.has(e));
|
|
65532
66847
|
if (skipped.length > 0) this.logger.warn(`Skipped hook event(s) for ${this.toolTarget} (not supported): ${skipped.join(", ")}`);
|
|
66848
|
+
if (optIn.length > 0) {
|
|
66849
|
+
const nativeNames = optIn.map((e) => optInEvents[e]).join(", ");
|
|
66850
|
+
this.logger.warn(`Skipped hook event(s) for ${this.toolTarget}: ${optIn.join(", ")}. ${factory.overrideOptIn?.note} To opt in, author them under the "${overrideKey}.hooks" override with the native name(s) ${nativeNames}.`);
|
|
66851
|
+
}
|
|
66852
|
+
if (misnamed.length > 0) {
|
|
66853
|
+
const nativeNames = misnamed.map((e) => optInEvents[e]).join(", ");
|
|
66854
|
+
this.logger.warn(`Skipped "${overrideKey}.hooks" key(s) for ${this.toolTarget}: ${misnamed.join(", ")}. Use the native name(s) ${nativeNames} instead.`);
|
|
66855
|
+
}
|
|
65533
66856
|
}
|
|
65534
66857
|
{
|
|
65535
66858
|
const supportedHookTypes = new Set(factory.supportedHookTypes);
|
|
@@ -73489,7 +74812,8 @@ const HERMES_OPAQUE_MAPPING_KEYS = [
|
|
|
73489
74812
|
* alias — `auth` (`oauth` for OAuth 2.1/PKCE), mTLS `client_cert` (string PEM
|
|
73490
74813
|
* path, or `[cert, key]`/`[cert, key, password]` list) and `client_key`,
|
|
73491
74814
|
* `connect_timeout` (seconds), `supports_parallel_tool_calls`, `protocol`,
|
|
73492
|
-
* `lazy`, `events` (see {@link copyHermesBoolLikeFields}), `
|
|
74815
|
+
* `lazy`, `events` (see {@link copyHermesBoolLikeFields}), `single_instance`,
|
|
74816
|
+
* `keepalive_interval`,
|
|
73493
74817
|
* `elicitation`, `trust`, `identity_header`, and
|
|
73494
74818
|
* the cost keys (see {@link copyHermesCostFields}) —
|
|
73495
74819
|
* verbatim from `source` to `target`. Field names are identical on both sides
|
|
@@ -73540,6 +74864,10 @@ function copyHermesAdvancedFields(source, target, logger) {
|
|
|
73540
74864
|
target.skip_preflight = source.skip_preflight;
|
|
73541
74865
|
copied = true;
|
|
73542
74866
|
}
|
|
74867
|
+
if (typeof source.single_instance === "boolean") {
|
|
74868
|
+
target.single_instance = source.single_instance;
|
|
74869
|
+
copied = true;
|
|
74870
|
+
}
|
|
73543
74871
|
if (typeof source.keepalive_interval === "number") {
|
|
73544
74872
|
target.keepalive_interval = source.keepalive_interval;
|
|
73545
74873
|
copied = true;
|
|
@@ -84131,7 +85459,7 @@ function buildVscodeCommandLists({ rules, toolLabel, logger, prefixSemantics = "
|
|
|
84131
85459
|
};
|
|
84132
85460
|
}
|
|
84133
85461
|
// src/features/permissions/bob-permissions.ts
|
|
84134
|
-
const TOOL_LABEL = "IBM Bob";
|
|
85462
|
+
const TOOL_LABEL$1 = "IBM Bob";
|
|
84135
85463
|
/** The top-level settings key holding Bob's auto-approval configuration. */
|
|
84136
85464
|
const APPROVAL_KEY$1 = "approval";
|
|
84137
85465
|
/** The top-level settings key holding Bob's per-feature auto-approve toggles. */
|
|
@@ -84213,7 +85541,7 @@ function warnAboutSkippedCategories({ permission, bashStated, authorsGroupSwitch
|
|
|
84213
85541
|
if (skipped.length === 0) return;
|
|
84214
85542
|
const names = skipped.map((category) => `'${category}'`).join(", ");
|
|
84215
85543
|
const hint = authorsGroupSwitches ? "" : ` ${GROUP_SWITCH_HINT}`;
|
|
84216
|
-
warnWithFallback(logger, bashStated ? `${TOOL_LABEL} only models shell-command permissions (${SURFACE_LABEL}); ${names} allow rules cannot be represented and were skipped.${hint}` : `${TOOL_LABEL} only models shell-command permissions (${SURFACE_LABEL}), and .rulesync/permissions.jsonc states no 'bash' category, so ${names} ${skipped.length === 1 ? "was" : "were"} skipped and the command lists were left untouched.${hint}`);
|
|
85544
|
+
warnWithFallback(logger, bashStated ? `${TOOL_LABEL$1} only models shell-command permissions (${SURFACE_LABEL}); ${names} allow rules cannot be represented and were skipped.${hint}` : `${TOOL_LABEL$1} only models shell-command permissions (${SURFACE_LABEL}), and .rulesync/permissions.jsonc states no 'bash' category, so ${names} ${skipped.length === 1 ? "was" : "were"} skipped and the command lists were left untouched.${hint}`);
|
|
84217
85545
|
}
|
|
84218
85546
|
/**
|
|
84219
85547
|
* Warn about what the `bob` override writes that Bob does not document: an
|
|
@@ -84233,7 +85561,7 @@ function warnAboutUndocumentedSettings({ override, logger }) {
|
|
|
84233
85561
|
...outsideWorkspace.length > 0 ? [`'enableOutsideWorkspace' for group(s) ${quoteAll(outsideWorkspace)}`] : []
|
|
84234
85562
|
];
|
|
84235
85563
|
if (parts.length === 0) return;
|
|
84236
|
-
warnWithFallback(logger, `${TOOL_LABEL} permissions: the bob override sets ${parts.join("; ")}, which Bob does not document; they were written as authored. Bob documents the groups ${quoteAll(BOB_PERMISSION_GROUP_IDS)}, the '${AUTO_APPROVE_KEY}' toggle(s) ${quoteAll(BOB_AUTO_APPROVE_KEYS)}, and 'enableOutsideWorkspace' for the '${OUTSIDE_WORKSPACE_GROUP_ID}' group only.`);
|
|
85564
|
+
warnWithFallback(logger, `${TOOL_LABEL$1} permissions: the bob override sets ${parts.join("; ")}, which Bob does not document; they were written as authored. Bob documents the groups ${quoteAll(BOB_PERMISSION_GROUP_IDS)}, the '${AUTO_APPROVE_KEY}' toggle(s) ${quoteAll(BOB_AUTO_APPROVE_KEYS)}, and 'enableOutsideWorkspace' for the '${OUTSIDE_WORKSPACE_GROUP_ID}' group only.`);
|
|
84237
85565
|
}
|
|
84238
85566
|
/**
|
|
84239
85567
|
* Name what the `bob` override newly auto-approves. The settings file is Bob's
|
|
@@ -84252,7 +85580,7 @@ function warnAboutNewAutoApprovals({ settings, override, filePath, logger }) {
|
|
|
84252
85580
|
...Object.entries(override?.autoApprove ?? {}).filter(([key, value]) => value === true && existingAutoApprove[key] !== true).map(([key]) => quoteValueForWarning(`${AUTO_APPROVE_KEY}.${key}`))
|
|
84253
85581
|
]);
|
|
84254
85582
|
if (added.size === 0) return;
|
|
84255
|
-
warnWithFallback(logger, `${TOOL_LABEL} permissions: the bob override now auto-approves ${[...added].join(", ")} in ${filePath}, Bob's user settings, so this applies to every project on this machine. Check it if .rulesync/permissions.jsonc arrived with a repository you cloned.`);
|
|
85583
|
+
warnWithFallback(logger, `${TOOL_LABEL$1} permissions: the bob override now auto-approves ${[...added].join(", ")} in ${filePath}, Bob's user settings, so this applies to every project on this machine. Check it if .rulesync/permissions.jsonc arrived with a repository you cloned.`);
|
|
84256
85584
|
}
|
|
84257
85585
|
/**
|
|
84258
85586
|
* Split the canonical `bash` rules — plus the restricting rules of the
|
|
@@ -84269,7 +85597,7 @@ function buildBobCommandLists({ permission, logger }) {
|
|
|
84269
85597
|
normalizePattern: widenToPrefixGlob$1
|
|
84270
85598
|
});
|
|
84271
85599
|
warnAboutUnwrittenCommandRules({
|
|
84272
|
-
toolLabel: TOOL_LABEL,
|
|
85600
|
+
toolLabel: TOOL_LABEL$1,
|
|
84273
85601
|
surfaceLabel: SURFACE_LABEL,
|
|
84274
85602
|
foreignRestrictingCategories,
|
|
84275
85603
|
shadowedAllowPatterns,
|
|
@@ -84284,7 +85612,7 @@ function buildBobCommandLists({ permission, logger }) {
|
|
|
84284
85612
|
for (const pattern of deny) lists[pattern] = "deny";
|
|
84285
85613
|
return buildVscodeCommandLists({
|
|
84286
85614
|
rules: lists,
|
|
84287
|
-
toolLabel: TOOL_LABEL,
|
|
85615
|
+
toolLabel: TOOL_LABEL$1,
|
|
84288
85616
|
logger,
|
|
84289
85617
|
prefixSemantics: "documented-prefix"
|
|
84290
85618
|
});
|
|
@@ -84456,7 +85784,7 @@ var BobPermissions = class BobPermissions extends ToolPermissions {
|
|
|
84456
85784
|
const rules = importVscodeCommandLists({
|
|
84457
85785
|
allowed: toStringArray$1(entry?.approvedCommands),
|
|
84458
85786
|
denied: toStringArray$1(entry?.deniedCommands),
|
|
84459
|
-
toolLabel: TOOL_LABEL,
|
|
85787
|
+
toolLabel: TOOL_LABEL$1,
|
|
84460
85788
|
logger,
|
|
84461
85789
|
prefixSemantics: "documented-prefix"
|
|
84462
85790
|
});
|
|
@@ -85253,6 +86581,7 @@ const CLAUDECODE_UNHONORED_KEY_SOURCES = {
|
|
|
85253
86581
|
disableMobileSimulatorTools: "managed settings",
|
|
85254
86582
|
disableRemotePreviewScripts: "managed settings",
|
|
85255
86583
|
disableSideloadFlags: "managed settings",
|
|
86584
|
+
enforceAnthropicSignIn: "managed settings",
|
|
85256
86585
|
externalEditorContext: "~/.claude.json",
|
|
85257
86586
|
forceRemoteSettingsRefresh: "managed settings",
|
|
85258
86587
|
gatewayInternalNetworks: "managed settings",
|
|
@@ -85405,12 +86734,14 @@ const CLAUDECODE_ENV_IGNORED_IN_EVERY_FILE = /* @__PURE__ */ new Set([
|
|
|
85405
86734
|
"CLAUDE_CODE_DISABLE_MOUNTED_DRIVE_RM_PROMPT",
|
|
85406
86735
|
"CLAUDE_CODE_DISABLE_POWERSHELL_CMD_RM_DENY",
|
|
85407
86736
|
"CLAUDE_CODE_DISABLE_SUBSTITUTION_RM_PROMPT",
|
|
86737
|
+
"CLAUDE_CODE_DISABLE_ULTRAREVIEW_TRUST_CHECK",
|
|
85408
86738
|
"CLAUDE_CODE_EVEN_MORE_DANGEROUSLY_SKIP_PERMISSIONS",
|
|
85409
86739
|
"CLAUDE_CODE_MESSAGING_SOCKET",
|
|
85410
86740
|
"CLAUDE_CODE_MESSAGING_TOKEN",
|
|
85411
86741
|
"CLAUDE_CODE_PROJECT_DIR_NAME",
|
|
85412
86742
|
"CLAUDE_CODE_REMOTE",
|
|
85413
86743
|
"CLAUDE_CODE_RESTRICTED",
|
|
86744
|
+
"CLAUDE_CODE_STRICT_INLINE_SHELL_RM_PROMPT",
|
|
85414
86745
|
"CLAUDE_CODE_WARN_DISK_FREE_GIB",
|
|
85415
86746
|
"CLAUDE_CODE_WARN_MEMORY_FREE_GIB"
|
|
85416
86747
|
]);
|
|
@@ -85422,6 +86753,13 @@ const CLAUDECODE_ENV_IGNORED_IN_EVERY_FILE = /* @__PURE__ */ new Set([
|
|
|
85422
86753
|
* dialog, and whether it processes attachments or expands `@` file mentions,
|
|
85423
86754
|
* and the screen reader (`CLAUDE_AX_*`) variables. Claude Code drops them there, so they are skipped at project scope and emitted only under `--global`.
|
|
85424
86755
|
*
|
|
86756
|
+
* `OTEL_RESOURCE_INCLUDE_HOST` (Claude Code v2.1.326+) adds the machine's name
|
|
86757
|
+
* and ID to telemetry, so it sits with the telemetry group. The reference lists
|
|
86758
|
+
* `CLAUDE_CODE_EXPERIMENTAL_CODE_MODE` separately: Code Mode follows it only
|
|
86759
|
+
* from the shell, user settings or a `--settings` file, and a project `0` does
|
|
86760
|
+
* not keep Code Mode off either, so any project value is skipped while user
|
|
86761
|
+
* settings (`--global`) still honor it.
|
|
86762
|
+
*
|
|
85425
86763
|
* Only the names the settings reference lists are covered; its directory,
|
|
85426
86764
|
* Windows and sign-in groups are introduced with "such as", so an unlisted member of those
|
|
85427
86765
|
* families is still written. Windows variable names are case-insensitive, so
|
|
@@ -85440,6 +86778,7 @@ const CLAUDECODE_ENV_PROJECT_IGNORED_NAMES = /* @__PURE__ */ new Set([
|
|
|
85440
86778
|
"CLAUDE_CODE_DISABLE_FILE_MENTIONS",
|
|
85441
86779
|
"CLAUDE_CODE_ENABLE_TELEMETRY",
|
|
85442
86780
|
"CLAUDE_CODE_ENHANCED_TELEMETRY_BETA",
|
|
86781
|
+
"CLAUDE_CODE_EXPERIMENTAL_CODE_MODE",
|
|
85443
86782
|
"CLAUDE_CODE_OAUTH_REFRESH_TOKEN",
|
|
85444
86783
|
"CLAUDE_CODE_OAUTH_SCOPES",
|
|
85445
86784
|
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
@@ -85458,6 +86797,7 @@ const CLAUDECODE_ENV_PROJECT_IGNORED_NAMES = /* @__PURE__ */ new Set([
|
|
|
85458
86797
|
"OTEL_EXPORTER_PROMETHEUS_PORT",
|
|
85459
86798
|
"OTEL_LOG_ASSISTANT_RESPONSES",
|
|
85460
86799
|
"OTEL_LOG_RAW_API_BODIES",
|
|
86800
|
+
"OTEL_RESOURCE_INCLUDE_HOST",
|
|
85461
86801
|
"TEMP",
|
|
85462
86802
|
"TMP",
|
|
85463
86803
|
"TMPDIR"
|
|
@@ -92969,6 +94309,263 @@ function convertFactorydroidToRulesyncPermissions({ allow, deny }) {
|
|
|
92969
94309
|
for (const pattern of deny) bash[pattern] = "deny";
|
|
92970
94310
|
return { permission: Object.keys(bash).length > 0 ? { bash } : {} };
|
|
92971
94311
|
}
|
|
94312
|
+
// src/features/permissions/gitlabduo-permissions.ts
|
|
94313
|
+
const GITLABDUO_GLOBAL_ONLY_MESSAGE = "GitLab Duo CLI reads the permissions setting only from the user settings file; use --global to sync ~/.gitlab/duo/settings.json";
|
|
94314
|
+
const TOOL_LABEL = "GitLab Duo CLI";
|
|
94315
|
+
const PERMISSIONS_KEY = "permissions";
|
|
94316
|
+
/** The Duo tool that runs a shell command; the only one rulesync writes statements for. */
|
|
94317
|
+
const COMMAND_TOOL_NAME = "run_command";
|
|
94318
|
+
/** The server refuses a pattern longer than this (`MAX_PATTERN_LENGTH`). */
|
|
94319
|
+
const MAX_PATTERN_LENGTH = 256;
|
|
94320
|
+
/**
|
|
94321
|
+
* Characters a written pattern must not hold:
|
|
94322
|
+
* - `; & | < > $ \` ( ) { }` and line breaks are shell metacharacters the
|
|
94323
|
+
* server refuses in a command-tool pattern.
|
|
94324
|
+
* - Quotes and the backslash are taken off by the shell-style word split the
|
|
94325
|
+
* server reads a pattern through, so the pattern would be matched as
|
|
94326
|
+
* something other than what it says.
|
|
94327
|
+
* - `[` and `]` start an `fnmatch` character class inside a token, which the
|
|
94328
|
+
* canonical glob does not read the same way.
|
|
94329
|
+
*/
|
|
94330
|
+
const UNSUPPORTED_PATTERN_CHARACTERS = /[;&|<>$`(){}\n\r'"\\[\]]/;
|
|
94331
|
+
/** Quotes and the backslash escape, which a shell-style word split takes off. */
|
|
94332
|
+
const SHELL_QUOTING_CHARACTERS = /['"\\]/g;
|
|
94333
|
+
/** A canonical pattern may spell "any arguments" as a trailing `:*` (`git:*`). */
|
|
94334
|
+
const TRAILING_ARGUMENT_WILDCARD = /:\*$/;
|
|
94335
|
+
/** Glob characters that make a Duo pattern match more than its literal spelling. */
|
|
94336
|
+
const GLOB_CHARACTERS = /[*?[\]]/;
|
|
94337
|
+
/**
|
|
94338
|
+
* Permissions adapter for GitLab Duo CLI.
|
|
94339
|
+
*
|
|
94340
|
+
* Duo CLI 10.5.0 reads a `permissions` array of
|
|
94341
|
+
* `{ action, resource, effect }` statements from the managed settings file and
|
|
94342
|
+
* the user's `~/.gitlab/duo/settings.json`. The project files
|
|
94343
|
+
* (`.gitlab/duo/settings.json`, `.gitlab/duo/settings.local.json`) are
|
|
94344
|
+
* deliberately not read for it, so this surface is **global only**.
|
|
94345
|
+
* @see https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/blob/v10.5.0/packages/core/settings/src/definitions.ts
|
|
94346
|
+
* @see https://gitlab.com/gitlab-org/editor-extensions/gitlab-lsp/-/blob/v10.5.0/packages/core/settings/src/tool_permissions.ts
|
|
94347
|
+
*
|
|
94348
|
+
* Only `allow` is enforced: each allow statement is submitted to the GitLab
|
|
94349
|
+
* instance as a session pattern approval when a session starts. `ask` and
|
|
94350
|
+
* `deny` statements are accepted but only logged. rulesync therefore writes
|
|
94351
|
+
* allow statements only, and never one that could auto-approve something the
|
|
94352
|
+
* canonical file restricts:
|
|
94353
|
+
*
|
|
94354
|
+
* - Only canonical `bash` `allow` rules are written, as
|
|
94355
|
+
* `{ action: "run_command", resource: <pattern>, effect: "allow" }`. Other
|
|
94356
|
+
* categories have no Duo spelling that is known to match no wider than the
|
|
94357
|
+
* canonical rule (the server matches other tools' patterns against their raw
|
|
94358
|
+
* JSON arguments), so their allow rules are skipped with a warning.
|
|
94359
|
+
* - Every `deny` and `ask` rule under `bash` or the all-tools `*` category
|
|
94360
|
+
* withholds the allow rules that could match the same command, because Duo
|
|
94361
|
+
* cannot enforce the restriction itself. A deny is also reported: the command
|
|
94362
|
+
* is asked about, not blocked.
|
|
94363
|
+
* - The GitLab server matches a command-tool pattern token by token
|
|
94364
|
+
* (`CommandPatternMatcher`): a literal token must match exactly, `*` is one
|
|
94365
|
+
* token that does not start with `-`, and a token holding a glob is matched
|
|
94366
|
+
* on its own. That is never wider than the canonical glob, where `*` spans
|
|
94367
|
+
* any characters. A trailing `:*` is written as ` *`. A pattern the server
|
|
94368
|
+
* refuses (a lone `*`, `**`, shell metacharacters, more than 256 characters)
|
|
94369
|
+
* or would read differently (quotes, escapes, character classes) is skipped
|
|
94370
|
+
* with a warning.
|
|
94371
|
+
* @see https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/ai/duo_workflows/command_pattern_matcher.rb
|
|
94372
|
+
*
|
|
94373
|
+
* On generate, the statements rulesync owns — those for `run_command` — are
|
|
94374
|
+
* replaced, and every other statement and key of the file is kept, with the
|
|
94375
|
+
* comments outside the `permissions` array (the array is rewritten whole).
|
|
94376
|
+
* On import, `run_command` statements come back under `bash`. An allow is
|
|
94377
|
+
* skipped when its resource holds a glob, which the canonical glob would read
|
|
94378
|
+
* more widely than Duo does, or when the server would refuse it, since it
|
|
94379
|
+
* approves nothing in Duo but would approve the command for other tools.
|
|
94380
|
+
*/
|
|
94381
|
+
var GitlabduoPermissions = class GitlabduoPermissions extends ToolPermissions {
|
|
94382
|
+
constructor(params) {
|
|
94383
|
+
super({
|
|
94384
|
+
...params,
|
|
94385
|
+
fileContent: params.fileContent ?? "{}"
|
|
94386
|
+
});
|
|
94387
|
+
}
|
|
94388
|
+
/**
|
|
94389
|
+
* `settings.json` holds every Duo CLI setting, so rulesync never brings it
|
|
94390
|
+
* into existence just to hold nothing.
|
|
94391
|
+
*/
|
|
94392
|
+
shouldSkipCreationWhenPayloadEmpty() {
|
|
94393
|
+
return true;
|
|
94394
|
+
}
|
|
94395
|
+
static getSettablePaths(_options = {}) {
|
|
94396
|
+
return {
|
|
94397
|
+
relativeDirPath: GITLABDUO_DIR,
|
|
94398
|
+
relativeFilePath: GITLABDUO_SETTINGS_FILE_NAME
|
|
94399
|
+
};
|
|
94400
|
+
}
|
|
94401
|
+
static async fromFile({ outputRoot = process.cwd(), validate = true, global = false }) {
|
|
94402
|
+
if (!global) throw new Error(GITLABDUO_GLOBAL_ONLY_MESSAGE);
|
|
94403
|
+
const paths = GitlabduoPermissions.getSettablePaths({ global });
|
|
94404
|
+
const fileContent = await readFileContentOrNull(join(outputRoot, paths.relativeDirPath, paths.relativeFilePath)) ?? "{}";
|
|
94405
|
+
return new GitlabduoPermissions({
|
|
94406
|
+
outputRoot,
|
|
94407
|
+
relativeDirPath: paths.relativeDirPath,
|
|
94408
|
+
relativeFilePath: paths.relativeFilePath,
|
|
94409
|
+
fileContent,
|
|
94410
|
+
validate,
|
|
94411
|
+
global: true
|
|
94412
|
+
});
|
|
94413
|
+
}
|
|
94414
|
+
static async fromRulesyncPermissions({ outputRoot = process.cwd(), rulesyncPermissions, logger, global = false }) {
|
|
94415
|
+
if (!global) throw new Error(GITLABDUO_GLOBAL_ONLY_MESSAGE);
|
|
94416
|
+
const paths = GitlabduoPermissions.getSettablePaths({ global });
|
|
94417
|
+
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
94418
|
+
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
94419
|
+
const baseContent = existingContent.trim() === "" ? "{}" : existingContent;
|
|
94420
|
+
const existing = parseSettings({
|
|
94421
|
+
content: baseContent,
|
|
94422
|
+
filePath
|
|
94423
|
+
})[PERMISSIONS_KEY];
|
|
94424
|
+
const generated = convertRulesyncToGitlabduoStatements({
|
|
94425
|
+
config: rulesyncPermissions.getJson(),
|
|
94426
|
+
logger
|
|
94427
|
+
});
|
|
94428
|
+
let fileContent = baseContent;
|
|
94429
|
+
if (existing !== void 0 && !Array.isArray(existing)) warnWithFallback(logger, `${TOOL_LABEL}: '${PERMISSIONS_KEY}' in ${filePath} is not an array, so it was left untouched rather than overwritten, and no rule was written.`);
|
|
94430
|
+
else {
|
|
94431
|
+
const statements = [...(existing ?? []).filter((statement) => !(isPlainObject(statement) && statement.action === COMMAND_TOOL_NAME)), ...generated];
|
|
94432
|
+
if (statements.length > 0 || existing !== void 0) {
|
|
94433
|
+
const edits = modify(baseContent, [PERMISSIONS_KEY], statements.length > 0 ? statements : void 0, { formattingOptions: {
|
|
94434
|
+
insertSpaces: true,
|
|
94435
|
+
tabSize: 2
|
|
94436
|
+
} });
|
|
94437
|
+
fileContent = applyEdits(baseContent, edits);
|
|
94438
|
+
}
|
|
94439
|
+
}
|
|
94440
|
+
return new GitlabduoPermissions({
|
|
94441
|
+
outputRoot,
|
|
94442
|
+
relativeDirPath: paths.relativeDirPath,
|
|
94443
|
+
relativeFilePath: paths.relativeFilePath,
|
|
94444
|
+
fileContent,
|
|
94445
|
+
validate: true,
|
|
94446
|
+
global: true
|
|
94447
|
+
});
|
|
94448
|
+
}
|
|
94449
|
+
toRulesyncPermissions() {
|
|
94450
|
+
const selfPath = join(this.getRelativeDirPath(), this.getRelativeFilePath());
|
|
94451
|
+
const raw = parseSettings({
|
|
94452
|
+
content: this.getFileContent() || "{}",
|
|
94453
|
+
filePath: selfPath
|
|
94454
|
+
})[PERMISSIONS_KEY];
|
|
94455
|
+
const statements = Array.isArray(raw) ? raw : [];
|
|
94456
|
+
if (raw !== void 0 && !Array.isArray(raw)) warnWithFallback(void 0, `${TOOL_LABEL} ignores '${PERMISSIONS_KEY}' unless it is an array, so nothing was imported from ${selfPath}.`);
|
|
94457
|
+
const bash = {};
|
|
94458
|
+
const skippedAllows = [];
|
|
94459
|
+
for (const statement of statements) {
|
|
94460
|
+
if (!isDuoPermissionStatement(statement) || statement.action !== COMMAND_TOOL_NAME) continue;
|
|
94461
|
+
const { resource, effect } = statement;
|
|
94462
|
+
if (effect === "allow" && (GLOB_CHARACTERS.test(resource) || toGitlabduoCommandResource(resource) !== resource)) {
|
|
94463
|
+
skippedAllows.push(resource);
|
|
94464
|
+
continue;
|
|
94465
|
+
}
|
|
94466
|
+
const previous = bash[resource];
|
|
94467
|
+
if (previous === void 0 || rank(effect) > rank(previous)) bash[resource] = effect;
|
|
94468
|
+
}
|
|
94469
|
+
if (skippedAllows.length > 0) warnWithFallback(void 0, `The run_command allow statement(s) for ${uniq(skippedAllows).join(", ")} in ${selfPath} were not imported: a glob matches more as a canonical pattern than in ${TOOL_LABEL} (where '*' is one argument that is not a flag), and a pattern the GitLab server refuses approves nothing in Duo but would for other tools.`);
|
|
94470
|
+
const config = { permission: Object.keys(bash).length > 0 ? { [SHELL_PERMISSION_CATEGORY]: bash } : {} };
|
|
94471
|
+
return RulesyncPermissions.fromImportedFileContent({
|
|
94472
|
+
outputRoot: this.outputRoot,
|
|
94473
|
+
sourcePath: this.getRelativePathFromCwd(),
|
|
94474
|
+
fileContent: JSON.stringify(config, null, 2)
|
|
94475
|
+
});
|
|
94476
|
+
}
|
|
94477
|
+
};
|
|
94478
|
+
function rank(effect) {
|
|
94479
|
+
return effect === "deny" ? 2 : effect === "ask" ? 1 : 0;
|
|
94480
|
+
}
|
|
94481
|
+
function isDuoPermissionStatement(value) {
|
|
94482
|
+
return isPlainObject(value) && typeof value.action === "string" && value.action.length > 0 && typeof value.resource === "string" && (value.effect === "allow" || value.effect === "ask" || value.effect === "deny");
|
|
94483
|
+
}
|
|
94484
|
+
function parseSettings({ content, filePath }) {
|
|
94485
|
+
let parsed;
|
|
94486
|
+
try {
|
|
94487
|
+
parsed = parseJsonc(content);
|
|
94488
|
+
} catch (error) {
|
|
94489
|
+
throw new Error(`Failed to parse GitLab Duo CLI settings at ${filePath}: ${formatError(error)}`, { cause: error });
|
|
94490
|
+
}
|
|
94491
|
+
if (!isPlainObject(parsed)) throw new Error(`GitLab Duo CLI settings at ${filePath} must contain a JSON object.`);
|
|
94492
|
+
return parsed;
|
|
94493
|
+
}
|
|
94494
|
+
/**
|
|
94495
|
+
* A canonical command pattern as Duo's token matcher reads it: trimmed, runs
|
|
94496
|
+
* of whitespace collapsed to one space (Duo splits a command into words, so
|
|
94497
|
+
* `git push` and `git push` are one command), and a trailing `:*` ("any
|
|
94498
|
+
* arguments") spelled ` *`.
|
|
94499
|
+
*/
|
|
94500
|
+
function normalizeGitlabduoCommandPattern(pattern) {
|
|
94501
|
+
let normalized = pattern.trim();
|
|
94502
|
+
if (TRAILING_ARGUMENT_WILDCARD.test(normalized)) normalized = `${normalized.slice(0, -2)} *`;
|
|
94503
|
+
return normalized.trim().split(/\s+/).join(" ");
|
|
94504
|
+
}
|
|
94505
|
+
/**
|
|
94506
|
+
* The Duo `resource` for a canonical `bash` allow pattern, or `null` when the
|
|
94507
|
+
* server would refuse it or read it differently from what it says. The result
|
|
94508
|
+
* never matches a command the canonical pattern does not match.
|
|
94509
|
+
*/
|
|
94510
|
+
function toGitlabduoCommandResource(pattern) {
|
|
94511
|
+
const resource = normalizeGitlabduoCommandPattern(pattern);
|
|
94512
|
+
if (resource === "" || resource === "*" || resource.length > MAX_PATTERN_LENGTH) return null;
|
|
94513
|
+
if (UNSUPPORTED_PATTERN_CHARACTERS.test(resource)) return null;
|
|
94514
|
+
if (resource.includes("**")) return null;
|
|
94515
|
+
return resource;
|
|
94516
|
+
}
|
|
94517
|
+
/**
|
|
94518
|
+
* Convert the canonical config into the `run_command` allow statements Duo CLI
|
|
94519
|
+
* enforces, reporting every rule that could not be carried.
|
|
94520
|
+
*/
|
|
94521
|
+
function convertRulesyncToGitlabduoStatements({ config, logger }) {
|
|
94522
|
+
const { rules, foreignRestrictingCategories, ignoredAllToolsAllowPatterns } = collectShellCommandRules(config.permission);
|
|
94523
|
+
const restrictions = uniq(rules.filter(({ action }) => action !== "allow").flatMap(({ pattern }) => [
|
|
94524
|
+
pattern,
|
|
94525
|
+
normalizeGitlabduoCommandPattern(pattern),
|
|
94526
|
+
normalizeGitlabduoCommandPattern(pattern.replaceAll(SHELL_QUOTING_CHARACTERS, ""))
|
|
94527
|
+
]).filter((pattern) => pattern !== "")).map((pattern) => ({
|
|
94528
|
+
pattern,
|
|
94529
|
+
fromAllToolsCategory: false
|
|
94530
|
+
}));
|
|
94531
|
+
const budget = createIntersectionBudget();
|
|
94532
|
+
const shadowingRestrictions = createShadowingRestrictionsTest(restrictions, { budget });
|
|
94533
|
+
const resources = [];
|
|
94534
|
+
const shadowedAllowPatterns = [];
|
|
94535
|
+
const unsupportedPatterns = [];
|
|
94536
|
+
for (const { pattern, action } of rules) {
|
|
94537
|
+
if (action !== "allow") continue;
|
|
94538
|
+
const resource = toGitlabduoCommandResource(pattern);
|
|
94539
|
+
if (resource === null) {
|
|
94540
|
+
unsupportedPatterns.push(pattern);
|
|
94541
|
+
continue;
|
|
94542
|
+
}
|
|
94543
|
+
if (shadowingRestrictions(resource).length > 0) {
|
|
94544
|
+
shadowedAllowPatterns.push(pattern);
|
|
94545
|
+
continue;
|
|
94546
|
+
}
|
|
94547
|
+
resources.push(resource);
|
|
94548
|
+
}
|
|
94549
|
+
warnAboutUnwrittenCommandRules({
|
|
94550
|
+
toolLabel: TOOL_LABEL,
|
|
94551
|
+
surfaceLabel: `${PERMISSIONS_KEY} statements for ${COMMAND_TOOL_NAME}`,
|
|
94552
|
+
foreignRestrictingCategories,
|
|
94553
|
+
shadowedAllowPatterns: uniq(shadowedAllowPatterns),
|
|
94554
|
+
ignoredAllToolsAllowPatterns,
|
|
94555
|
+
intersectionBudgetExhausted: budget.remaining === 0,
|
|
94556
|
+
logger
|
|
94557
|
+
});
|
|
94558
|
+
const denyPatterns = uniq(rules.filter(({ action }) => action === "deny").map(({ pattern }) => pattern));
|
|
94559
|
+
if (denyPatterns.length > 0) warnWithFallback(logger, `${TOOL_LABEL} enforces only allow statements in '${PERMISSIONS_KEY}' (ask and deny are logged and ignored), so the deny rule(s) for ${denyPatterns.join(", ")} were not written. Those commands are asked about rather than blocked.`);
|
|
94560
|
+
const foreignAllowCategories = Object.entries(config.permission).filter(([category, categoryRules]) => category !== "bash" && category !== "*" && Object.values(categoryRules).includes("allow")).map(([category]) => category);
|
|
94561
|
+
if (foreignAllowCategories.length > 0) warnWithFallback(logger, `${TOOL_LABEL}: only 'bash' allow rules are written (as ${COMMAND_TOOL_NAME} statements), so the allow rules of '${foreignAllowCategories.join("', '")}' were skipped.`);
|
|
94562
|
+
if (unsupportedPatterns.length > 0) warnWithFallback(logger, `${TOOL_LABEL} refuses a ${COMMAND_TOOL_NAME} pattern that is a lone '*', holds '**' or a shell metacharacter, or is longer than ${MAX_PATTERN_LENGTH} characters, and reads quotes, escapes and '[...]' differently from the canonical glob, so the allow rule(s) for ${uniq(unsupportedPatterns).join(", ")} were skipped.`);
|
|
94563
|
+
return uniq(resources).map((resource) => ({
|
|
94564
|
+
action: COMMAND_TOOL_NAME,
|
|
94565
|
+
resource,
|
|
94566
|
+
effect: "allow"
|
|
94567
|
+
}));
|
|
94568
|
+
}
|
|
92972
94569
|
// src/features/permissions/goose-permissions.ts
|
|
92973
94570
|
const GOOSE_GLOBAL_ONLY_MESSAGE = "Goose permissions are global-only; use --global to sync ~/.config/goose/permission.yaml";
|
|
92974
94571
|
const GOOSE_USER_KEY = "user";
|
|
@@ -105287,6 +106884,13 @@ const toolPermissionsFactories = /* @__PURE__ */ new Map([
|
|
|
105287
106884
|
supportsGlobal: true
|
|
105288
106885
|
}
|
|
105289
106886
|
}],
|
|
106887
|
+
["gitlabduo", {
|
|
106888
|
+
class: GitlabduoPermissions,
|
|
106889
|
+
meta: {
|
|
106890
|
+
supportsProject: false,
|
|
106891
|
+
supportsGlobal: true
|
|
106892
|
+
}
|
|
106893
|
+
}],
|
|
105290
106894
|
["goose", {
|
|
105291
106895
|
class: GoosePermissions,
|
|
105292
106896
|
meta: {
|
|
@@ -108195,4 +109799,4 @@ const CHECKS_IMPORT_STRATEGY = {
|
|
|
108195
109799
|
};
|
|
108196
109800
|
export { RulesyncSkillFrontmatterSchema as $, RULESYNC_RULES_RELATIVE_DIR_PATH as $n, getFileSizeAndExecutableBit as $t, CODEBUDDY_LOCAL_RULE_FILE_NAME as A, ToolTargetSchema as An, fallbackLogger as At, CLAUDECODE_DIR as B, RULESYNC_CONFIG_RELATIVE_FILE_PATH as Bn, assertDirectoryIfExists as Bt, LETTACODE_DIR as C, toPosixPath as Cn, SourceEntrySchema as Ct, COMMANDCODE_DIR as D, ALL_TOOL_TARGETS as Dn, ConsoleLogger as Dt, FACTORYDROID_SETTINGS_LOCAL_FILE_NAME as E, mapWithConcurrency as En, findControlCharacter as Et, sweepRefusalReason as F, FEATURE_SOURCE_TREE_ENTRIES as Fn, CLIError as Ft, findProjectInstructionBudgetFindings as G, RULESYNC_IGNORE_RELATIVE_FILE_PATH as Gn, assertWritablePathInsideRoot as Gt, CLAUDECODE_MEMORIES_DIR_NAME as H, RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH as Hn, assertNoSymlinkBelowRoot as Ht, loadYaml as I, MAX_FILE_SIZE as In, ErrorCodes as It, hasWindowsFoldableName as J, RULESYNC_MCP_SCHEMA_URL as Jn, directoryExists as Jt, toInstructionBudgetFile as K, RULESYNC_LOCAL_CONFIG_RELATIVE_FILE_PATH as Kn, checkPathTraversal as Kt, CODEXCLI_BASH_RULES_FILE_NAME as L, RULESYNC_AIIGNORE_RELATIVE_FILE_PATH as Ln, parseJsonc as Lt, AUGMENTCODE_SETTINGS_LOCAL_FILE_NAME as M, ALL_FEATURES_WITH_WILDCARD as Mn, withFallbackLoggerTarget as Mt, caseFoldIdentity as N, DEPRECATED_FEATURE_REPLACEMENTS as Nn, resetRunWarningState as Nt, COMMANDCODE_SETTINGS_LOCAL_FILE_NAME as O, ALL_TOOL_TARGETS_WITH_WILDCARD as On, JsonLogger as Ot, groupSpellingsByCaseFoldedIdentity as P, CURATED_RULES_FEATURE_SUBDIR as Pn, withWarnOnceScope as Pt, RulesyncSkill as Q, RULESYNC_RELATIVE_DIR_PATH as Qn, findFilesByGlobs as Qt, CODEXCLI_DIR as R, RULESYNC_CHECKS_RELATIVE_DIR_PATH as Rn, PathOutsideRootError as Rt, QWENCODE_LOCAL_RULE_FILE_NAME as S, splitPathSegments as Sn, GITIGNORE_DESTINATION_KEY as St, FACTORYDROID_DIR as T, writeFileContent as Tn, getSourceTransport as Tt, CLAUDECODE_SETTINGS_LOCAL_FILE_NAME as U, RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH as Un, assertPathResolvesInsideRoot as Ut, CLAUDECODE_LOCAL_RULE_FILE_NAME as V, RULESYNC_CONFIG_SCHEMA_URL as Vn, assertLandingOutsideVcsMetadata as Vt, CLAUDECODE_SKILLS_DIR_PATH as W, RULESYNC_HOOKS_RELATIVE_FILE_PATH as Wn, assertTreeContainsNoSymlinks as Wt, RulesyncSubagent as X, RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH as Xn, fileExists as Xt, getLocalSkillDirNames as Y, RULESYNC_NPM_SOURCES_LOCK_RELATIVE_FILE_PATH as Yn, ensureDir as Yt, RulesyncSubagentFrontmatterSchema as Z, RULESYNC_PERMISSIONS_SCHEMA_URL as Zn, fileExistsStrict as Zt, SkillsProcessor as _, removeFileWithoutFollowingSymlinks as _n, mergeInputRootConfigs as _t, convertFromTool as a, listDirectoryEntryNames as an, formatMegabytes as ar, RulesyncHooks as at, REASONIX_LOCAL_RULE_FILE_NAME as b, resolvedRelativePath as bn, CONFLICTING_TARGET_PAIRS as bt, ELLIPSIS_WIDTH as c, normalizePosixDirPath as cn, hasEnclosingMarkOutsideKeycap as cr, RulesyncCommand as ct, McpProcessor as d, readFileContent as dn, stripControlCharactersKeepingLineFeeds as dr, RulesyncCheckFrontmatterSchema as dt, getHomeDirectory as en, RULESYNC_SKILLS_RELATIVE_DIR_PATH as er, RulesyncRule as et, IgnoreProcessor as f, readFileContentOrNull as fn, stripControlCharactersKeepingLineFeedsAndTabs as fr, stringifyFrontmatter as ft, SubagentsProcessor as g, removeFileStrict as gn, ConfigResolver as gt, RulesProcessor as h, removeFile as hn, SKILL_FILE_NAME as ht, inspectInputRoots as i, isSymlink as in, RULESYNC_XDG_CONFIG_HOME_DEFAULT_DIR_NAME as ir, RulesyncIgnore as it, AUGMENTCODE_DIR as j, ALL_FEATURES as jn, warnOnConflictingFlags as jt, CODEBUDDY_DIR as k, PACKAGING_TOOL_TARGETS as kn, WarningCollectingLogger as kt, displayWidthOf as l, pathEscapesRoot as ln, quoteForLog as lr, RulesyncCommandFrontmatterSchema as lt, ChecksProcessor as m, removeDirectoryStrict as mn, SHARED_USER_MANAGED_CONFIG_PATHS as mt, formatSourceLoadFailure as n, isFileSystemError as nn, RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH as nr, RulesyncPermissions as nt, getProcessorRegistryEntry as o, listFilePathsRecursively as on, formatError as or, getRulesyncSourceCandidates as ot, HooksProcessor as p, removeDirectory as pn, stripHiddenCharacters as pr, isRecord as pt, classifyRemoteName as q, RULESYNC_MCP_RELATIVE_FILE_PATH as qn, createTempDirectory as qt, generate as r, isRootDirPath as rn, RULESYNC_USER_CONFIG_DIR_NAME as rr, RulesyncMcp as rt, parseCommaSeparatedList as s, listSubdirectoryNames as sn, truncateText as sr, resolveRulesyncSourceWritePath as st, importFromTool as t, isFileNotFoundError as tn, RULESYNC_SOURCES_LOCK_RELATIVE_FILE_PATH as tr, RulesyncRuleFrontmatterSchema as tt, shortenToWidth as u, posixRelativePathEscapesRoot as un, stripControlCharacters as ur, RulesyncCheck as ut, CRUSH_LOCAL_RULE_FILE_NAME as v, removeTempDirectory as vn, parseConfigFileContent as vt, LETTACODE_SETTINGS_LOCAL_FILE_NAME as w, writeFileBuffer as wn, assertTargetsFeaturesExclusive as wt, QWENCODE_DIR as x, runWithDirectoryRollback as xn, ConfigFileSchema as xt, CommandsProcessor as y, resolvePath as yn, resolveEffectiveInputRoots as yt, CLAUDECODE_AGENT_MEMORY_LOCAL_DIR_NAME as z, RULESYNC_COMMANDS_RELATIVE_DIR_PATH as zn, applyFileMode as zt };
|
|
108197
109801
|
|
|
108198
|
-
//# sourceMappingURL=import-
|
|
109802
|
+
//# sourceMappingURL=import-Ch9kXISC.js.map
|