rulesync 43.9.2 → 43.10.1
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 +1 -1
- package/dist/cli/index.cjs +13 -8
- package/dist/cli/index.js +13 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-BYa6wJXz.cjs → import-DT6BSklJ.cjs} +1463 -328
- package/dist/{import-C8KKmzZS.js → import-fiaj0fDK.js} +1447 -312
- package/dist/{import-C8KKmzZS.js.map → import-fiaj0fDK.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -382,36 +382,36 @@ function formatError(error) {
|
|
|
382
382
|
return boundErrorMessage(String(error));
|
|
383
383
|
}
|
|
384
384
|
// src/constants/rulesync-paths.ts
|
|
385
|
-
const { join: join$
|
|
385
|
+
const { join: join$358 } = node_path.posix;
|
|
386
386
|
const RULESYNC_CONFIG_RELATIVE_FILE_PATH = "rulesync.jsonc";
|
|
387
387
|
const RULESYNC_LOCAL_CONFIG_RELATIVE_FILE_PATH = "rulesync.local.jsonc";
|
|
388
388
|
const RULESYNC_USER_CONFIG_DIR_NAME = "rulesync";
|
|
389
389
|
const RULESYNC_XDG_CONFIG_HOME_DEFAULT_DIR_NAME = ".config";
|
|
390
390
|
const RULESYNC_RELATIVE_DIR_PATH = ".rulesync";
|
|
391
391
|
const RULES_FEATURE_SUBDIR = "rules";
|
|
392
|
-
const CURATED_RULES_FEATURE_SUBDIR = join$
|
|
392
|
+
const CURATED_RULES_FEATURE_SUBDIR = join$358(RULES_FEATURE_SUBDIR, ".curated");
|
|
393
393
|
const COMMANDS_FEATURE_SUBDIR = "commands";
|
|
394
394
|
const SUBAGENTS_FEATURE_SUBDIR = "subagents";
|
|
395
395
|
const CHECKS_FEATURE_SUBDIR = "checks";
|
|
396
396
|
const SKILLS_FEATURE_SUBDIR = "skills";
|
|
397
|
-
const CURATED_SKILLS_FEATURE_SUBDIR = join$
|
|
398
|
-
const RULESYNC_RULES_RELATIVE_DIR_PATH = join$
|
|
399
|
-
const RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH = join$
|
|
400
|
-
const RULESYNC_COMMANDS_RELATIVE_DIR_PATH = join$
|
|
401
|
-
const RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH = join$
|
|
402
|
-
const RULESYNC_CHECKS_RELATIVE_DIR_PATH = join$
|
|
403
|
-
const RULESYNC_MCP_RELATIVE_FILE_PATH = join$
|
|
404
|
-
const RULESYNC_HOOKS_RELATIVE_FILE_PATH = join$
|
|
405
|
-
const RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH = join$
|
|
406
|
-
join$
|
|
407
|
-
const RULESYNC_HOOKS_LEGACY_RELATIVE_FILE_PATH = join$
|
|
408
|
-
const RULESYNC_PERMISSIONS_LEGACY_RELATIVE_FILE_PATH = join$
|
|
397
|
+
const CURATED_SKILLS_FEATURE_SUBDIR = join$358(SKILLS_FEATURE_SUBDIR, ".curated");
|
|
398
|
+
const RULESYNC_RULES_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, RULES_FEATURE_SUBDIR);
|
|
399
|
+
const RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, CURATED_RULES_FEATURE_SUBDIR);
|
|
400
|
+
const RULESYNC_COMMANDS_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, COMMANDS_FEATURE_SUBDIR);
|
|
401
|
+
const RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, SUBAGENTS_FEATURE_SUBDIR);
|
|
402
|
+
const RULESYNC_CHECKS_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, CHECKS_FEATURE_SUBDIR);
|
|
403
|
+
const RULESYNC_MCP_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, "mcp.jsonc");
|
|
404
|
+
const RULESYNC_HOOKS_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, "hooks.jsonc");
|
|
405
|
+
const RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, "permissions.jsonc");
|
|
406
|
+
join$358(RULESYNC_RELATIVE_DIR_PATH, "mcp.json");
|
|
407
|
+
const RULESYNC_HOOKS_LEGACY_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, "hooks.json");
|
|
408
|
+
const RULESYNC_PERMISSIONS_LEGACY_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, "permissions.json");
|
|
409
409
|
const RULESYNC_AIIGNORE_FILE_NAME = ".aiignore";
|
|
410
|
-
const RULESYNC_AIIGNORE_RELATIVE_FILE_PATH = join$
|
|
410
|
+
const RULESYNC_AIIGNORE_RELATIVE_FILE_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, ".aiignore");
|
|
411
411
|
const RULESYNC_IGNORE_RELATIVE_FILE_PATH = ".rulesyncignore";
|
|
412
412
|
const RULESYNC_OVERVIEW_FILE_NAME = "overview.md";
|
|
413
|
-
const RULESYNC_SKILLS_RELATIVE_DIR_PATH = join$
|
|
414
|
-
const RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH = join$
|
|
413
|
+
const RULESYNC_SKILLS_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, SKILLS_FEATURE_SUBDIR);
|
|
414
|
+
const RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH = join$358(RULESYNC_RELATIVE_DIR_PATH, CURATED_SKILLS_FEATURE_SUBDIR);
|
|
415
415
|
const RULESYNC_SOURCES_LOCK_RELATIVE_FILE_PATH = "rulesync.lock";
|
|
416
416
|
const RULESYNC_NPM_SOURCES_LOCK_RELATIVE_FILE_PATH = "rulesync-npm.lock.json";
|
|
417
417
|
const RULESYNC_MCP_FILE_NAME = "mcp.jsonc";
|
|
@@ -849,7 +849,8 @@ const skillsProcessorToolTargetTuple = [
|
|
|
849
849
|
"zed",
|
|
850
850
|
"zoocode",
|
|
851
851
|
"dsh",
|
|
852
|
-
"lettacode"
|
|
852
|
+
"lettacode",
|
|
853
|
+
"openclaw"
|
|
853
854
|
];
|
|
854
855
|
const hooksProcessorToolTargetTuple = [
|
|
855
856
|
"amp",
|
|
@@ -5205,7 +5206,8 @@ const HookDefinitionSchema = zod_mini.z.looseObject({
|
|
|
5205
5206
|
asyncRewake: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
5206
5207
|
rewakeMessage: zod_mini.z.optional(safeString),
|
|
5207
5208
|
rewakeSummary: zod_mini.z.optional(safeString),
|
|
5208
|
-
continueOnBlock: zod_mini.z.optional(zod_mini.z.boolean())
|
|
5209
|
+
continueOnBlock: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
5210
|
+
strictJsonOutput: zod_mini.z.optional(zod_mini.z.boolean())
|
|
5209
5211
|
});
|
|
5210
5212
|
/**
|
|
5211
5213
|
* All canonical hook event names.
|
|
@@ -6846,41 +6848,55 @@ const JUNIE_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_JUNIE_EVENT_NAM
|
|
|
6846
6848
|
/**
|
|
6847
6849
|
* Map canonical camelCase event names to Mistral Vibe snake_case.
|
|
6848
6850
|
*
|
|
6849
|
-
*
|
|
6850
|
-
*
|
|
6851
|
-
*
|
|
6852
|
-
*
|
|
6851
|
+
* The canonical `stop` and `subagentStop` events both map to Vibe's
|
|
6852
|
+
* `post_agent` (fires after every assistant turn ending without pending tool
|
|
6853
|
+
* calls); the adapter tells them apart with the hook's `match` on the agent
|
|
6854
|
+
* name (`main` for the main agent). v3.1.1 added `pre_agent`, `notification`,
|
|
6855
|
+
* `session_start` and `session_end`, and v3.1.3 added `pre_llm` and
|
|
6856
|
+
* `post_llm`.
|
|
6853
6857
|
*
|
|
6854
|
-
* These are the v2.21.0 names; the pre-2.21.0 spellings (`before_tool`,
|
|
6858
|
+
* These are the v2.21.0+ names; the pre-2.21.0 spellings (`before_tool`,
|
|
6855
6859
|
* `after_tool`, `post_agent_turn`) are rejected by Vibe's strict `HookType`
|
|
6856
6860
|
* enum.
|
|
6857
|
-
* @see https://github.com/mistralai/mistral-vibe/blob/
|
|
6861
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/core/hooks/models.py
|
|
6858
6862
|
*/
|
|
6859
6863
|
const CANONICAL_TO_VIBE_EVENT_NAMES = {
|
|
6860
6864
|
preToolUse: "pre_tool",
|
|
6861
6865
|
postToolUse: "post_tool",
|
|
6862
6866
|
stop: "post_agent",
|
|
6863
|
-
subagentStop: "post_agent"
|
|
6867
|
+
subagentStop: "post_agent",
|
|
6868
|
+
beforeSubmitPrompt: "pre_agent",
|
|
6869
|
+
notification: "notification",
|
|
6870
|
+
sessionStart: "session_start",
|
|
6871
|
+
sessionEnd: "session_end",
|
|
6872
|
+
preModelInvocation: "pre_llm",
|
|
6873
|
+
postModelInvocation: "post_llm"
|
|
6864
6874
|
};
|
|
6865
6875
|
/**
|
|
6866
6876
|
* Hook events supported by Mistral Vibe (mistral-vibe).
|
|
6867
6877
|
*
|
|
6868
|
-
* Vibe
|
|
6869
|
-
* `
|
|
6870
|
-
* `
|
|
6871
|
-
*
|
|
6872
|
-
*
|
|
6873
|
-
*
|
|
6874
|
-
*
|
|
6875
|
-
*
|
|
6876
|
-
* `
|
|
6877
|
-
*
|
|
6878
|
-
*
|
|
6879
|
-
*
|
|
6880
|
-
*
|
|
6881
|
-
* `
|
|
6882
|
-
*
|
|
6883
|
-
*
|
|
6878
|
+
* Vibe reads hooks from `.vibe/hooks.toml`: `pre_tool` ← `preToolUse`,
|
|
6879
|
+
* `post_tool` ← `postToolUse`, `post_agent` ← `stop` / `subagentStop`,
|
|
6880
|
+
* `pre_agent` ← `beforeSubmitPrompt`, `notification` ← `notification`,
|
|
6881
|
+
* `session_start` ← `sessionStart`, `session_end` ← `sessionEnd`, `pre_llm` ←
|
|
6882
|
+
* `preModelInvocation` and `post_llm` ← `postModelInvocation`.
|
|
6883
|
+
*
|
|
6884
|
+
* `post_agent`, `pre_agent`, `pre_llm` and `post_llm` take a `match` on the
|
|
6885
|
+
* agent whose turn it is: the reserved alias `main` selects the main agent, so
|
|
6886
|
+
* canonical `stop` and `beforeSubmitPrompt` are written with `match = "main"`.
|
|
6887
|
+
* `session_start` matches the source (`startup` / `resume` / `clear` /
|
|
6888
|
+
* `fork`), `session_end` the reason (`exit` / `clear` / `other`) and
|
|
6889
|
+
* `notification` the notification type (`approval_requested` /
|
|
6890
|
+
* `question_asked` / `turn_completed` / `turn_failed`). The `strict` flag is
|
|
6891
|
+
* valid on `pre_tool`, `post_tool`, `pre_agent`, `pre_llm` and `post_llm`
|
|
6892
|
+
* (`STRICT_HOOK_TYPES`). Only `type: "command"` hooks are relevant.
|
|
6893
|
+
*
|
|
6894
|
+
* v2.21.0 graduated hooks from experimental and renamed all three original
|
|
6895
|
+
* types (`before_tool` → `pre_tool`, `after_tool` → `post_tool`,
|
|
6896
|
+
* `post_agent_turn` → `post_agent`). `HookType` is a strict enum, so an entry
|
|
6897
|
+
* using an old name is rejected outright and reported as a `HookConfigIssue`.
|
|
6898
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/core/hooks/models.py
|
|
6899
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/plugins/builtins/vibe/skills/vibe/SKILL.md
|
|
6884
6900
|
*/
|
|
6885
6901
|
const VIBE_HOOK_EVENTS = eventsOf(CANONICAL_TO_VIBE_EVENT_NAMES);
|
|
6886
6902
|
/**
|
|
@@ -8450,6 +8466,31 @@ const ClaudecodePermissionsOverrideSchema = zod_mini.z.looseObject({
|
|
|
8450
8466
|
sandbox: zod_mini.z.optional(zod_mini.z.looseObject({}))
|
|
8451
8467
|
});
|
|
8452
8468
|
/**
|
|
8469
|
+
* Tool-scoped override block for Command Code. The `permissions` object of
|
|
8470
|
+
* `.commandcode/settings.json` carries three documented non-list fields with
|
|
8471
|
+
* no canonical permission category: `defaultMode` (the session-start mode:
|
|
8472
|
+
* `default`, `accept-edits`, `plan`, `yolo` or `dont-ask`, plus the aliases
|
|
8473
|
+
* Command Code accepts such as `bypassPermissions` or `acceptEdits`),
|
|
8474
|
+
* `additionalDirectories` (extra directories treated as inside the workspace)
|
|
8475
|
+
* and `disableBypass` (`"disable"` or `true` makes `yolo` impossible to enter). Only
|
|
8476
|
+
* these three are written; the managed `allow`/`ask`/`deny` lists stay driven
|
|
8477
|
+
* by the shared `permission` block, and any other key placed here is ignored
|
|
8478
|
+
* with a warning. Values that widen trust are written with a warning.
|
|
8479
|
+
*
|
|
8480
|
+
* @example
|
|
8481
|
+
* { "permissions": { "defaultMode": "plan", "disableBypass": true } }
|
|
8482
|
+
* @see https://commandcode.ai/docs/permissions
|
|
8483
|
+
*/
|
|
8484
|
+
const CommandcodePermissionsFieldsSchema = zod_mini.z.looseObject({
|
|
8485
|
+
defaultMode: zod_mini.z.optional(zod_mini.z.string()),
|
|
8486
|
+
additionalDirectories: zod_mini.z.optional(zod_mini.z.array(zod_mini.z.string())),
|
|
8487
|
+
disableBypass: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.literal("disable"), zod_mini.z.boolean()]))
|
|
8488
|
+
});
|
|
8489
|
+
const CommandcodePermissionsOverrideSchema = zod_mini.z.looseObject({
|
|
8490
|
+
permission: zod_mini.z.optional(ToolScopedPermissionSchema),
|
|
8491
|
+
permissions: zod_mini.z.optional(CommandcodePermissionsFieldsSchema)
|
|
8492
|
+
});
|
|
8493
|
+
/**
|
|
8453
8494
|
* Tool-scoped override block for Mistral Vibe. Vibe's per-tool `BaseToolConfig`
|
|
8454
8495
|
* carries a `sensitive_patterns` list — patterns that escalate to ASK even when
|
|
8455
8496
|
* the tool's base permission is ALWAYS (allow). The canonical model can only set
|
|
@@ -9725,7 +9766,7 @@ const PermissionsConfigSchema = zod_mini.z.looseObject({
|
|
|
9725
9766
|
continue: zod_mini.z.optional(CanonicalPermissionsOverrideSchema),
|
|
9726
9767
|
copilot: zod_mini.z.optional(CopilotPermissionsOverrideSchema),
|
|
9727
9768
|
codebuddy: zod_mini.z.optional(CodebuddyPermissionsOverrideSchema),
|
|
9728
|
-
commandcode: zod_mini.z.optional(
|
|
9769
|
+
commandcode: zod_mini.z.optional(CommandcodePermissionsOverrideSchema),
|
|
9729
9770
|
lettacode: zod_mini.z.optional(CanonicalPermissionsOverrideSchema),
|
|
9730
9771
|
crush: zod_mini.z.optional(CanonicalPermissionsOverrideSchema),
|
|
9731
9772
|
goose: zod_mini.z.optional(CanonicalPermissionsOverrideSchema),
|
|
@@ -11566,6 +11607,15 @@ const RulesyncSkillFrontmatterSchema = zod_mini.z.looseObject({
|
|
|
11566
11607
|
"disable-model-invocation": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
11567
11608
|
"user-invocable": zod_mini.z.optional(zod_mini.z.boolean())
|
|
11568
11609
|
})),
|
|
11610
|
+
openclaw: zod_mini.z.optional(zod_mini.z.looseObject({
|
|
11611
|
+
homepage: zod_mini.z.optional(zod_mini.z.string()),
|
|
11612
|
+
"user-invocable": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
11613
|
+
"disable-model-invocation": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
11614
|
+
"command-dispatch": zod_mini.z.optional(zod_mini.z.string()),
|
|
11615
|
+
"command-tool": zod_mini.z.optional(zod_mini.z.string()),
|
|
11616
|
+
"command-arg-mode": zod_mini.z.optional(zod_mini.z.string()),
|
|
11617
|
+
metadata: zod_mini.z.optional(zod_mini.z.looseObject({}))
|
|
11618
|
+
})),
|
|
11569
11619
|
reasonix: zod_mini.z.optional(zod_mini.z.looseObject({
|
|
11570
11620
|
invocation: zod_mini.z.optional(zod_mini.z.string()),
|
|
11571
11621
|
"disable-model-invocation": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
@@ -11645,6 +11695,13 @@ const RulesyncSkillFrontmatterSchema = zod_mini.z.looseObject({
|
|
|
11645
11695
|
"when-to-use": zod_mini.z.optional(zod_mini.z.string()),
|
|
11646
11696
|
paths: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())]))
|
|
11647
11697
|
})),
|
|
11698
|
+
firebender: zod_mini.z.optional(zod_mini.z.looseObject({
|
|
11699
|
+
version: zod_mini.z.optional(zod_mini.z.unknown()),
|
|
11700
|
+
autoTrigger: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
11701
|
+
"disable-model-invocation": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
11702
|
+
projectTypes: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())])),
|
|
11703
|
+
icon: zod_mini.z.optional(zod_mini.z.string())
|
|
11704
|
+
})),
|
|
11648
11705
|
zcode: zod_mini.z.optional(zod_mini.z.looseObject({
|
|
11649
11706
|
when_to_use: zod_mini.z.optional(zod_mini.z.string()),
|
|
11650
11707
|
license: zod_mini.z.optional(zod_mini.z.string()),
|
|
@@ -11934,9 +11991,9 @@ async function getLocalSkillDirNames(sourceTree) {
|
|
|
11934
11991
|
* The rulesync skill frontmatter exposes a root-level `disable-model-invocation`
|
|
11935
11992
|
* default that applies to every tool supporting the flag (claudecode, codebuddy, copilot,
|
|
11936
11993
|
* copilotcli, crush, cursor, zed, pi, omp, qwencode, vibe, grokcli, factorydroid, dsh, reasonix,
|
|
11937
|
-
* commandcode, lettacode, opencode, opencodev1, mimocode, xum). Each tool's own section
|
|
11938
|
-
* default with a per-target value. A defined section value
|
|
11939
|
-
* always wins over the root default.
|
|
11994
|
+
* commandcode, lettacode, opencode, opencodev1, mimocode, xum, firebender). Each tool's own section
|
|
11995
|
+
* may override that default with a per-target value. A defined section value
|
|
11996
|
+
* (including `false`) always wins over the root default.
|
|
11940
11997
|
*
|
|
11941
11998
|
* `devin` also consumes the root-level value — it maps `true` onto a user-only
|
|
11942
11999
|
* `triggers` list (see `devin-skill.ts`) — but has no section key of the same
|
|
@@ -17511,7 +17568,7 @@ const COMMANDCODE_SKILLS_DIR_PATH = (0, node_path.join)(COMMANDCODE_DIR, "skills
|
|
|
17511
17568
|
* (Command Code would send it as prompt text; a rulesync command carries its
|
|
17512
17569
|
* own frontmatter) and only the body is kept.
|
|
17513
17570
|
*
|
|
17514
|
-
* @see https://commandcode.ai/docs/custom-slash-commands
|
|
17571
|
+
* @see https://commandcode.ai/docs/reference/slash-commands#custom-slash-commands
|
|
17515
17572
|
*/
|
|
17516
17573
|
var CommandcodeCommand = class CommandcodeCommand extends ToolCommand {
|
|
17517
17574
|
static getSettablePaths(_options = {}) {
|
|
@@ -21020,12 +21077,25 @@ function raiseOpencodeAgentToV2(fields) {
|
|
|
21020
21077
|
}
|
|
21021
21078
|
const OPENCODE_FILE_TEMPLATE_PATTERN = /^\s*\{file:(.+?)\}\s*$/;
|
|
21022
21079
|
/**
|
|
21080
|
+
* Resolves the path of a `{file:...}` reference the way OpenCode does: relative
|
|
21081
|
+
* to the config file's directory, absolute as written, or from the home
|
|
21082
|
+
* directory when it starts with `~/`.
|
|
21083
|
+
*
|
|
21084
|
+
* @see https://opencode.ai/docs/config/#files
|
|
21085
|
+
*/
|
|
21086
|
+
function resolveOpencodeFileTemplatePath({ referencedPath, configDir }) {
|
|
21087
|
+
if (referencedPath.startsWith("~/")) return (0, node_path.join)(getHomeDirectory(), referencedPath.slice(2));
|
|
21088
|
+
if ((0, node_path.isAbsolute)(referencedPath)) return referencedPath;
|
|
21089
|
+
return (0, node_path.join)(configDir, referencedPath);
|
|
21090
|
+
}
|
|
21091
|
+
/**
|
|
21023
21092
|
* Resolves an OpenCode `{file:./path}` string reference into the referenced
|
|
21024
21093
|
* file's contents. OpenCode resolves these paths relative to the config file's
|
|
21025
21094
|
* location, so `configDir` must be the directory holding `opencode.json`. When
|
|
21026
21095
|
* the value is not a whole-value file reference it is returned unchanged; when
|
|
21027
21096
|
* the referenced file cannot be read the literal value is preserved (so the
|
|
21028
|
-
* reference is not silently lost).
|
|
21097
|
+
* reference is not silently lost). As in OpenCode, an absolute path is used as
|
|
21098
|
+
* written and a path starting with `~/` is taken from the home directory.
|
|
21029
21099
|
*
|
|
21030
21100
|
* When `containmentRoot` is given (project scope), a reference whose real
|
|
21031
21101
|
* location — every `..` segment and symbolic link resolved — lies outside it is
|
|
@@ -21043,7 +21113,10 @@ async function resolveOpencodeFileTemplate({ value, configDir, containmentRoot,
|
|
|
21043
21113
|
if (!match) return value;
|
|
21044
21114
|
const referencedPath = match[1]?.trim().replace(/^\.\//, "");
|
|
21045
21115
|
if (!referencedPath) return value;
|
|
21046
|
-
const targetPath = (
|
|
21116
|
+
const targetPath = resolveOpencodeFileTemplatePath({
|
|
21117
|
+
referencedPath,
|
|
21118
|
+
configDir
|
|
21119
|
+
});
|
|
21047
21120
|
if (containmentRoot === void 0) return await readFileContentOrNull(targetPath) ?? value;
|
|
21048
21121
|
const relativePath = await resolvedRelativePath({
|
|
21049
21122
|
rootPath: containmentRoot,
|
|
@@ -26459,18 +26532,86 @@ var FactorydroidSkill = class FactorydroidSkill extends ToolSkill {
|
|
|
26459
26532
|
};
|
|
26460
26533
|
// src/features/skills/firebender-skill.ts
|
|
26461
26534
|
/**
|
|
26535
|
+
* The Agent Skills standard keys the `agentsskills` section carries. On import
|
|
26536
|
+
* they go back there, exactly as for the `agentsskills` target, and every other
|
|
26537
|
+
* key besides `name` / `description` goes into the `firebender` section.
|
|
26538
|
+
*/
|
|
26539
|
+
const AGENT_SKILLS_STANDARD_KEYS$1 = /* @__PURE__ */ new Set([
|
|
26540
|
+
"name",
|
|
26541
|
+
"description",
|
|
26542
|
+
"license",
|
|
26543
|
+
"compatibility",
|
|
26544
|
+
"metadata",
|
|
26545
|
+
"allowed-tools"
|
|
26546
|
+
]);
|
|
26547
|
+
/**
|
|
26462
26548
|
* Firebender skills follow the Agent Skills layout (`<name>/SKILL.md` with the
|
|
26463
26549
|
* required `name` and `description` frontmatter, plus optional supporting
|
|
26464
26550
|
* files), so this target reuses {@link AgentsSkillsSkill} with Firebender's
|
|
26465
26551
|
* recommended locations: `.firebender/skills/` (project) and
|
|
26466
26552
|
* `~/.firebender/skills/` (user).
|
|
26467
26553
|
*
|
|
26554
|
+
* On top of the standard fields, Firebender reads `version`, `autoTrigger`,
|
|
26555
|
+
* `disable-model-invocation` (the inverse of `autoTrigger`, which wins when
|
|
26556
|
+
* both are set), `projectTypes` and `icon`. Those come from the `firebender`
|
|
26557
|
+
* section of the rulesync skill and are written verbatim;
|
|
26558
|
+
* `disable-model-invocation` falls back to the root-level rulesync value.
|
|
26559
|
+
*
|
|
26468
26560
|
* @see https://docs.firebender.com/api-reference/skills
|
|
26469
26561
|
*/
|
|
26470
|
-
var FirebenderSkill = class extends AgentsSkillsSkill {
|
|
26562
|
+
var FirebenderSkill = class FirebenderSkill extends AgentsSkillsSkill {
|
|
26471
26563
|
static getSettablePaths(_options = {}) {
|
|
26472
26564
|
return { relativeDirPath: FIREBENDER_SKILLS_DIR_PATH };
|
|
26473
26565
|
}
|
|
26566
|
+
toRulesyncSkill() {
|
|
26567
|
+
const base = super.toRulesyncSkill();
|
|
26568
|
+
const firebenderSection = Object.fromEntries(Object.entries(this.getFrontmatter()).filter(([key]) => !AGENT_SKILLS_STANDARD_KEYS$1.has(key)));
|
|
26569
|
+
if (Object.keys(firebenderSection).length === 0) return base;
|
|
26570
|
+
const rulesyncFrontmatter = {
|
|
26571
|
+
...base.getFrontmatter(),
|
|
26572
|
+
firebender: firebenderSection
|
|
26573
|
+
};
|
|
26574
|
+
return this.toRulesyncSkillWith(rulesyncFrontmatter);
|
|
26575
|
+
}
|
|
26576
|
+
static fromRulesyncSkill({ outputRoot = process.cwd(), rulesyncSkill, validate = true, global = false, logger }) {
|
|
26577
|
+
const settablePaths = FirebenderSkill.getSettablePaths({ global });
|
|
26578
|
+
const rulesyncFrontmatter = rulesyncSkill.getFrontmatter();
|
|
26579
|
+
const dirName = rulesyncSkill.getDirName();
|
|
26580
|
+
const firebenderSection = {};
|
|
26581
|
+
const ignoredKeys = [];
|
|
26582
|
+
for (const [key, value] of Object.entries(rulesyncFrontmatter.firebender ?? {})) if (AGENT_SKILLS_STANDARD_KEYS$1.has(key)) ignoredKeys.push(key);
|
|
26583
|
+
else firebenderSection[key] = value;
|
|
26584
|
+
if (ignoredKeys.length > 0) warnWithFallback(logger, `${(0, node_path.join)(outputRoot, settablePaths.relativeDirPath, dirName, SKILL_FILE_NAME)}: the firebender section sets ${ignoredKeys.map(quoteValueForWarning).join(", ")}, which ${ignoredKeys.length === 1 ? "is" : "are"} ignored there; set name/description at the root and the Agent Skills standard fields at the root or in the agentsskills section.`);
|
|
26585
|
+
const disableModelInvocation = resolveDisableModelInvocation({
|
|
26586
|
+
rootFrontmatter: rulesyncFrontmatter,
|
|
26587
|
+
section: rulesyncFrontmatter.firebender
|
|
26588
|
+
});
|
|
26589
|
+
const frontmatter = {
|
|
26590
|
+
name: rulesyncFrontmatter.name,
|
|
26591
|
+
description: rulesyncFrontmatter.description,
|
|
26592
|
+
...toSpecConformantAgentSkillFields(resolveAgentsSkillsSection(rulesyncFrontmatter)),
|
|
26593
|
+
...firebenderSection,
|
|
26594
|
+
...disableModelInvocation !== void 0 && { "disable-model-invocation": disableModelInvocation }
|
|
26595
|
+
};
|
|
26596
|
+
AgentsSkillsSkill.reportSpecViolations({
|
|
26597
|
+
outputRoot,
|
|
26598
|
+
relativeDirPath: settablePaths.relativeDirPath,
|
|
26599
|
+
dirName,
|
|
26600
|
+
frontmatter,
|
|
26601
|
+
sourceAllowedTools: rulesyncFrontmatter.agentsskills?.["allowed-tools"],
|
|
26602
|
+
logger
|
|
26603
|
+
});
|
|
26604
|
+
return new FirebenderSkill({
|
|
26605
|
+
outputRoot,
|
|
26606
|
+
relativeDirPath: settablePaths.relativeDirPath,
|
|
26607
|
+
dirName,
|
|
26608
|
+
frontmatter,
|
|
26609
|
+
body: rulesyncSkill.getBody(),
|
|
26610
|
+
otherFiles: rulesyncSkill.getOtherFiles(),
|
|
26611
|
+
validate,
|
|
26612
|
+
global
|
|
26613
|
+
});
|
|
26614
|
+
}
|
|
26474
26615
|
static toolTarget = "firebender";
|
|
26475
26616
|
};
|
|
26476
26617
|
// src/features/skills/gitlabduo-skill.ts
|
|
@@ -26697,39 +26838,22 @@ var GrokcliSkill = class GrokcliSkill extends ToolSkill {
|
|
|
26697
26838
|
return new GrokcliSkill(this.forDeletionParams(params));
|
|
26698
26839
|
}
|
|
26699
26840
|
};
|
|
26700
|
-
// src/
|
|
26701
|
-
const JunieSkillFrontmatterSchema = zod_mini.z.looseObject({
|
|
26702
|
-
name: zod_mini.z.string(),
|
|
26703
|
-
description: zod_mini.z.string()
|
|
26704
|
-
});
|
|
26841
|
+
// src/utils/markdown-paragraph.ts
|
|
26705
26842
|
/** An ATX markdown heading line (`#` … `######`). */
|
|
26706
26843
|
const HEADING_LINE = /^#{1,6}(\s|$)/;
|
|
26707
26844
|
/**
|
|
26708
|
-
*
|
|
26709
|
-
* `description` is not provided in the frontmatter, Junie CLI extracts the
|
|
26710
|
-
* first paragraph of the body content as the description." Headings do not
|
|
26711
|
-
* count as that paragraph — "If the body is also empty or contains only
|
|
26712
|
-
* headings, the skill will fail to load."
|
|
26845
|
+
* The first non-heading paragraph of a Markdown body, collapsed onto one line.
|
|
26713
26846
|
*
|
|
26714
|
-
*
|
|
26715
|
-
*
|
|
26716
|
-
*
|
|
26717
|
-
* the
|
|
26718
|
-
*
|
|
26719
|
-
*
|
|
26720
|
-
*
|
|
26721
|
-
*
|
|
26722
|
-
* correct fallback with the wrong value everywhere, canonical config included.
|
|
26723
|
-
*
|
|
26724
|
-
* A paragraph runs to the first blank line or heading, and is collapsed onto
|
|
26725
|
-
* one line because it becomes a YAML frontmatter value. A fenced code block is
|
|
26726
|
-
* not treated specially: it is ordinary content, so a body whose first
|
|
26727
|
-
* paragraph is a fence yields the fence text. Returns an empty string when the
|
|
26728
|
-
* body holds no such paragraph, which the caller turns into a skipped skill.
|
|
26729
|
-
*
|
|
26730
|
-
* @see https://junie.jetbrains.com/docs/agent-skills.html
|
|
26847
|
+
* JetBrains Junie falls back to this paragraph as the description of a skill
|
|
26848
|
+
* or subagent whose frontmatter omits one. Heading lines are skipped rather
|
|
26849
|
+
* than taken, so a body opening with `# Title` does not yield the title. A
|
|
26850
|
+
* paragraph runs to the first blank line or heading, and is collapsed onto one
|
|
26851
|
+
* line because callers store it as a YAML frontmatter value. A fenced code
|
|
26852
|
+
* block is not treated specially: it is ordinary content, so a body whose
|
|
26853
|
+
* first paragraph is a fence yields the fence text. Returns an empty string
|
|
26854
|
+
* when the body holds no such paragraph.
|
|
26731
26855
|
*/
|
|
26732
|
-
function
|
|
26856
|
+
function firstNonHeadingParagraph(body) {
|
|
26733
26857
|
const paragraph = [];
|
|
26734
26858
|
for (const rawLine of body.split(/\r?\n/)) {
|
|
26735
26859
|
const line = rawLine.trim();
|
|
@@ -26743,6 +26867,11 @@ function deriveDescriptionFromBody(body) {
|
|
|
26743
26867
|
}
|
|
26744
26868
|
return paragraph.join(" ").trim();
|
|
26745
26869
|
}
|
|
26870
|
+
// src/features/skills/junie-skill.ts
|
|
26871
|
+
const JunieSkillFrontmatterSchema = zod_mini.z.looseObject({
|
|
26872
|
+
name: zod_mini.z.string(),
|
|
26873
|
+
description: zod_mini.z.string()
|
|
26874
|
+
});
|
|
26746
26875
|
/**
|
|
26747
26876
|
* Represents a JetBrains Junie skill directory.
|
|
26748
26877
|
* Skills are stored under the .junie/skills directory with SKILL.md files.
|
|
@@ -26813,7 +26942,7 @@ var JunieSkill = class JunieSkill extends ToolSkill {
|
|
|
26813
26942
|
});
|
|
26814
26943
|
let frontmatter = loaded.frontmatter;
|
|
26815
26944
|
if (isRecord(frontmatter) && frontmatter.description === void 0) {
|
|
26816
|
-
const derived =
|
|
26945
|
+
const derived = firstNonHeadingParagraph(loaded.body);
|
|
26817
26946
|
if (derived === "") throw new Error(`Cannot import ${(0, node_path.join)(loaded.outputRoot, loaded.relativeDirPath, loaded.dirName, SKILL_FILE_NAME)}: it has no description and its body has no paragraph to derive one from, so Junie cannot load it either. Add a description to the frontmatter.`);
|
|
26818
26947
|
frontmatter = {
|
|
26819
26948
|
...frontmatter,
|
|
@@ -27847,6 +27976,125 @@ var PiSkill = class extends ToolSkill {
|
|
|
27847
27976
|
var OmpSkill = class extends PiSkill {
|
|
27848
27977
|
static layout = OMP_LAYOUT;
|
|
27849
27978
|
};
|
|
27979
|
+
// src/constants/openclaw-paths.ts
|
|
27980
|
+
const OPENCLAW_WORKSPACE_DIR_PATH = (0, node_path.join)(".openclaw", "workspace");
|
|
27981
|
+
const OPENCLAW_RULE_FILE_NAME = "AGENTS.md";
|
|
27982
|
+
const OPENCLAW_CONFIG_DIR_PATH = ".openclaw";
|
|
27983
|
+
const OPENCLAW_CONFIG_FILE_NAME = "openclaw.json";
|
|
27984
|
+
const OPENCLAW_MCP_SERVERS_KEY = "servers";
|
|
27985
|
+
const OPENCLAW_PROJECT_SKILLS_DIR_PATH = (0, node_path.join)(".agents", "skills");
|
|
27986
|
+
const OPENCLAW_GLOBAL_SKILLS_DIR_PATH = (0, node_path.join)(OPENCLAW_CONFIG_DIR_PATH, "skills");
|
|
27987
|
+
// src/features/skills/openclaw-skill.ts
|
|
27988
|
+
const OpenclawSkillFrontmatterSchema = zod_mini.z.looseObject({
|
|
27989
|
+
name: zod_mini.z.string(),
|
|
27990
|
+
description: zod_mini.z.string(),
|
|
27991
|
+
homepage: zod_mini.z.optional(zod_mini.z.string()),
|
|
27992
|
+
"user-invocable": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
27993
|
+
"disable-model-invocation": zod_mini.z.optional(zod_mini.z.boolean()),
|
|
27994
|
+
"command-dispatch": zod_mini.z.optional(zod_mini.z.string()),
|
|
27995
|
+
"command-tool": zod_mini.z.optional(zod_mini.z.string()),
|
|
27996
|
+
"command-arg-mode": zod_mini.z.optional(zod_mini.z.string()),
|
|
27997
|
+
metadata: zod_mini.z.optional(zod_mini.z.looseObject({}))
|
|
27998
|
+
});
|
|
27999
|
+
/**
|
|
28000
|
+
* Represents an OpenClaw skill directory.
|
|
28001
|
+
*
|
|
28002
|
+
* Project mode writes the execution folder's `.agents/skills/<name>/SKILL.md`,
|
|
28003
|
+
* which OpenClaw loads when a session runs from that folder (the same mechanism
|
|
28004
|
+
* that loads the folder's `AGENTS.md`). Global mode writes the managed/local
|
|
28005
|
+
* `~/.openclaw/skills/<name>/SKILL.md` root, visible to every agent sharing the
|
|
28006
|
+
* default state directory. The execution folder's `skills/` and the personal
|
|
28007
|
+
* `~/.agents/skills` roots are left alone (see `openclaw-paths.ts`).
|
|
28008
|
+
*
|
|
28009
|
+
* Every key beyond `name`/`description` is carried in the `openclaw` section of
|
|
28010
|
+
* the rulesync skill; the two invocation flags and `metadata` fall back to the
|
|
28011
|
+
* shared root-level defaults when the section omits them.
|
|
28012
|
+
*
|
|
28013
|
+
* @see https://docs.openclaw.ai/tools/skills
|
|
28014
|
+
*/
|
|
28015
|
+
var OpenclawSkill = class OpenclawSkill extends ToolSkill {
|
|
28016
|
+
constructor({ outputRoot = process.cwd(), relativeDirPath = OPENCLAW_PROJECT_SKILLS_DIR_PATH, dirName, frontmatter, body, otherFiles = [], validate = true, global = false }) {
|
|
28017
|
+
super({
|
|
28018
|
+
outputRoot,
|
|
28019
|
+
relativeDirPath,
|
|
28020
|
+
dirName,
|
|
28021
|
+
mainFile: {
|
|
28022
|
+
name: SKILL_FILE_NAME,
|
|
28023
|
+
body,
|
|
28024
|
+
frontmatter: { ...frontmatter }
|
|
28025
|
+
},
|
|
28026
|
+
otherFiles,
|
|
28027
|
+
global
|
|
28028
|
+
});
|
|
28029
|
+
if (validate) {
|
|
28030
|
+
const result = this.validate();
|
|
28031
|
+
if (!result.success) throw result.error;
|
|
28032
|
+
}
|
|
28033
|
+
}
|
|
28034
|
+
static getSettablePaths({ global = false } = {}) {
|
|
28035
|
+
return { relativeDirPath: global ? OPENCLAW_GLOBAL_SKILLS_DIR_PATH : OPENCLAW_PROJECT_SKILLS_DIR_PATH };
|
|
28036
|
+
}
|
|
28037
|
+
getFrontmatter() {
|
|
28038
|
+
return OpenclawSkillFrontmatterSchema.parse(this.requireMainFileFrontmatter());
|
|
28039
|
+
}
|
|
28040
|
+
validate() {
|
|
28041
|
+
return this.validateMainFileFrontmatter(OpenclawSkillFrontmatterSchema);
|
|
28042
|
+
}
|
|
28043
|
+
toRulesyncSkill() {
|
|
28044
|
+
const { name, description, ...section } = this.getFrontmatter();
|
|
28045
|
+
const rulesyncFrontmatter = {
|
|
28046
|
+
name,
|
|
28047
|
+
description,
|
|
28048
|
+
targets: ["*"],
|
|
28049
|
+
...Object.keys(section).length > 0 && { openclaw: section }
|
|
28050
|
+
};
|
|
28051
|
+
return this.toRulesyncSkillWith(rulesyncFrontmatter);
|
|
28052
|
+
}
|
|
28053
|
+
static fromRulesyncSkill({ outputRoot = process.cwd(), rulesyncSkill, validate = true, global = false }) {
|
|
28054
|
+
const rulesyncFrontmatter = rulesyncSkill.getFrontmatter();
|
|
28055
|
+
const { name: _sectionName, description: _sectionDescription, ...section } = rulesyncFrontmatter.openclaw ?? {};
|
|
28056
|
+
const disableModelInvocation = resolveDisableModelInvocation({
|
|
28057
|
+
rootFrontmatter: rulesyncFrontmatter,
|
|
28058
|
+
section
|
|
28059
|
+
});
|
|
28060
|
+
const userInvocable = resolveUserInvocable({
|
|
28061
|
+
rootFrontmatter: rulesyncFrontmatter,
|
|
28062
|
+
section
|
|
28063
|
+
});
|
|
28064
|
+
const metadata = resolveMetadata({
|
|
28065
|
+
rootFrontmatter: rulesyncFrontmatter,
|
|
28066
|
+
section
|
|
28067
|
+
});
|
|
28068
|
+
const frontmatter = {
|
|
28069
|
+
...section,
|
|
28070
|
+
name: rulesyncFrontmatter.name,
|
|
28071
|
+
description: rulesyncFrontmatter.description,
|
|
28072
|
+
...metadata !== void 0 && { metadata },
|
|
28073
|
+
...disableModelInvocation !== void 0 && { "disable-model-invocation": disableModelInvocation },
|
|
28074
|
+
...userInvocable !== void 0 && { "user-invocable": userInvocable }
|
|
28075
|
+
};
|
|
28076
|
+
return new OpenclawSkill({
|
|
28077
|
+
outputRoot,
|
|
28078
|
+
relativeDirPath: OpenclawSkill.getSettablePaths({ global }).relativeDirPath,
|
|
28079
|
+
dirName: rulesyncSkill.getDirName(),
|
|
28080
|
+
frontmatter,
|
|
28081
|
+
body: rulesyncSkill.getBody(),
|
|
28082
|
+
otherFiles: rulesyncSkill.getOtherFiles(),
|
|
28083
|
+
validate,
|
|
28084
|
+
global
|
|
28085
|
+
});
|
|
28086
|
+
}
|
|
28087
|
+
static toolTarget = "openclaw";
|
|
28088
|
+
static async fromDir(params) {
|
|
28089
|
+
return new OpenclawSkill(await this.loadStandardSkillParams({
|
|
28090
|
+
params,
|
|
28091
|
+
schema: OpenclawSkillFrontmatterSchema
|
|
28092
|
+
}));
|
|
28093
|
+
}
|
|
28094
|
+
static forDeletion(params) {
|
|
28095
|
+
return new OpenclawSkill(this.forDeletionParams(params));
|
|
28096
|
+
}
|
|
28097
|
+
};
|
|
27850
28098
|
// src/features/skills/opencodev1-skill.ts
|
|
27851
28099
|
/**
|
|
27852
28100
|
* Skill generator for **OpenCode V1** (OpenCode 1.x). Skills live in the same
|
|
@@ -29910,6 +30158,14 @@ const toolSkillFactories = /* @__PURE__ */ new Map([
|
|
|
29910
30158
|
supportsSimulated: false,
|
|
29911
30159
|
supportsGlobal: true
|
|
29912
30160
|
}
|
|
30161
|
+
}],
|
|
30162
|
+
["openclaw", {
|
|
30163
|
+
class: OpenclawSkill,
|
|
30164
|
+
meta: {
|
|
30165
|
+
supportsProject: true,
|
|
30166
|
+
supportsSimulated: false,
|
|
30167
|
+
supportsGlobal: true
|
|
30168
|
+
}
|
|
29913
30169
|
}]
|
|
29914
30170
|
]);
|
|
29915
30171
|
const defaultGetFactory$5 = (target) => {
|
|
@@ -32403,7 +32659,7 @@ function warnAboutReservedAgentName({ name, relativeFilePath, logger }) {
|
|
|
32403
32659
|
* `.commandcode/agents/` (project) or `~/.commandcode/agents/` (user); the
|
|
32404
32660
|
* body is the agent's system prompt.
|
|
32405
32661
|
*
|
|
32406
|
-
* @see https://commandcode.ai/docs/
|
|
32662
|
+
* @see https://commandcode.ai/docs/agents
|
|
32407
32663
|
*/
|
|
32408
32664
|
var CommandcodeSubagent = class extends FrontmatterMarkdownToolSubagent {
|
|
32409
32665
|
static getSettablePaths(_options = {}) {
|
|
@@ -34157,7 +34413,7 @@ var HermesagentSubagent = class HermesagentSubagent extends ToolSubagent {
|
|
|
34157
34413
|
*/
|
|
34158
34414
|
const JunieSubagentFrontmatterSchema = zod_mini.z.looseObject({
|
|
34159
34415
|
name: zod_mini.z.optional(zod_mini.z.string()),
|
|
34160
|
-
description: zod_mini.z.string(),
|
|
34416
|
+
description: zod_mini.z.optional(zod_mini.z.string()),
|
|
34161
34417
|
tools: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())])),
|
|
34162
34418
|
disallowedTools: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())])),
|
|
34163
34419
|
mcpServers: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())])),
|
|
@@ -34168,6 +34424,34 @@ const JunieSubagentFrontmatterSchema = zod_mini.z.looseObject({
|
|
|
34168
34424
|
skills: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.string(), zod_mini.z.array(zod_mini.z.string())])),
|
|
34169
34425
|
allowPromptArgument: zod_mini.z.optional(zod_mini.z.boolean())
|
|
34170
34426
|
});
|
|
34427
|
+
/** Junie truncates a body-derived subagent description to this many characters. */
|
|
34428
|
+
const JUNIE_DERIVED_DESCRIPTION_MAX_LENGTH = 1024;
|
|
34429
|
+
/**
|
|
34430
|
+
* Junie's fallback when a subagent's frontmatter has no `description`: the
|
|
34431
|
+
* first non-heading paragraph of the body, truncated to 1,024 characters.
|
|
34432
|
+
* Returns `undefined` when the body has no such paragraph.
|
|
34433
|
+
*
|
|
34434
|
+
* @see https://junie.jetbrains.com/docs/junie-cli-subagents.html
|
|
34435
|
+
*/
|
|
34436
|
+
function deriveDescriptionFromBody(body) {
|
|
34437
|
+
const paragraph = firstNonHeadingParagraph(body);
|
|
34438
|
+
if (paragraph === "") return void 0;
|
|
34439
|
+
return truncateText({
|
|
34440
|
+
text: paragraph,
|
|
34441
|
+
maxLength: JUNIE_DERIVED_DESCRIPTION_MAX_LENGTH,
|
|
34442
|
+
suffix: ""
|
|
34443
|
+
});
|
|
34444
|
+
}
|
|
34445
|
+
function isMissingDescription(value) {
|
|
34446
|
+
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
34447
|
+
}
|
|
34448
|
+
/**
|
|
34449
|
+
* Junie's fallback subagent name: the file name without its `.agent.md` or
|
|
34450
|
+
* `.md` extension.
|
|
34451
|
+
*/
|
|
34452
|
+
function nameFromFileName(relativeFilePath) {
|
|
34453
|
+
return relativeFilePath.replace(/(\.agent)?\.md$/, "");
|
|
34454
|
+
}
|
|
34171
34455
|
var JunieSubagent = class JunieSubagent extends ToolSubagent {
|
|
34172
34456
|
frontmatter;
|
|
34173
34457
|
body;
|
|
@@ -34199,8 +34483,8 @@ var JunieSubagent = class JunieSubagent extends ToolSubagent {
|
|
|
34199
34483
|
outputRoot: ".",
|
|
34200
34484
|
frontmatter: {
|
|
34201
34485
|
targets: ["*"],
|
|
34202
|
-
name: name ?? this.getRelativeFilePath()
|
|
34203
|
-
description,
|
|
34486
|
+
name: name ?? nameFromFileName(this.getRelativeFilePath()),
|
|
34487
|
+
...description !== void 0 && { description },
|
|
34204
34488
|
...Object.keys(junieSection).length > 0 && { junie: junieSection }
|
|
34205
34489
|
},
|
|
34206
34490
|
body: this.body,
|
|
@@ -34259,7 +34543,16 @@ var JunieSubagent = class JunieSubagent extends ToolSubagent {
|
|
|
34259
34543
|
const dirPath = relativeDirPath ?? this.getSettablePaths({ global }).relativeDirPath;
|
|
34260
34544
|
const filePath = (0, node_path.join)(outputRoot, dirPath, relativeFilePath);
|
|
34261
34545
|
const fileContent = await readFileContent(filePath);
|
|
34262
|
-
const { frontmatter, body: content } = parseFrontmatter(fileContent, filePath);
|
|
34546
|
+
const { frontmatter: parsedFrontmatter, body: content } = parseFrontmatter(fileContent, filePath);
|
|
34547
|
+
let frontmatter = parsedFrontmatter;
|
|
34548
|
+
if (isRecord(frontmatter) && isMissingDescription(frontmatter.description)) {
|
|
34549
|
+
const { description: _missing, ...rest } = frontmatter;
|
|
34550
|
+
const derived = deriveDescriptionFromBody(content);
|
|
34551
|
+
frontmatter = derived === void 0 ? rest : {
|
|
34552
|
+
...rest,
|
|
34553
|
+
description: derived
|
|
34554
|
+
};
|
|
34555
|
+
}
|
|
34263
34556
|
const result = JunieSubagentFrontmatterSchema.safeParse(frontmatter);
|
|
34264
34557
|
if (!result.success) throw new Error(`Invalid frontmatter in ${filePath}: ${formatError(result.error)}`);
|
|
34265
34558
|
return new JunieSubagent({
|
|
@@ -34957,11 +35250,19 @@ const LettacodeSubagentFrontmatterSchema = zod_mini.z.looseObject({
|
|
|
34957
35250
|
*/
|
|
34958
35251
|
const LETTACODE_AGENT_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
34959
35252
|
/**
|
|
34960
|
-
* Names
|
|
34961
|
-
*
|
|
34962
|
-
* (`RESERVED_EXTERNAL_SUBAGENT_NAMES` in `src/agent/subagents/index.ts`)
|
|
35253
|
+
* Names a custom subagent cannot take: Letta Code skips it when agents are
|
|
35254
|
+
* loaded. These are the external-agent launcher names
|
|
35255
|
+
* (`RESERVED_EXTERNAL_SUBAGENT_NAMES` in `src/agent/subagents/index.ts`)
|
|
35256
|
+
* plus `memory`, which the same loader also skips (as of letta-code v0.34.66).
|
|
34963
35257
|
*/
|
|
34964
|
-
const LETTACODE_RESERVED_AGENT_NAMES = /* @__PURE__ */ new Set([
|
|
35258
|
+
const LETTACODE_RESERVED_AGENT_NAMES = /* @__PURE__ */ new Set([
|
|
35259
|
+
"letta",
|
|
35260
|
+
"claude-code",
|
|
35261
|
+
"codex",
|
|
35262
|
+
"opencode",
|
|
35263
|
+
"cursor",
|
|
35264
|
+
"memory"
|
|
35265
|
+
]);
|
|
34965
35266
|
/**
|
|
34966
35267
|
* The subagent is still generated as authored — the name is the user's to
|
|
34967
35268
|
* change, and a rename here would make it diverge from the other targets —
|
|
@@ -41484,18 +41785,20 @@ var AugmentcodePluginRule = class extends AugmentcodeRule {
|
|
|
41484
41785
|
return { nonRoot: { relativeDirPath: AUGMENTCODE_PLUGIN_RULES_DIR } };
|
|
41485
41786
|
}
|
|
41486
41787
|
/**
|
|
41487
|
-
* Auggie 1.x (
|
|
41488
|
-
*
|
|
41489
|
-
* plugins (`rules/` in a plugin)" is
|
|
41490
|
-
* commands, agents, skills, hooks
|
|
41491
|
-
*
|
|
41492
|
-
*
|
|
41788
|
+
* Auggie 1.x (the stable line on npm `latest` since 1.2.0; 0.x is kept only
|
|
41789
|
+
* on the `v0-release` tag with auto-update turned off) no longer loads
|
|
41790
|
+
* `rules/` from plugins: "Rules shipped in plugins (`rules/` in a plugin)" is
|
|
41791
|
+
* listed among the removed features, while commands, agents, skills, hooks
|
|
41792
|
+
* and MCP servers still load. The rule files are still written for users
|
|
41793
|
+
* pinned to 0.x, which reads them, but under 1.x the bundle silently loses
|
|
41794
|
+
* them, so say so.
|
|
41493
41795
|
* @see https://docs.augmentcode.com/cli/whats-new
|
|
41796
|
+
* @see https://www.augmentcode.com/changelog
|
|
41494
41797
|
* @see https://docs.augmentcode.com/cli/v0/plugins
|
|
41495
41798
|
*/
|
|
41496
41799
|
static async getGenerationWarnings({ toolRules }) {
|
|
41497
41800
|
if (toolRules.length === 0) return [];
|
|
41498
|
-
return [`augmentcode-plugin: plugin rules (rules/*.md) are loaded by Auggie 0.x only; Auggie 1.x no longer reads rules/ from plugins, so these ${toolRules.length} rule file(s)
|
|
41801
|
+
return [`augmentcode-plugin: plugin rules (rules/*.md) are loaded by Auggie 0.x only; Auggie 1.x no longer reads rules/ from plugins, so these ${toolRules.length} rule file(s) reach only users pinned to Auggie 0.x (1.x is the stable CLI since 1.2.0). Ship instructions that must reach Auggie 1.x users as a skill, or have them generate the augmentcode target in their project.`];
|
|
41499
41802
|
}
|
|
41500
41803
|
};
|
|
41501
41804
|
// src/features/rules/bob-rule.ts
|
|
@@ -46081,12 +46384,6 @@ var OmpRule = class OmpRule extends ToolRule {
|
|
|
46081
46384
|
}
|
|
46082
46385
|
static toolTarget = "omp";
|
|
46083
46386
|
};
|
|
46084
|
-
// src/constants/openclaw-paths.ts
|
|
46085
|
-
const OPENCLAW_WORKSPACE_DIR_PATH = (0, node_path.join)(".openclaw", "workspace");
|
|
46086
|
-
const OPENCLAW_RULE_FILE_NAME = "AGENTS.md";
|
|
46087
|
-
const OPENCLAW_CONFIG_DIR_PATH = ".openclaw";
|
|
46088
|
-
const OPENCLAW_CONFIG_FILE_NAME = "openclaw.json";
|
|
46089
|
-
const OPENCLAW_MCP_SERVERS_KEY = "servers";
|
|
46090
46387
|
// src/features/rules/openclaw-rule.ts
|
|
46091
46388
|
/**
|
|
46092
46389
|
* Rule generator for OpenClaw, the always-on assistant gateway.
|
|
@@ -54616,12 +54913,23 @@ function toolMatcherEntryToCanonical({ rawEntry, eventName, converterConfig, war
|
|
|
54616
54913
|
* tool-native keys through verbatim — so documented native triggers (e.g.
|
|
54617
54914
|
* kiro-ide's `PostFileSave`) survive an import → generate round-trip instead
|
|
54618
54915
|
* of failing canonical validation.
|
|
54916
|
+
*
|
|
54917
|
+
* An event key named `__proto__`, `constructor` or `prototype` is dropped with
|
|
54918
|
+
* a warning: no tool documents such an event, and carrying it into
|
|
54919
|
+
* `.rulesync/hooks.jsonc` would make the next `generate` fail the
|
|
54920
|
+
* prototype-pollution key validation.
|
|
54619
54921
|
*/
|
|
54620
|
-
function buildImportedHooksConfig({ hooks, overrideKey, version = 1, extraOverride }) {
|
|
54922
|
+
function buildImportedHooksConfig({ hooks, overrideKey, version = 1, extraOverride, logger }) {
|
|
54621
54923
|
const canonical = {};
|
|
54622
54924
|
const native = {};
|
|
54623
|
-
for (const [event, defs] of Object.entries(hooks))
|
|
54624
|
-
|
|
54925
|
+
for (const [event, defs] of Object.entries(hooks)) {
|
|
54926
|
+
if (isPrototypePollutionKey(event)) {
|
|
54927
|
+
logger?.warn(`Skipping imported ${overrideKey} hooks event ${quoteValueForWarning(event)}: reserved key names cannot be used as hook events.`);
|
|
54928
|
+
continue;
|
|
54929
|
+
}
|
|
54930
|
+
if (isHookEvent(event)) canonical[event] = defs;
|
|
54931
|
+
else native[event] = defs;
|
|
54932
|
+
}
|
|
54625
54933
|
const override = { ...extraOverride };
|
|
54626
54934
|
if (Object.keys(native).length > 0) override.hooks = native;
|
|
54627
54935
|
const config = {
|
|
@@ -54871,6 +55179,7 @@ var AntigravityHooks = class extends ToolHooks {
|
|
|
54871
55179
|
});
|
|
54872
55180
|
const overrideKey = this.constructor.getOverrideKey();
|
|
54873
55181
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
55182
|
+
logger,
|
|
54874
55183
|
hooks,
|
|
54875
55184
|
overrideKey
|
|
54876
55185
|
}), null, 2) });
|
|
@@ -55255,6 +55564,7 @@ var AugmentcodeHooks = class AugmentcodeHooks extends ToolHooks {
|
|
|
55255
55564
|
converterConfig: AUGMENTCODE_CONVERTER_CONFIG
|
|
55256
55565
|
});
|
|
55257
55566
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
55567
|
+
logger,
|
|
55258
55568
|
hooks,
|
|
55259
55569
|
overrideKey: "augmentcode"
|
|
55260
55570
|
}), null, 2) });
|
|
@@ -55331,6 +55641,7 @@ var AugmentcodePluginHooks = class AugmentcodePluginHooks extends ToolHooks {
|
|
|
55331
55641
|
converterConfig: AUGMENTCODE_PLUGIN_CONVERTER_CONFIG
|
|
55332
55642
|
});
|
|
55333
55643
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
55644
|
+
logger,
|
|
55334
55645
|
hooks,
|
|
55335
55646
|
overrideKey: "augmentcode"
|
|
55336
55647
|
}), null, 2) });
|
|
@@ -55892,6 +56203,7 @@ var SettingsJsonHooks = class extends ToolHooks {
|
|
|
55892
56203
|
converterConfig: ctor.getConverterConfig()
|
|
55893
56204
|
});
|
|
55894
56205
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
56206
|
+
logger,
|
|
55895
56207
|
hooks,
|
|
55896
56208
|
overrideKey: spec.overrideKey
|
|
55897
56209
|
}), null, 2) });
|
|
@@ -56685,13 +56997,14 @@ var CodewhaleHooks = class CodewhaleHooks extends ToolHooks {
|
|
|
56685
56997
|
global
|
|
56686
56998
|
});
|
|
56687
56999
|
}
|
|
56688
|
-
toRulesyncHooks() {
|
|
57000
|
+
toRulesyncHooks({ logger } = {}) {
|
|
56689
57001
|
const parsed = this.parseFileContentOrThrow({
|
|
56690
57002
|
displayName: "Codewhale",
|
|
56691
57003
|
parse: (fileContent) => parseCodewhaleToml(fileContent)
|
|
56692
57004
|
});
|
|
56693
57005
|
const rawHooks = this.global ? isPlainObject(parsed.hooks) ? parsed.hooks.hooks : void 0 : parsed.hooks;
|
|
56694
57006
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
57007
|
+
logger,
|
|
56695
57008
|
hooks: codewhaleHooksToCanonical(rawHooks),
|
|
56696
57009
|
overrideKey: "codewhale"
|
|
56697
57010
|
}), null, 2) });
|
|
@@ -56929,6 +57242,7 @@ var CodexcliHooks = class CodexcliHooks extends ToolHooks {
|
|
|
56929
57242
|
logger
|
|
56930
57243
|
});
|
|
56931
57244
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
57245
|
+
logger,
|
|
56932
57246
|
hooks,
|
|
56933
57247
|
overrideKey: "codexcli"
|
|
56934
57248
|
}), null, 2) });
|
|
@@ -57025,6 +57339,7 @@ var CommandcodeHooks = class CommandcodeHooks extends ToolHooks {
|
|
|
57025
57339
|
converterConfig: COMMANDCODE_CONVERTER_CONFIG
|
|
57026
57340
|
});
|
|
57027
57341
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
57342
|
+
logger,
|
|
57028
57343
|
hooks,
|
|
57029
57344
|
overrideKey: "commandcode"
|
|
57030
57345
|
}), null, 2) });
|
|
@@ -57324,6 +57639,7 @@ var CopilotHooks = class CopilotHooks extends ToolHooks {
|
|
|
57324
57639
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
57325
57640
|
}).hooks, options?.logger);
|
|
57326
57641
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
57642
|
+
logger: options?.logger,
|
|
57327
57643
|
hooks,
|
|
57328
57644
|
overrideKey: "copilot"
|
|
57329
57645
|
}), null, 2) });
|
|
@@ -57776,6 +58092,7 @@ var CopilotcliHooks = class CopilotcliHooks extends ToolHooks {
|
|
|
57776
58092
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
57777
58093
|
}).hooks, options?.logger);
|
|
57778
58094
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
58095
|
+
logger: options?.logger,
|
|
57779
58096
|
hooks,
|
|
57780
58097
|
overrideKey: "copilotcli",
|
|
57781
58098
|
...this.disableAllHooks !== void 0 && { extraOverride: { disableAllHooks: this.disableAllHooks } }
|
|
@@ -58013,6 +58330,15 @@ function normalizeCrushEventName(event) {
|
|
|
58013
58330
|
/** Crush tool events, by normalized spelling, on which a `matcher` is valid. */
|
|
58014
58331
|
const NORMALIZED_CRUSH_TOOL_EVENTS = new Set(CRUSH_TOOL_EVENTS.map((event) => normalizeCrushEventName(event)));
|
|
58015
58332
|
/**
|
|
58333
|
+
* Every event Crush fires, by normalized spelling: the twelve with a canonical
|
|
58334
|
+
* counterpart plus `PermissionResult`, which is a tool event. Crush refuses to
|
|
58335
|
+
* load the whole config when a `hooks` key names any other event
|
|
58336
|
+
* ("hook <key>: unknown event").
|
|
58337
|
+
* @see https://github.com/charmbracelet/crush/blob/v0.102.0/internal/hooks/events.go
|
|
58338
|
+
* @see https://github.com/charmbracelet/crush/blob/v0.102.0/internal/config/hooks.go
|
|
58339
|
+
*/
|
|
58340
|
+
const NORMALIZED_KNOWN_CRUSH_EVENTS = new Set([...Object.values(CANONICAL_TO_CRUSH_EVENT_NAMES), ...CRUSH_TOOL_EVENTS].map((event) => normalizeCrushEventName(event)));
|
|
58341
|
+
/**
|
|
58016
58342
|
* Resolve a `crush.hooks` override key to the canonical event it names, or
|
|
58017
58343
|
* null when it names no canonical event. The key may be spelled the canonical
|
|
58018
58344
|
* way (`stop`) or in any spelling Crush accepts for the event (`TurnEnd`,
|
|
@@ -58041,11 +58367,13 @@ function resolveOverrideCanonicalEvent(key) {
|
|
|
58041
58367
|
* spelling it uses: the override replaces the shared entries of that event
|
|
58042
58368
|
* (as for every other tool's override), and override keys that name the same
|
|
58043
58369
|
* event are concatenated in order, the way Crush itself merges them. A key
|
|
58044
|
-
* that names
|
|
58045
|
-
*
|
|
58046
|
-
*
|
|
58047
|
-
*
|
|
58048
|
-
*
|
|
58370
|
+
* that names a Crush event with no canonical counterpart (`PermissionResult`)
|
|
58371
|
+
* is written verbatim so it round-trips; keys of that kind that Crush reads as
|
|
58372
|
+
* the same event are concatenated under the first spelling. A key that names
|
|
58373
|
+
* no Crush event at all (such as the Claude Code spelling `Stop`) is skipped
|
|
58374
|
+
* with a warning, since Crush would refuse to load the whole config. A
|
|
58375
|
+
* `matcher` is only written on a tool event: Crush rejects the whole config
|
|
58376
|
+
* when one appears anywhere else.
|
|
58049
58377
|
*/
|
|
58050
58378
|
function canonicalToCrushHooks({ config, toolOverride, logger }) {
|
|
58051
58379
|
const shared = /* @__PURE__ */ new Map();
|
|
@@ -58068,6 +58396,10 @@ function canonicalToCrushHooks({ config, toolOverride, logger }) {
|
|
|
58068
58396
|
}) ?? key;
|
|
58069
58397
|
else {
|
|
58070
58398
|
const normalized = normalizeCrushEventName(key);
|
|
58399
|
+
if (!NORMALIZED_KNOWN_CRUSH_EVENTS.has(normalized)) {
|
|
58400
|
+
logger?.warn(`crush.hooks event ${quoteValueForWarning(key)} is not a Crush hook event, so it was skipped — Crush refuses to load a config with an unknown hook event.`);
|
|
58401
|
+
continue;
|
|
58402
|
+
}
|
|
58071
58403
|
crushEvent = verbatimSpellings.get(normalized) ?? key;
|
|
58072
58404
|
verbatimSpellings.set(normalized, crushEvent);
|
|
58073
58405
|
}
|
|
@@ -58221,9 +58553,10 @@ var CrushHooks = class CrushHooks extends ToolHooks {
|
|
|
58221
58553
|
global
|
|
58222
58554
|
});
|
|
58223
58555
|
}
|
|
58224
|
-
toRulesyncHooks() {
|
|
58556
|
+
toRulesyncHooks({ logger } = {}) {
|
|
58225
58557
|
const hooks = crushHooksToCanonical(this.json[CRUSH_HOOKS_KEY]);
|
|
58226
58558
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
58559
|
+
logger,
|
|
58227
58560
|
hooks,
|
|
58228
58561
|
overrideKey: "crush"
|
|
58229
58562
|
}), null, 2) });
|
|
@@ -58320,7 +58653,7 @@ var CursorHooks = class CursorHooks extends ToolHooks {
|
|
|
58320
58653
|
static supportsPreserveUnowned() {
|
|
58321
58654
|
return true;
|
|
58322
58655
|
}
|
|
58323
|
-
toRulesyncHooks() {
|
|
58656
|
+
toRulesyncHooks({ logger } = {}) {
|
|
58324
58657
|
const content = this.getFileContent();
|
|
58325
58658
|
const parsed = JSON.parse(content);
|
|
58326
58659
|
const cursorHooks = parsed.hooks ?? {};
|
|
@@ -58334,6 +58667,7 @@ var CursorHooks = class CursorHooks extends ToolHooks {
|
|
|
58334
58667
|
}
|
|
58335
58668
|
const version = parsed.version ?? 1;
|
|
58336
58669
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
58670
|
+
logger,
|
|
58337
58671
|
hooks: canonicalHooks,
|
|
58338
58672
|
overrideKey: "cursor",
|
|
58339
58673
|
version
|
|
@@ -58351,6 +58685,22 @@ var CursorHooks = class CursorHooks extends ToolHooks {
|
|
|
58351
58685
|
};
|
|
58352
58686
|
// src/features/hooks/deepagents-hooks.ts
|
|
58353
58687
|
/**
|
|
58688
|
+
* deepagents-code 0.2.11+ spells the canonical `failClosed` as a per-handler
|
|
58689
|
+
* `onError: "continue" | "deny"`. Only `"deny"` changes behavior: a failed,
|
|
58690
|
+
* timed-out or invalid-output `PreToolUse` handler then denies the tool call.
|
|
58691
|
+
* `"continue"` is the default, so `false` is omitted; upstream ignores the
|
|
58692
|
+
* field on every other event, so a `true` there is dropped with a warning.
|
|
58693
|
+
* Older dcode versions ignore the field and keep failing open.
|
|
58694
|
+
* https://github.com/langchain-ai/deepagents/blob/main/libs/code/HOOKS.md
|
|
58695
|
+
*/
|
|
58696
|
+
const DEEPAGENTS_KEYWORD_FIELDS = [{
|
|
58697
|
+
canonical: "failClosed",
|
|
58698
|
+
tool: "onError",
|
|
58699
|
+
trueValue: "deny",
|
|
58700
|
+
falseValue: "continue",
|
|
58701
|
+
events: /* @__PURE__ */ new Set(["preToolUse"])
|
|
58702
|
+
}];
|
|
58703
|
+
/**
|
|
58354
58704
|
* Convert the canonical hooks config to the deepagents Hooks v2 document.
|
|
58355
58705
|
*
|
|
58356
58706
|
* ```json
|
|
@@ -58360,7 +58710,8 @@ var CursorHooks = class CursorHooks extends ToolHooks {
|
|
|
58360
58710
|
* Definitions sharing an event and matcher land in one group, preserving their
|
|
58361
58711
|
* authored order — upstream runs a group's handlers in sequence.
|
|
58362
58712
|
*/
|
|
58363
|
-
function canonicalToDeepagentsHooks(config) {
|
|
58713
|
+
function canonicalToDeepagentsHooks(config, logger) {
|
|
58714
|
+
const warn = warnOnce(logger);
|
|
58364
58715
|
const supported = new Set(DEEPAGENTS_HOOK_EVENTS);
|
|
58365
58716
|
const effectiveHooks = {
|
|
58366
58717
|
...config.hooks,
|
|
@@ -58383,6 +58734,13 @@ function canonicalToDeepagentsHooks(config) {
|
|
|
58383
58734
|
};
|
|
58384
58735
|
if (def.timeout !== void 0 && def.timeout !== null && def.timeout > 0) handler.timeout = def.timeout;
|
|
58385
58736
|
if (def.statusMessage !== void 0 && def.statusMessage !== null) handler.statusMessage = def.statusMessage;
|
|
58737
|
+
Object.assign(handler, emitKeywordFields({
|
|
58738
|
+
def,
|
|
58739
|
+
hookType: "command",
|
|
58740
|
+
eventName: canonicalEvent,
|
|
58741
|
+
fields: DEEPAGENTS_KEYWORD_FIELDS,
|
|
58742
|
+
warn
|
|
58743
|
+
}));
|
|
58386
58744
|
const matcher = def.matcher !== void 0 && def.matcher !== null && def.matcher !== "" ? def.matcher : void 0;
|
|
58387
58745
|
const groups = hooks[deepagentsEvent] ??= [];
|
|
58388
58746
|
const group = groups.find((candidate) => candidate.matcher === matcher);
|
|
@@ -58398,7 +58756,8 @@ function canonicalToDeepagentsHooks(config) {
|
|
|
58398
58756
|
/**
|
|
58399
58757
|
* Convert the Hooks v2 document back to the canonical hooks record.
|
|
58400
58758
|
*/
|
|
58401
|
-
function deepagentsToCanonicalHooks(hooks) {
|
|
58759
|
+
function deepagentsToCanonicalHooks(hooks, logger) {
|
|
58760
|
+
const warn = warnOnce(logger);
|
|
58402
58761
|
const canonical = {};
|
|
58403
58762
|
for (const [deepagentsEvent, groups] of Object.entries(hooks)) {
|
|
58404
58763
|
const canonicalEvent = lookupOwn({
|
|
@@ -58417,6 +58776,19 @@ function deepagentsToCanonicalHooks(hooks) {
|
|
|
58417
58776
|
if (typeof group.matcher === "string" && group.matcher !== "") def.matcher = group.matcher;
|
|
58418
58777
|
if (typeof handler.timeout === "number") def.timeout = handler.timeout;
|
|
58419
58778
|
if (typeof handler.statusMessage === "string") def.statusMessage = handler.statusMessage;
|
|
58779
|
+
let keywordSource = handler;
|
|
58780
|
+
if (canonicalEvent === "preToolUse" && handler.onError !== void 0 && handler.onError !== "deny" && handler.onError !== "continue") {
|
|
58781
|
+
warn(`Dropping "onError" from an imported "command" hook on "${canonicalEvent}": ${quoteValueForWarning(handler.onError)} is not "deny" or "continue", so the hook is imported without "failClosed" and fails open on the next generate.`);
|
|
58782
|
+
const { onError: _dropped, ...rest } = handler;
|
|
58783
|
+
keywordSource = rest;
|
|
58784
|
+
}
|
|
58785
|
+
Object.assign(def, importKeywordFields({
|
|
58786
|
+
h: keywordSource,
|
|
58787
|
+
hookType: "command",
|
|
58788
|
+
eventName: canonicalEvent,
|
|
58789
|
+
fields: DEEPAGENTS_KEYWORD_FIELDS,
|
|
58790
|
+
warn
|
|
58791
|
+
}));
|
|
58420
58792
|
(canonical[canonicalEvent] ??= []).push(def);
|
|
58421
58793
|
}
|
|
58422
58794
|
}
|
|
@@ -58475,8 +58847,8 @@ var DeepagentsHooks = class DeepagentsHooks extends ToolHooks {
|
|
|
58475
58847
|
global
|
|
58476
58848
|
});
|
|
58477
58849
|
}
|
|
58478
|
-
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false }) {
|
|
58479
|
-
const hooks = canonicalToDeepagentsHooks(rulesyncHooks.getJson());
|
|
58850
|
+
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false, logger }) {
|
|
58851
|
+
const hooks = canonicalToDeepagentsHooks(rulesyncHooks.getJson(), logger);
|
|
58480
58852
|
const fileContent = JSON.stringify({ hooks }, null, 2);
|
|
58481
58853
|
const paths = DeepagentsHooks.getSettablePaths({ global });
|
|
58482
58854
|
return new DeepagentsHooks({
|
|
@@ -58487,19 +58859,20 @@ var DeepagentsHooks = class DeepagentsHooks extends ToolHooks {
|
|
|
58487
58859
|
validate
|
|
58488
58860
|
});
|
|
58489
58861
|
}
|
|
58490
|
-
toRulesyncHooks() {
|
|
58862
|
+
toRulesyncHooks({ logger } = {}) {
|
|
58491
58863
|
const parsed = this.parseFileContentOrThrow({
|
|
58492
58864
|
displayName: "deepagents",
|
|
58493
58865
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
58494
58866
|
});
|
|
58495
58867
|
const rawHooks = isRecord(parsed) ? parsed.hooks : void 0;
|
|
58496
|
-
const hooks = Array.isArray(rawHooks) ? deepagentsLegacyToCanonicalHooks(rawHooks) : isRecord(rawHooks) ? deepagentsToCanonicalHooks(rawHooks) : {};
|
|
58868
|
+
const hooks = Array.isArray(rawHooks) ? deepagentsLegacyToCanonicalHooks(rawHooks) : isRecord(rawHooks) ? deepagentsToCanonicalHooks(rawHooks, logger) : {};
|
|
58497
58869
|
return this.toRulesyncHooksDefault({
|
|
58498
58870
|
outputRoot: getDeepagentsRulesyncOutputRoot({
|
|
58499
58871
|
nativeOutputRoot: this.outputRoot,
|
|
58500
58872
|
global: this.global
|
|
58501
58873
|
}),
|
|
58502
58874
|
fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
58875
|
+
logger,
|
|
58503
58876
|
hooks,
|
|
58504
58877
|
overrideKey: "deepagents"
|
|
58505
58878
|
}), null, 2)
|
|
@@ -58605,6 +58978,7 @@ var DevinHooks = class extends ToolHooks {
|
|
|
58605
58978
|
logger
|
|
58606
58979
|
});
|
|
58607
58980
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
58981
|
+
logger,
|
|
58608
58982
|
hooks,
|
|
58609
58983
|
overrideKey: "devin"
|
|
58610
58984
|
}), null, 2) });
|
|
@@ -58830,6 +59204,7 @@ var FactorydroidHooks = class FactorydroidHooks extends ToolHooks {
|
|
|
58830
59204
|
logger
|
|
58831
59205
|
});
|
|
58832
59206
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59207
|
+
logger,
|
|
58833
59208
|
hooks,
|
|
58834
59209
|
overrideKey: "factorydroid"
|
|
58835
59210
|
}), null, 2) });
|
|
@@ -58914,9 +59289,10 @@ var FirebenderHooks = class FirebenderHooks extends ToolHooks {
|
|
|
58914
59289
|
static supportsPreserveUnowned() {
|
|
58915
59290
|
return true;
|
|
58916
59291
|
}
|
|
58917
|
-
toRulesyncHooks() {
|
|
59292
|
+
toRulesyncHooks({ logger } = {}) {
|
|
58918
59293
|
const parsed = JSON.parse(this.getFileContent());
|
|
58919
59294
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59295
|
+
logger,
|
|
58920
59296
|
hooks: parsed.hooks ?? {},
|
|
58921
59297
|
overrideKey: "firebender",
|
|
58922
59298
|
version: parsed.version ?? 1
|
|
@@ -58984,6 +59360,7 @@ var GitlabduoHooks = class GitlabduoHooks extends ToolHooks {
|
|
|
58984
59360
|
logger
|
|
58985
59361
|
});
|
|
58986
59362
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59363
|
+
logger,
|
|
58987
59364
|
hooks,
|
|
58988
59365
|
overrideKey: "gitlabduo"
|
|
58989
59366
|
}), null, 2) });
|
|
@@ -59053,6 +59430,7 @@ var GooseHooks = class GooseHooks extends ToolHooks {
|
|
|
59053
59430
|
logger
|
|
59054
59431
|
});
|
|
59055
59432
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59433
|
+
logger,
|
|
59056
59434
|
hooks,
|
|
59057
59435
|
overrideKey: "goose"
|
|
59058
59436
|
}), null, 2) });
|
|
@@ -59135,6 +59513,7 @@ var GrokcliHooks = class GrokcliHooks extends ToolHooks {
|
|
|
59135
59513
|
logger
|
|
59136
59514
|
});
|
|
59137
59515
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59516
|
+
logger,
|
|
59138
59517
|
hooks,
|
|
59139
59518
|
overrideKey: "grokcli"
|
|
59140
59519
|
}), null, 2) });
|
|
@@ -59428,7 +59807,7 @@ var HermesagentHooks = class HermesagentHooks extends ToolHooks {
|
|
|
59428
59807
|
}) }
|
|
59429
59808
|
});
|
|
59430
59809
|
}
|
|
59431
|
-
toRulesyncHooks() {
|
|
59810
|
+
toRulesyncHooks({ logger } = {}) {
|
|
59432
59811
|
const hooks = hermesHooksToCanonical(parseSharedConfig({
|
|
59433
59812
|
format: "yaml",
|
|
59434
59813
|
fileContent: this.getFileContent()
|
|
@@ -59439,6 +59818,7 @@ var HermesagentHooks = class HermesagentHooks extends ToolHooks {
|
|
|
59439
59818
|
global: this.global
|
|
59440
59819
|
}),
|
|
59441
59820
|
fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59821
|
+
logger,
|
|
59442
59822
|
hooks,
|
|
59443
59823
|
overrideKey: "hermesagent"
|
|
59444
59824
|
}), null, 2)
|
|
@@ -59468,13 +59848,20 @@ const JUNIE_CONVERTER_CONFIG = {
|
|
|
59468
59848
|
projectDirVar: "",
|
|
59469
59849
|
supportedHookTypes: /* @__PURE__ */ new Set(["command"]),
|
|
59470
59850
|
noMatcherEvents: /* @__PURE__ */ new Set(["beforeSubmitPrompt", "stop"]),
|
|
59471
|
-
booleanPassthroughFields: [
|
|
59472
|
-
|
|
59473
|
-
|
|
59474
|
-
|
|
59475
|
-
|
|
59476
|
-
|
|
59477
|
-
|
|
59851
|
+
booleanPassthroughFields: [
|
|
59852
|
+
{
|
|
59853
|
+
canonical: "failClosed",
|
|
59854
|
+
tool: "blockOnError"
|
|
59855
|
+
},
|
|
59856
|
+
{
|
|
59857
|
+
canonical: "async",
|
|
59858
|
+
tool: "async"
|
|
59859
|
+
},
|
|
59860
|
+
{
|
|
59861
|
+
canonical: "strictJsonOutput",
|
|
59862
|
+
tool: "strictJsonOutput"
|
|
59863
|
+
}
|
|
59864
|
+
]
|
|
59478
59865
|
};
|
|
59479
59866
|
var JunieHooks = class JunieHooks extends ToolHooks {
|
|
59480
59867
|
isDeletable() {
|
|
@@ -59526,6 +59913,7 @@ var JunieHooks = class JunieHooks extends ToolHooks {
|
|
|
59526
59913
|
logger
|
|
59527
59914
|
});
|
|
59528
59915
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
59916
|
+
logger,
|
|
59529
59917
|
hooks,
|
|
59530
59918
|
overrideKey: "junie"
|
|
59531
59919
|
}), null, 2) });
|
|
@@ -59664,33 +60052,255 @@ const SHELL_EVENT_TOOL_GATES = {
|
|
|
59664
60052
|
}
|
|
59665
60053
|
};
|
|
59666
60054
|
/**
|
|
59667
|
-
* Canonical events whose command receives
|
|
59668
|
-
* stdin
|
|
59669
|
-
*
|
|
59670
|
-
*
|
|
59671
|
-
*
|
|
59672
|
-
* protection example in the plugins doc).
|
|
59673
|
-
*
|
|
59674
|
-
* The payload mirrors Claude Code's `PreToolUse` input: `hook_event_name`,
|
|
59675
|
-
* `session_id` (`input.sessionID`), `tool_use_id` (`input.callID`),
|
|
59676
|
-
* `tool_name` (the raw OpenCode tool name — `bash`, `edit`, `<server>_<tool>`
|
|
59677
|
-
* for MCP — the same subject a `matcher` is tested against), `tool_input`
|
|
59678
|
-
* (`output.args`) and `cwd` (the plugin context's `directory`, falling back to
|
|
59679
|
-
* `process.cwd()`). It is serialized lazily, on the first handler whose
|
|
59680
|
-
* matcher matches, so a tool call no hook applies to pays nothing for it.
|
|
59681
|
-
*
|
|
59682
|
-
* Bun Shell has no stdin option on a command and rejects redirections on a
|
|
59683
|
-
* subshell, so the payload is piped in by the shell's builtin `echo`
|
|
59684
|
-
* (`echo ${payload} | <command>`); Bun escapes the interpolated value, so the
|
|
59685
|
-
* payload never reaches the shell as syntax. The pipe feeds the first
|
|
59686
|
-
* pipeline of the command — a compound `a && b` or `a; b` gives the payload
|
|
59687
|
-
* to `a` only, so multi-step guards belong in a script.
|
|
60055
|
+
* Canonical events whose command receives Claude Code's JSON input for the
|
|
60056
|
+
* event on stdin (every other command gets an empty stdin), with the fields
|
|
60057
|
+
* besides `hook_event_name` and `cwd`. `tool_name` is the raw OpenCode tool
|
|
60058
|
+
* name, the subject a `matcher` is tested against. A payload is serialized
|
|
60059
|
+
* lazily, once per invocation, by the first handler that runs.
|
|
59688
60060
|
*
|
|
59689
60061
|
* @see https://opencode.ai/docs/plugins/
|
|
59690
60062
|
* @see https://bun.sh/docs/runtime/shell
|
|
59691
60063
|
* @see https://code.claude.com/docs/en/hooks
|
|
59692
60064
|
*/
|
|
59693
|
-
const
|
|
60065
|
+
const STDIN_PAYLOADS = {
|
|
60066
|
+
preToolUse: {
|
|
60067
|
+
name: "PreToolUse",
|
|
60068
|
+
fields: [
|
|
60069
|
+
"session_id: input.sessionID",
|
|
60070
|
+
"tool_use_id: input.callID",
|
|
60071
|
+
"tool_name: input.tool",
|
|
60072
|
+
"tool_input: output?.args"
|
|
60073
|
+
]
|
|
60074
|
+
},
|
|
60075
|
+
postToolUse: {
|
|
60076
|
+
name: "PostToolUse",
|
|
60077
|
+
fields: [
|
|
60078
|
+
"session_id: input.sessionID",
|
|
60079
|
+
"tool_use_id: input.callID",
|
|
60080
|
+
"tool_name: input.tool",
|
|
60081
|
+
"tool_input: input.args",
|
|
60082
|
+
"tool_response: output"
|
|
60083
|
+
]
|
|
60084
|
+
},
|
|
60085
|
+
stop: {
|
|
60086
|
+
name: "Stop",
|
|
60087
|
+
fields: ["session_id: event.properties?.sessionID"]
|
|
60088
|
+
}
|
|
60089
|
+
};
|
|
60090
|
+
/**
|
|
60091
|
+
* V1 hooks that run before the action they belong to — every named hook but
|
|
60092
|
+
* `tool.execute.after`: like the Bun Shell call earlier versions emitted, a
|
|
60093
|
+
* failing command throws there, which aborts the action. Everywhere else a
|
|
60094
|
+
* failure is only logged.
|
|
60095
|
+
*/
|
|
60096
|
+
const BLOCKING_HOOKS = new Set(Object.keys(NAMED_HOOK_MATCHER_SUBJECTS).filter((hook) => hook !== "tool.execute.after"));
|
|
60097
|
+
/**
|
|
60098
|
+
* Helpers of every plugin with a handler. Bun Shell cannot give a command a
|
|
60099
|
+
* stdin of its own, and one that inherits OpenCode's (the TTY, or the pipe of
|
|
60100
|
+
* `opencode serve --stdio`) blocks forever once any part of it reads stdin. So
|
|
60101
|
+
* `__rulesyncRunCommand` runs the command in the host's own Bun-compiled binary
|
|
60102
|
+
* as the Bun CLI (`BUN_BE_BUN=1`, without the project's `.env`): `exec` runs it
|
|
60103
|
+
* with the same Bun Shell, parsing the text the template literal of earlier
|
|
60104
|
+
* versions held, with the payload as stdin. The script clears `BUN_BE_BUN` for
|
|
60105
|
+
* the programs the command starts: Bun Shell has no `unset`, so it exports an
|
|
60106
|
+
* empty value, which Bun treats as unset (only a non-empty value other than
|
|
60107
|
+
* `0` makes a Bun-compiled binary act as the Bun CLI). A host without the Bun
|
|
60108
|
+
* CLI fails the probe and falls back to Bun Shell, piping the payload into the
|
|
60109
|
+
* first command only (a probe still running after 10 s is killed; it, a
|
|
60110
|
+
* failing one or one that prints anything but `rulesync` means no Bun CLI for
|
|
60111
|
+
* 5 minutes). Ordinary commands write to the host's stdout and stderr, as Bun
|
|
60112
|
+
* Shell echoed them; a `preToolUse` command's are read, 1 MiB each kept (more
|
|
60113
|
+
* stdout denies; on the Bun Shell fallback the whole output is buffered before
|
|
60114
|
+
* that check). Output
|
|
60115
|
+
* pipes a background process keeps open are read for 1 s after the command
|
|
60116
|
+
* exits; what arrived by then is kept, and the reads are then cancelled, as
|
|
60117
|
+
* they are at a timeout. The OpenCode 1.x-style `event` hooks (`inProcess`)
|
|
60118
|
+
* take the Bun Shell path too: starting the child takes about
|
|
60119
|
+
* 250 ms, and OpenCode 1.x's one-shot `opencode run` exits right after
|
|
60120
|
+
* `session.idle`, before a `stop` command run that way could start.
|
|
60121
|
+
* A command that outlives its timeout (counted from its start) resolves to
|
|
60122
|
+
* `null` and is killed. On POSIX its process tree, read from procfs or else
|
|
60123
|
+
* `ps`, gets SIGTERM and, 2 s later, SIGKILL for each of those processes still
|
|
60124
|
+
* alive (same start time, wherever it was reparented) and what it started
|
|
60125
|
+
* since; the command's own process is signalled through its Bun handle only,
|
|
60126
|
+
* so a PID reused after it exited is never signalled. The command keeps
|
|
60127
|
+
* OpenCode's process group, so it keeps the terminal
|
|
60128
|
+
* and Ctrl-C, but a process that left the tree before the timeout (orphaned or
|
|
60129
|
+
* `setsid`) escapes, and without procfs and `ps` only
|
|
60130
|
+
* the command's own process is killed (logged). The pending SIGKILL keeps the
|
|
60131
|
+
* host alive for those 2 s. On Windows, `taskkill /T /F` ends the tree as
|
|
60132
|
+
* linked by parent PID at that moment, then the child is ended through its
|
|
60133
|
+
* handle; a process whose parent had already exited is not reached. Bun Shell
|
|
60134
|
+
* (the fallback) cannot kill: it stops waiting, and the command keeps running.
|
|
60135
|
+
* On a failure, `__rulesyncRunHook` throws in a blocking hook or logs it
|
|
60136
|
+
* otherwise.
|
|
60137
|
+
*
|
|
60138
|
+
* @see https://bun.sh/docs/bundler/executables
|
|
60139
|
+
*/
|
|
60140
|
+
function buildRunHelperLinesFor(cwdExpression) {
|
|
60141
|
+
const spawn = (script, stdin, stdout = "\"pipe\"", stderr = stdout) => `Bun.spawn([process.execPath, "--no-env-file", "exec", ${script}], { cwd: ${cwdExpression}, env: { ...process.env, BUN_BE_BUN: "1" }, stdin: ${stdin}, stdout: ${stdout}, stderr: ${stderr}, windowsHide: true })`;
|
|
60142
|
+
return [
|
|
60143
|
+
"const __rulesyncRead = (stream, limit = 1048576) => {",
|
|
60144
|
+
" const chunks = [];",
|
|
60145
|
+
" let size = 0;",
|
|
60146
|
+
" const reader = stream.getReader();",
|
|
60147
|
+
" let reading = true;",
|
|
60148
|
+
" const done = (async () => {",
|
|
60149
|
+
" for (let read; reading && !(read = await reader.read()).done; ) {",
|
|
60150
|
+
" if (reading && (size += read.value.length) <= limit) chunks.push(read.value);",
|
|
60151
|
+
" }",
|
|
60152
|
+
" })().catch(() => {});",
|
|
60153
|
+
" const stop = () => {",
|
|
60154
|
+
" if (reading) (reading = false), reader.cancel().catch(() => {});",
|
|
60155
|
+
" };",
|
|
60156
|
+
" return { done, stop, text: () => Buffer.concat(chunks).toString(), overflow: () => size > limit };",
|
|
60157
|
+
"};",
|
|
60158
|
+
"let __rulesyncCanExec;",
|
|
60159
|
+
"let __rulesyncRetryAt = 0;",
|
|
60160
|
+
"// pid -> [ppid, start time], from procfs or else ps; a reused PID gets a new start time.",
|
|
60161
|
+
"const __rulesyncProcesses = () => {",
|
|
60162
|
+
" const processes = new Map();",
|
|
60163
|
+
" try {",
|
|
60164
|
+
" const fs = require(\"node:fs\");",
|
|
60165
|
+
" for (const pid of fs.readdirSync(\"/proc\").filter((name) => /^\\d+$/.test(name))) {",
|
|
60166
|
+
" try {",
|
|
60167
|
+
" const stat = fs.readFileSync(\"/proc/\" + pid + \"/stat\", \"utf8\");",
|
|
60168
|
+
" const fields = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \");",
|
|
60169
|
+
" processes.set(pid, [fields[1], fields[19]]);",
|
|
60170
|
+
" } catch {}",
|
|
60171
|
+
" }",
|
|
60172
|
+
" if (processes.size > 0) return processes;",
|
|
60173
|
+
" } catch {}",
|
|
60174
|
+
" try {",
|
|
60175
|
+
" // The C locale keeps `lstart` in one format; it is compared as text, never parsed.",
|
|
60176
|
+
" const env = { ...process.env, LC_ALL: \"C\", LANG: \"C\" };",
|
|
60177
|
+
" const ps = Bun.spawnSync([\"ps\", \"-A\", \"-o\", \"pid=,ppid=,lstart=\"], { env, timeout: 5000 });",
|
|
60178
|
+
" if (ps.exitCode === 0) {",
|
|
60179
|
+
" for (const line of ps.stdout.toString().trim().split(\"\\n\")) {",
|
|
60180
|
+
" const [pid, ppid, ...started] = line.trim().split(/\\s+/);",
|
|
60181
|
+
" processes.set(pid, [ppid, started.join(\" \")]);",
|
|
60182
|
+
" }",
|
|
60183
|
+
" return processes;",
|
|
60184
|
+
" }",
|
|
60185
|
+
" } catch {}",
|
|
60186
|
+
" console.error(\"[rulesync-hooks] neither /proc nor ps is available: only the hook process is killed\");",
|
|
60187
|
+
"};",
|
|
60188
|
+
"const __rulesyncTree = (roots, processes) => {",
|
|
60189
|
+
" const tree = [...roots];",
|
|
60190
|
+
" for (let size = -1; size !== tree.length; ) {",
|
|
60191
|
+
" size = tree.length;",
|
|
60192
|
+
" for (const [pid, [ppid]] of processes ?? []) if (tree.includes(ppid) && !tree.includes(pid)) tree.push(pid);",
|
|
60193
|
+
" }",
|
|
60194
|
+
" return tree;",
|
|
60195
|
+
"};",
|
|
60196
|
+
"// The child itself is signalled only through its handle, a no-op once Bun has reaped it, so a",
|
|
60197
|
+
"// reused PID is never signalled; its descendants only while it is running (not reaped, its PID",
|
|
60198
|
+
"// cannot be reused), and in the SIGKILL round only with both snapshots: the first snapshot's",
|
|
60199
|
+
"// descendants that are the same processes (same start time), and what they and the child,",
|
|
60200
|
+
"// if it ran across the second snapshot, have started since.",
|
|
60201
|
+
"const __rulesyncKillTree = (proc) => {",
|
|
60202
|
+
" const kill = (pids, signal) => pids.forEach((pid) => { try { process.kill(Number(pid), signal); } catch {} });",
|
|
60203
|
+
" const running = () => proc.exitCode === null && proc.signalCode === null;",
|
|
60204
|
+
" const root = String(proc.pid);",
|
|
60205
|
+
" const before = running() ? __rulesyncProcesses() : undefined;",
|
|
60206
|
+
" const first = before && running() ? __rulesyncTree([root], before).slice(1) : [];",
|
|
60207
|
+
" proc.kill(\"SIGTERM\");",
|
|
60208
|
+
" kill(first, \"SIGTERM\");",
|
|
60209
|
+
" setTimeout(() => {",
|
|
60210
|
+
" const alive = running();",
|
|
60211
|
+
" const now = before && __rulesyncProcesses();",
|
|
60212
|
+
" if (!now) return proc.kill(\"SIGKILL\");",
|
|
60213
|
+
" // Every first-snapshot descendant that is still the same process, wherever it was",
|
|
60214
|
+
" // reparented (to PID 1 or a subreaper), and the child if it survived SIGTERM, with what",
|
|
60215
|
+
" // they have started since. The child is killed first, so it starts nothing more.",
|
|
60216
|
+
" const same = first.filter((pid) => now.get(pid)?.[1] === before.get(pid)?.[1]);",
|
|
60217
|
+
" const own = alive && running() && now.get(root)?.[1] === before.get(root)?.[1];",
|
|
60218
|
+
" proc.kill(\"SIGKILL\");",
|
|
60219
|
+
" kill(__rulesyncTree(own ? [root, ...same] : same, now).filter((pid) => pid !== root), \"SIGKILL\");",
|
|
60220
|
+
" }, 2000);",
|
|
60221
|
+
"};",
|
|
60222
|
+
"// `proc.kill()` is TerminateProcess on the child alone. A libuv program (node) that dies takes",
|
|
60223
|
+
"// the children it spawned along through its job object, but not ones started through another",
|
|
60224
|
+
"// program (cmd.exe) or detached. taskkill /T ends the tree as linked by parent PID at that",
|
|
60225
|
+
"// moment; System32's copy, so a taskkill earlier on PATH is never run.",
|
|
60226
|
+
"const __rulesyncKillWindowsTree = (proc) => {",
|
|
60227
|
+
" if (proc.exitCode === null && proc.signalCode === null) {",
|
|
60228
|
+
" const taskkill = (process.env.SystemRoot ?? \"C:\\\\Windows\") + \"\\\\System32\\\\taskkill.exe\";",
|
|
60229
|
+
" try {",
|
|
60230
|
+
" Bun.spawnSync([taskkill, \"/T\", \"/F\", \"/PID\", String(proc.pid)], { stdout: \"ignore\", stderr: \"ignore\", windowsHide: true, timeout: 5000 });",
|
|
60231
|
+
" } catch {}",
|
|
60232
|
+
" }",
|
|
60233
|
+
" proc.kill();",
|
|
60234
|
+
"};",
|
|
60235
|
+
"const __rulesyncRunCommand = async ({ command, input, seconds, inProcess = false, echo = false }) => {",
|
|
60236
|
+
" // A probe that printed `rulesync` is kept; one past its deadline, failing or printing",
|
|
60237
|
+
" // anything else means no Bun CLI for 5 minutes; one that threw is dropped, so the next",
|
|
60238
|
+
" // command probes again.",
|
|
60239
|
+
" if (!inProcess && (__rulesyncCanExec === undefined || (__rulesyncRetryAt && Date.now() >= __rulesyncRetryAt))) {",
|
|
60240
|
+
" __rulesyncRetryAt = 0;",
|
|
60241
|
+
" const probing = (__rulesyncCanExec = (async () => {",
|
|
60242
|
+
` const probe = ${spawn("\"echo rulesync\"", "\"ignore\"", "\"pipe\"", "\"ignore\"")};`,
|
|
60243
|
+
" const output = __rulesyncRead(probe.stdout, 1024);",
|
|
60244
|
+
" let timer;",
|
|
60245
|
+
" // Settles on its own, even if the probe ignores the kill or a process holds its stdout.",
|
|
60246
|
+
" const deadline = new Promise((resolve) => (timer = setTimeout(resolve, 10000, null)));",
|
|
60247
|
+
" const exited = Promise.all([probe.exited, output.done]).then(([code]) => code);",
|
|
60248
|
+
" const exitCode = await Promise.race([exited, deadline]).finally(() => clearTimeout(timer));",
|
|
60249
|
+
" if (exitCode === null) probe.kill(\"SIGKILL\"), output.stop();",
|
|
60250
|
+
" const found = exitCode === 0 && output.text().trim() === \"rulesync\";",
|
|
60251
|
+
" if (!found) __rulesyncRetryAt = Date.now() + 300000;",
|
|
60252
|
+
" return found;",
|
|
60253
|
+
" })().catch(() => {",
|
|
60254
|
+
" if (__rulesyncCanExec === probing) __rulesyncCanExec = undefined;",
|
|
60255
|
+
" return false;",
|
|
60256
|
+
" }));",
|
|
60257
|
+
" }",
|
|
60258
|
+
" let timer;",
|
|
60259
|
+
" const timeout = () => new Promise((resolve) => (timer = setTimeout(resolve, seconds * 1000, null)));",
|
|
60260
|
+
" if (inProcess || !(await __rulesyncCanExec)) {",
|
|
60261
|
+
` const run = Bun.$\`echo \${input} | \${{ raw: command }}\`.cwd(${cwdExpression}).nothrow();`,
|
|
60262
|
+
" const result = await Promise.race([echo ? run : run.quiet(), timeout()]).finally(() => clearTimeout(timer));",
|
|
60263
|
+
" if (!result || echo) return result && { exitCode: result.exitCode };",
|
|
60264
|
+
" const { exitCode, stdout, stderr } = result;",
|
|
60265
|
+
" return { exitCode, stdout: stdout.toString(), stderr: stderr.toString(), overflow: stdout.length > 1048576 };",
|
|
60266
|
+
" }",
|
|
60267
|
+
" // An ordinary command writes to the host's stdout and stderr; a preToolUse one is read.",
|
|
60268
|
+
" const output = echo ? \"inherit\" : \"pipe\";",
|
|
60269
|
+
` const proc = ${spawn("\"export BUN_BE_BUN=\\n\" + command", "new TextEncoder().encode(input + \"\\n\")", "output")};`,
|
|
60270
|
+
" const [stdout, stderr] = echo ? [] : [__rulesyncRead(proc.stdout), __rulesyncRead(proc.stderr)];",
|
|
60271
|
+
" const exitCode = await Promise.race([proc.exited, timeout()]).finally(() => clearTimeout(timer));",
|
|
60272
|
+
" if (exitCode === null) {",
|
|
60273
|
+
" stdout?.stop(), stderr?.stop();",
|
|
60274
|
+
" if (process.platform === \"win32\") __rulesyncKillWindowsTree(proc);",
|
|
60275
|
+
" else __rulesyncKillTree(proc);",
|
|
60276
|
+
" return null;",
|
|
60277
|
+
" }",
|
|
60278
|
+
" if (echo) return { exitCode };",
|
|
60279
|
+
" await Promise.race([Promise.all([stdout.done, stderr.done]), Bun.sleep(1000)]);",
|
|
60280
|
+
" stdout.stop(), stderr.stop();",
|
|
60281
|
+
" return { exitCode, stdout: stdout.text(), stderr: stderr.text(), overflow: stdout.overflow() };",
|
|
60282
|
+
"};",
|
|
60283
|
+
"const __rulesyncRunHook = async ({ label, command, input, blocking, seconds, inProcess = false }) => {",
|
|
60284
|
+
" let result;",
|
|
60285
|
+
" try {",
|
|
60286
|
+
" result = await __rulesyncRunCommand({ command, input, seconds, inProcess, echo: true });",
|
|
60287
|
+
" } catch (error) {",
|
|
60288
|
+
" if (blocking) throw error;",
|
|
60289
|
+
" console.error(\"[rulesync-hooks] \" + label + \" hook failed:\", error);",
|
|
60290
|
+
" return;",
|
|
60291
|
+
" }",
|
|
60292
|
+
" if (result === null) {",
|
|
60293
|
+
" const message = \"[rulesync-hooks] \" + label + \" hook timed out after \" + seconds + \"s\";",
|
|
60294
|
+
" if (blocking) throw new Error(message);",
|
|
60295
|
+
" return console.error(message);",
|
|
60296
|
+
" }",
|
|
60297
|
+
" if (result.exitCode === 0) return;",
|
|
60298
|
+
" const message = \"[rulesync-hooks] \" + label + \" hook exited with code \" + result.exitCode;",
|
|
60299
|
+
" if (blocking) throw new Error(message);",
|
|
60300
|
+
" console.error(message);",
|
|
60301
|
+
"};"
|
|
60302
|
+
];
|
|
60303
|
+
}
|
|
59694
60304
|
/**
|
|
59695
60305
|
* Name of the helper the generated plugin defines when a `preToolUse` handler
|
|
59696
60306
|
* is present. It interprets the command's result like Claude Code does for a
|
|
@@ -59700,7 +60310,10 @@ const STDIN_PAYLOAD_EVENTS = { preToolUse: "PreToolUse" };
|
|
|
59700
60310
|
* - exit code 0 with JSON stdout whose `hookSpecificOutput.permissionDecision`
|
|
59701
60311
|
* is `"deny"` → deny, with `permissionDecisionReason` as the reason;
|
|
59702
60312
|
* - exit code 0 otherwise → allow;
|
|
59703
|
-
* - any other non-zero exit → deny too, with stderr or the exit code
|
|
60313
|
+
* - any other non-zero exit → deny too, with stderr or the exit code;
|
|
60314
|
+
* - more than 1 MiB of stdout → deny, without parsing it;
|
|
60315
|
+
* - a command past its timeout → deny, like a non-zero exit, unless the hook
|
|
60316
|
+
* sets `failClosed: false`, which allows the call and logs the timeout.
|
|
59704
60317
|
*
|
|
59705
60318
|
* Every reason goes through the `sanitizeBlockReason` helper shared with the
|
|
59706
60319
|
* Pi extension (`hook-block-reason.ts`): control and format characters are
|
|
@@ -59716,7 +60329,12 @@ const PRE_TOOL_USE_RESULT_HELPER = "__rulesyncEnforcePreToolUseResult";
|
|
|
59716
60329
|
const PRE_TOOL_USE_RESULT_HELPER_LINES = [
|
|
59717
60330
|
...buildBlockReasonSanitizerLines({ typed: false }),
|
|
59718
60331
|
"",
|
|
59719
|
-
`const ${PRE_TOOL_USE_RESULT_HELPER} = (result) => {`,
|
|
60332
|
+
`const ${PRE_TOOL_USE_RESULT_HELPER} = (result, failClosed) => {`,
|
|
60333
|
+
" if (result === null) {",
|
|
60334
|
+
" if (failClosed !== false) throw new Error(\"preToolUse hook timed out.\");",
|
|
60335
|
+
" return console.error(\"[rulesync-hooks] preToolUse hook timed out\");",
|
|
60336
|
+
" }",
|
|
60337
|
+
" if (result.overflow) throw new Error(\"preToolUse hook wrote more than 1 MiB to stdout.\");",
|
|
59720
60338
|
" const stderr = result.stderr.toString();",
|
|
59721
60339
|
" if (result.exitCode === 0) {",
|
|
59722
60340
|
" let parsed;",
|
|
@@ -59750,15 +60368,70 @@ function escapeForTemplateLiteral(command) {
|
|
|
59750
60368
|
function validateAndSanitizeMatcher(matcher) {
|
|
59751
60369
|
return sanitizeMatcherRegex(matcher).replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
59752
60370
|
}
|
|
59753
|
-
/**
|
|
60371
|
+
/**
|
|
60372
|
+
* A hook's `timeout` in seconds, Claude Code's default of 600 when it sets none,
|
|
60373
|
+
* capped at what `setTimeout` can wait (larger values fire at once), and its
|
|
60374
|
+
* `failClosed` as written: unset is not `false`.
|
|
60375
|
+
*/
|
|
60376
|
+
function hookTimingOf(def) {
|
|
60377
|
+
const timeout = def.timeout !== void 0 && def.timeout > 0 ? def.timeout : 600;
|
|
60378
|
+
return {
|
|
60379
|
+
timeout: Math.min(timeout, 2147483),
|
|
60380
|
+
failClosed: def.failClosed
|
|
60381
|
+
};
|
|
60382
|
+
}
|
|
60383
|
+
const FAIL_CLOSED_TOOL_LABELS = {
|
|
60384
|
+
kilo: "Kilo Code",
|
|
60385
|
+
mimocode: "MiMo Code",
|
|
60386
|
+
opencode: "OpenCode",
|
|
60387
|
+
opencodev1: "OpenCode V1"
|
|
60388
|
+
};
|
|
60389
|
+
/**
|
|
60390
|
+
* Canonical events other than `preToolUse` whose hook runs before its action in
|
|
60391
|
+
* every OpenCode-style plugin (V1 and V2): a failing or timed-out command always
|
|
60392
|
+
* aborts the action there. A test checks it against `BLOCKING_HOOKS` and the V2
|
|
60393
|
+
* generator's `isBlockingOpencodeV2Target`.
|
|
60394
|
+
*/
|
|
60395
|
+
const ALWAYS_BLOCKING_EVENTS = /* @__PURE__ */ new Set([
|
|
60396
|
+
"beforeShellExecution",
|
|
60397
|
+
"beforeSubmitPrompt",
|
|
60398
|
+
"preModelInvocation",
|
|
60399
|
+
"userPromptExpansion",
|
|
60400
|
+
"preCompact"
|
|
60401
|
+
]);
|
|
60402
|
+
/**
|
|
60403
|
+
* Warn about each `failClosed` the generated plugin ignores where it changes
|
|
60404
|
+
* the outcome: the plugin only reads it on `preToolUse`, to decide what a
|
|
60405
|
+
* timed-out command does. Elsewhere a hook that runs before its action always
|
|
60406
|
+
* fails on a timeout, so a `false` there is ignored (a `true` already holds),
|
|
60407
|
+
* and any other hook only logs it, so a `true` there is ignored (a `false`
|
|
60408
|
+
* already holds, like the other targets treat an omitted `false`).
|
|
60409
|
+
*/
|
|
60410
|
+
function warnIgnoredFailClosed({ config, supportedEvents, toolConfigKey, logger }) {
|
|
60411
|
+
const configHooks = {
|
|
60412
|
+
...config.hooks,
|
|
60413
|
+
...config[toolConfigKey]?.hooks
|
|
60414
|
+
};
|
|
60415
|
+
const plugin = `the generated ${FAIL_CLOSED_TOOL_LABELS[toolConfigKey]} plugin`;
|
|
60416
|
+
for (const [event, definitions] of Object.entries(configHooks)) {
|
|
60417
|
+
if (event === "preToolUse" || !supportedEvents.includes(event)) continue;
|
|
60418
|
+
const blocking = ALWAYS_BLOCKING_EVENTS.has(event);
|
|
60419
|
+
for (const def of definitions) {
|
|
60420
|
+
if (def.failClosed !== !blocking) continue;
|
|
60421
|
+
logger?.warn(blocking ? `failClosed: false on "${event}" hook will be ignored — ${plugin} always blocks the action when this hook fails or times out, and only supports failClosed on preToolUse` : `failClosed on "${event}" hook will be ignored — ${plugin} only supports failClosed on preToolUse`);
|
|
60422
|
+
}
|
|
60423
|
+
}
|
|
60424
|
+
}
|
|
60425
|
+
/** The per-canonical-event gates and payload every handler of it carries. */
|
|
59754
60426
|
function handlerExtrasFor(canonicalEvent) {
|
|
59755
60427
|
const shellGate = SHELL_EVENT_TOOL_GATES[canonicalEvent];
|
|
59756
60428
|
const propertyGate = GENERIC_EVENT_PROPERTY_GATES[canonicalEvent];
|
|
59757
|
-
const
|
|
60429
|
+
const payload = shellGate ? void 0 : STDIN_PAYLOADS[canonicalEvent];
|
|
59758
60430
|
return {
|
|
60431
|
+
event: canonicalEvent,
|
|
59759
60432
|
...shellGate ? { toolGate: shellGate.tool } : {},
|
|
59760
60433
|
...propertyGate ? { propertyGate } : {},
|
|
59761
|
-
...
|
|
60434
|
+
...payload ? { payload } : {}
|
|
59762
60435
|
};
|
|
59763
60436
|
}
|
|
59764
60437
|
/**
|
|
@@ -59771,7 +60444,8 @@ function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHand
|
|
|
59771
60444
|
const extras = handlerExtrasFor(canonicalEvent);
|
|
59772
60445
|
const toolEvent = shellGate?.toolEvent ?? eventMap[canonicalEvent];
|
|
59773
60446
|
if (!toolEvent) continue;
|
|
59774
|
-
const
|
|
60447
|
+
const isNamedHook = Object.hasOwn(NAMED_HOOK_MATCHER_SUBJECTS, toolEvent);
|
|
60448
|
+
const matcherSupported = !shellGate && isNamedHook && NAMED_HOOK_MATCHER_SUBJECTS[toolEvent] !== null;
|
|
59775
60449
|
const handlers = [];
|
|
59776
60450
|
for (const def of definitions) {
|
|
59777
60451
|
if ((def.type ?? "command") !== "command") continue;
|
|
@@ -59780,11 +60454,14 @@ function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHand
|
|
|
59780
60454
|
handlers.push({
|
|
59781
60455
|
command: def.command,
|
|
59782
60456
|
matcher: def.matcher ? def.matcher : void 0,
|
|
60457
|
+
blocking: BLOCKING_HOOKS.has(toolEvent),
|
|
60458
|
+
...hookTimingOf(def),
|
|
60459
|
+
inProcess: !isNamedHook,
|
|
59783
60460
|
...extras
|
|
59784
60461
|
});
|
|
59785
60462
|
}
|
|
59786
60463
|
if (handlers.length > 0) {
|
|
59787
|
-
const grouped =
|
|
60464
|
+
const grouped = isNamedHook ? namedEventHandlers : genericEventHandlers;
|
|
59788
60465
|
const existing = grouped[toolEvent];
|
|
59789
60466
|
if (existing) existing.push(...handlers);
|
|
59790
60467
|
else grouped[toolEvent] = handlers;
|
|
@@ -59800,13 +60477,17 @@ function buildGenericEventBodyLines(genericEventHandlers) {
|
|
|
59800
60477
|
for (const [eventName, handlers] of Object.entries(genericEventHandlers)) {
|
|
59801
60478
|
bodyLines.push(` ${isFirst ? "if" : "else if"} (event.type === "${eventName}") {`);
|
|
59802
60479
|
isFirst = false;
|
|
60480
|
+
for (const line of buildPayloadClosureLines({
|
|
60481
|
+
handlers,
|
|
60482
|
+
cwdExpression: V1_CWD_EXPRESSION
|
|
60483
|
+
})) bodyLines.push(` ${line}`);
|
|
59803
60484
|
for (const handler of handlers) {
|
|
59804
|
-
const
|
|
60485
|
+
const runStatement = buildRunStatement(handler);
|
|
59805
60486
|
if (handler.propertyGate) {
|
|
59806
60487
|
bodyLines.push(` if (${handler.propertyGate}) {`);
|
|
59807
|
-
bodyLines.push(`
|
|
60488
|
+
bodyLines.push(` ${runStatement}`);
|
|
59808
60489
|
bodyLines.push(" }");
|
|
59809
|
-
} else bodyLines.push(`
|
|
60490
|
+
} else bodyLines.push(` ${runStatement}`);
|
|
59810
60491
|
}
|
|
59811
60492
|
bodyLines.push(" }");
|
|
59812
60493
|
}
|
|
@@ -59816,39 +60497,61 @@ function buildGenericEventBodyLines(genericEventHandlers) {
|
|
|
59816
60497
|
function stdinPayloadVariable(stdinEvent) {
|
|
59817
60498
|
return `__rulesync${stdinEvent}Input`;
|
|
59818
60499
|
}
|
|
60500
|
+
/** The `cwd` a V1 payload reports: the session directory, else the process's. */
|
|
60501
|
+
const V1_CWD_EXPRESSION = "directory ?? process.cwd()";
|
|
60502
|
+
/** Lazily serialized closures for the payloads the handlers use (internal tables only). */
|
|
60503
|
+
function buildPayloadClosureLines({ handlers, cwdExpression }) {
|
|
60504
|
+
const payloads = /* @__PURE__ */ new Map();
|
|
60505
|
+
for (const handler of handlers) if (handler.payload) payloads.set(handler.payload.name, handler.payload);
|
|
60506
|
+
const lines = [];
|
|
60507
|
+
for (const payload of payloads.values()) {
|
|
60508
|
+
const variable = stdinPayloadVariable(payload.name);
|
|
60509
|
+
lines.push(`let ${variable}Cache;`, `const ${variable} = () =>`);
|
|
60510
|
+
lines.push(` (${variable}Cache ??= JSON.stringify({`);
|
|
60511
|
+
lines.push(` hook_event_name: "${payload.name}",`);
|
|
60512
|
+
lines.push(...payload.fields.map((field) => ` ${field},`));
|
|
60513
|
+
lines.push(` cwd: ${cwdExpression},`, " }));");
|
|
60514
|
+
}
|
|
60515
|
+
return lines;
|
|
60516
|
+
}
|
|
59819
60517
|
/**
|
|
59820
|
-
* The statement that runs a handler's command
|
|
59821
|
-
*
|
|
59822
|
-
*
|
|
60518
|
+
* The statement that runs a handler's command with its stdin payload, or an
|
|
60519
|
+
* empty stdin. The command keeps the escaping it had in the template literal
|
|
60520
|
+
* earlier versions emitted, so `bun exec` parses the same text.
|
|
59823
60521
|
*/
|
|
59824
60522
|
function buildRunStatement(handler) {
|
|
59825
|
-
const
|
|
59826
|
-
|
|
59827
|
-
|
|
59828
|
-
|
|
59829
|
-
|
|
59830
|
-
|
|
60523
|
+
const command = JSON.stringify(escapeForTemplateLiteral(handler.command));
|
|
60524
|
+
const input = handler.payload ? `${stdinPayloadVariable(handler.payload.name)}()` : "\"\"";
|
|
60525
|
+
if (handler.payload?.name === "PreToolUse") {
|
|
60526
|
+
const failClosed = handler.failClosed === void 0 ? "" : `, ${handler.failClosed}`;
|
|
60527
|
+
return `${PRE_TOOL_USE_RESULT_HELPER}(await __rulesyncRunCommand({ command: ${command}, input: ${input}, seconds: ${handler.timeout} })${failClosed});`;
|
|
60528
|
+
}
|
|
60529
|
+
return `await __rulesyncRunHook({ ${[
|
|
60530
|
+
`label: ${JSON.stringify(handler.event)}`,
|
|
60531
|
+
`command: ${command}`,
|
|
60532
|
+
`input: ${input}`,
|
|
60533
|
+
`blocking: ${handler.blocking}`,
|
|
60534
|
+
`seconds: ${handler.timeout}`,
|
|
60535
|
+
...handler.inProcess ? ["inProcess: true"] : []
|
|
60536
|
+
].join(", ")} });`;
|
|
60537
|
+
}
|
|
60538
|
+
/** The helpers a plugin body defines before its handlers, run in `cwdExpression`. */
|
|
60539
|
+
function buildRunHelperLines({ handlers, cwdExpression }) {
|
|
60540
|
+
if (handlers.length === 0) return [];
|
|
60541
|
+
const usesPreToolUse = handlers.some((handler) => handler.payload?.name === "PreToolUse");
|
|
60542
|
+
return [...buildRunHelperLinesFor(cwdExpression), ...usesPreToolUse ? ["", ...PRE_TOOL_USE_RESULT_HELPER_LINES] : []];
|
|
59831
60543
|
}
|
|
59832
60544
|
/** Emit the named (`tool.execute.*`) handler blocks. */
|
|
59833
60545
|
function buildNamedEventBodyLines(namedEventHandlers) {
|
|
59834
60546
|
const bodyLines = [];
|
|
59835
60547
|
for (const [eventName, handlers] of Object.entries(namedEventHandlers)) {
|
|
59836
60548
|
const matcherSubject = NAMED_HOOK_MATCHER_SUBJECTS[eventName] ?? null;
|
|
59837
|
-
const
|
|
59838
|
-
|
|
59839
|
-
|
|
59840
|
-
|
|
59841
|
-
|
|
59842
|
-
|
|
59843
|
-
bodyLines.push(` (${payload}Cache ??= JSON.stringify({`);
|
|
59844
|
-
bodyLines.push(` hook_event_name: "${stdinEvent}",`);
|
|
59845
|
-
bodyLines.push(" session_id: input.sessionID,");
|
|
59846
|
-
bodyLines.push(" tool_use_id: input.callID,");
|
|
59847
|
-
bodyLines.push(" tool_name: input.tool,");
|
|
59848
|
-
bodyLines.push(" tool_input: output?.args,");
|
|
59849
|
-
bodyLines.push(" cwd: directory ?? process.cwd(),");
|
|
59850
|
-
bodyLines.push(" }));");
|
|
59851
|
-
}
|
|
60549
|
+
const payloadLines = buildPayloadClosureLines({
|
|
60550
|
+
handlers,
|
|
60551
|
+
cwdExpression: V1_CWD_EXPRESSION
|
|
60552
|
+
});
|
|
60553
|
+
bodyLines.push(` "${eventName}": async (${payloadLines.length > 0 ? "input, output" : "input"}) => {`);
|
|
60554
|
+
bodyLines.push(...payloadLines.map((line) => ` ${line}`));
|
|
59852
60555
|
for (const handler of handlers) {
|
|
59853
60556
|
const runStatement = buildRunStatement(handler);
|
|
59854
60557
|
if (handler.toolGate) {
|
|
@@ -59871,7 +60574,7 @@ function buildNamedEventBodyLines(namedEventHandlers) {
|
|
|
59871
60574
|
}
|
|
59872
60575
|
/** Wrap the handler body lines in the requested export shape. */
|
|
59873
60576
|
function wrapInExportShape({ preambleLines, bodyLines, exportStyle }) {
|
|
59874
|
-
const pluginContextPattern = preambleLines.length > 0 ? "{
|
|
60577
|
+
const pluginContextPattern = preambleLines.length > 0 ? "{ directory }" : "{ $ }";
|
|
59875
60578
|
const lines = [];
|
|
59876
60579
|
if (exportStyle === "default") {
|
|
59877
60580
|
lines.push("export default {");
|
|
@@ -59912,7 +60615,10 @@ function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey,
|
|
|
59912
60615
|
});
|
|
59913
60616
|
const bodyLines = [...buildGenericEventBodyLines(genericEventHandlers), ...buildNamedEventBodyLines(namedEventHandlers)];
|
|
59914
60617
|
return wrapInExportShape({
|
|
59915
|
-
preambleLines:
|
|
60618
|
+
preambleLines: buildRunHelperLines({
|
|
60619
|
+
handlers: [...Object.values(namedEventHandlers), ...Object.values(genericEventHandlers)].flat(),
|
|
60620
|
+
cwdExpression: V1_CWD_EXPRESSION
|
|
60621
|
+
}),
|
|
59916
60622
|
bodyLines,
|
|
59917
60623
|
exportStyle
|
|
59918
60624
|
}).join("\n");
|
|
@@ -59946,8 +60652,15 @@ var KiloHooks = class KiloHooks extends ToolHooks {
|
|
|
59946
60652
|
validate
|
|
59947
60653
|
});
|
|
59948
60654
|
}
|
|
59949
|
-
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false }) {
|
|
59950
|
-
const
|
|
60655
|
+
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false, logger }) {
|
|
60656
|
+
const config = rulesyncHooks.getJson();
|
|
60657
|
+
warnIgnoredFailClosed({
|
|
60658
|
+
config,
|
|
60659
|
+
supportedEvents: KILO_HOOK_EVENTS,
|
|
60660
|
+
toolConfigKey: "kilo",
|
|
60661
|
+
logger
|
|
60662
|
+
});
|
|
60663
|
+
const fileContent = generateOpencodeStylePluginCode(config, KILO_HOOK_EVENTS, "kilo", CANONICAL_TO_KILO_EVENT_NAMES, "default");
|
|
59951
60664
|
const paths = KiloHooks.getSettablePaths({ global });
|
|
59952
60665
|
return new KiloHooks({
|
|
59953
60666
|
outputRoot,
|
|
@@ -60155,7 +60868,7 @@ var KimiCodeHooks = class KimiCodeHooks extends ToolHooks {
|
|
|
60155
60868
|
global: true
|
|
60156
60869
|
});
|
|
60157
60870
|
}
|
|
60158
|
-
toRulesyncHooks() {
|
|
60871
|
+
toRulesyncHooks({ logger } = {}) {
|
|
60159
60872
|
const config = parseSharedConfig({
|
|
60160
60873
|
format: "toml",
|
|
60161
60874
|
fileContent: this.getFileContent()
|
|
@@ -60168,6 +60881,7 @@ var KimiCodeHooks = class KimiCodeHooks extends ToolHooks {
|
|
|
60168
60881
|
relativeDirPath: RULESYNC_RELATIVE_DIR_PATH,
|
|
60169
60882
|
relativeFilePath: RULESYNC_HOOKS_FILE_NAME,
|
|
60170
60883
|
fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
60884
|
+
logger,
|
|
60171
60885
|
hooks: kimiCodeHooksToCanonical(config.hooks),
|
|
60172
60886
|
overrideKey: "kimi-code"
|
|
60173
60887
|
}), null, 2)
|
|
@@ -60392,12 +61106,13 @@ var KiroIdeHooks = class extends ToolHooks {
|
|
|
60392
61106
|
validate
|
|
60393
61107
|
});
|
|
60394
61108
|
}
|
|
60395
|
-
toRulesyncHooks() {
|
|
61109
|
+
toRulesyncHooks({ logger } = {}) {
|
|
60396
61110
|
const hooks = kiroIdeHooksToCanonical(this.parseFileContentOrThrow({
|
|
60397
61111
|
displayName: "Kiro IDE",
|
|
60398
61112
|
parse: (fileContent) => KiroIdeHooksFileSchema.parse(JSON.parse(fileContent))
|
|
60399
61113
|
}).hooks ?? []);
|
|
60400
61114
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
61115
|
+
logger,
|
|
60401
61116
|
hooks,
|
|
60402
61117
|
overrideKey: KIRO_HOOKS_OVERRIDE_KEY
|
|
60403
61118
|
}), null, 2) });
|
|
@@ -60582,12 +61297,13 @@ var KiroHooks = class KiroHooks extends ToolHooks {
|
|
|
60582
61297
|
validate
|
|
60583
61298
|
});
|
|
60584
61299
|
}
|
|
60585
|
-
toRulesyncHooks() {
|
|
61300
|
+
toRulesyncHooks({ logger } = {}) {
|
|
60586
61301
|
const hooks = kiroHooksToCanonical(this.parseFileContentOrThrow({
|
|
60587
61302
|
displayName: "Kiro",
|
|
60588
61303
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
60589
61304
|
}).hooks);
|
|
60590
61305
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
61306
|
+
logger,
|
|
60591
61307
|
hooks,
|
|
60592
61308
|
overrideKey: "kiro"
|
|
60593
61309
|
}), null, 2) });
|
|
@@ -60741,6 +61457,7 @@ var LettacodeHooks = class LettacodeHooks extends ToolHooks {
|
|
|
60741
61457
|
converterConfig: LETTACODE_CONVERTER_CONFIG
|
|
60742
61458
|
});
|
|
60743
61459
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
61460
|
+
logger,
|
|
60744
61461
|
hooks,
|
|
60745
61462
|
overrideKey: "lettacode"
|
|
60746
61463
|
}), null, 2) });
|
|
@@ -60759,10 +61476,7 @@ var LettacodeHooks = class LettacodeHooks extends ToolHooks {
|
|
|
60759
61476
|
* option; the per-type checks inside the loop stay, so an older 2.x that
|
|
60760
61477
|
* ignores it still runs each command only for its own event).
|
|
60761
61478
|
*
|
|
60762
|
-
* Commands run
|
|
60763
|
-
* plugin runs inside the Bun-built OpenCode binary) whose working directory is
|
|
60764
|
-
* the plugin location's directory, so the global `Bun.$` defaults other
|
|
60765
|
-
* plugins see are left alone.
|
|
61479
|
+
* Commands run in the plugin location's directory (see `buildRunHelperLines`).
|
|
60766
61480
|
*
|
|
60767
61481
|
* @see https://opencode.ai/v2/docs/build/plugins/
|
|
60768
61482
|
*/
|
|
@@ -60785,13 +61499,33 @@ const OPENCODE_V2_HANDLER_GATES = {
|
|
|
60785
61499
|
permissionDenied: "event.data?.reply === \"reject\""
|
|
60786
61500
|
};
|
|
60787
61501
|
/**
|
|
60788
|
-
*
|
|
60789
|
-
*
|
|
60790
|
-
* `execute.before` hook fails the tool call with the error message, which the
|
|
60791
|
-
* model sees — the same contract the V1 plugin implements, interpreted by the
|
|
60792
|
-
* shared `PRE_TOOL_USE_RESULT_HELPER`.
|
|
61502
|
+
* The V2 counterparts of the V1 stdin payloads (`STDIN_PAYLOADS`), plus
|
|
61503
|
+
* Claude Code's `PostToolUseFailure` input for a failed call.
|
|
60793
61504
|
*/
|
|
60794
|
-
const
|
|
61505
|
+
const TOOL_CALL_FIELDS = [
|
|
61506
|
+
"session_id: event.sessionID",
|
|
61507
|
+
"tool_use_id: event.id",
|
|
61508
|
+
"tool_name: event.tool",
|
|
61509
|
+
"tool_input: event.input"
|
|
61510
|
+
];
|
|
61511
|
+
const OPENCODE_V2_STDIN_PAYLOADS = {
|
|
61512
|
+
preToolUse: {
|
|
61513
|
+
name: "PreToolUse",
|
|
61514
|
+
fields: TOOL_CALL_FIELDS
|
|
61515
|
+
},
|
|
61516
|
+
postToolUse: {
|
|
61517
|
+
name: "PostToolUse",
|
|
61518
|
+
fields: [...TOOL_CALL_FIELDS, "tool_response: event.result"]
|
|
61519
|
+
},
|
|
61520
|
+
postToolUseFailure: {
|
|
61521
|
+
name: "PostToolUseFailure",
|
|
61522
|
+
fields: [...TOOL_CALL_FIELDS, "error: event.error?.message ?? event.error"]
|
|
61523
|
+
},
|
|
61524
|
+
stop: {
|
|
61525
|
+
name: "Stop",
|
|
61526
|
+
fields: ["session_id: event.data?.sessionID"]
|
|
61527
|
+
}
|
|
61528
|
+
};
|
|
60795
61529
|
/**
|
|
60796
61530
|
* Helper the generated plugin defines when a handler has a matcher. A matcher
|
|
60797
61531
|
* is tested against the V2 tool name and, for a tool OpenCode 2.x renamed,
|
|
@@ -60828,28 +61562,21 @@ function buildHookRegistrationLines(hookPoint, handlers) {
|
|
|
60828
61562
|
const lines = [];
|
|
60829
61563
|
lines.push("__rulesyncRegistrations.push(");
|
|
60830
61564
|
lines.push(` await ctx.${domain}.hook("${name}", async (event) => {`);
|
|
60831
|
-
|
|
60832
|
-
|
|
60833
|
-
|
|
60834
|
-
|
|
60835
|
-
lines.push(` const ${payload} = () =>`);
|
|
60836
|
-
lines.push(` (${payload}Cache ??= JSON.stringify({`);
|
|
60837
|
-
lines.push(` hook_event_name: "${stdinEvent}",`);
|
|
60838
|
-
lines.push(" session_id: event.sessionID,");
|
|
60839
|
-
lines.push(" tool_use_id: event.id,");
|
|
60840
|
-
lines.push(" tool_name: event.tool,");
|
|
60841
|
-
lines.push(" tool_input: event.input,");
|
|
60842
|
-
lines.push(" cwd: directory,");
|
|
60843
|
-
lines.push(" }));");
|
|
60844
|
-
}
|
|
61565
|
+
lines.push(...buildPayloadClosureLines({
|
|
61566
|
+
handlers,
|
|
61567
|
+
cwdExpression: "directory"
|
|
61568
|
+
}).map((line) => ` ${line}`));
|
|
60845
61569
|
for (const handler of handlers) lines.push(...wrapInConditions(handler, buildRunStatement(handler), " "));
|
|
60846
61570
|
lines.push(" }),");
|
|
60847
61571
|
lines.push(");");
|
|
60848
61572
|
return lines;
|
|
60849
61573
|
}
|
|
60850
61574
|
/**
|
|
60851
|
-
* Emit the event-stream loop.
|
|
60852
|
-
* a failing
|
|
61575
|
+
* Emit the event-stream loop. Event handlers are non-blocking, so
|
|
61576
|
+
* `__rulesyncRunHook` logs a failing command instead of throwing, and it
|
|
61577
|
+
* neither skips its siblings nor ends the subscription. Each handler also runs
|
|
61578
|
+
* in its own try/catch, so a throw while evaluating its gate or building its
|
|
61579
|
+
* payload, outside `__rulesyncRunHook`, is logged the same way. The
|
|
60853
61580
|
* subscription passes `types` so the server delivers only the handled events.
|
|
60854
61581
|
*/
|
|
60855
61582
|
function buildEventLoopLines(eventHandlers) {
|
|
@@ -60865,11 +61592,16 @@ function buildEventLoopLines(eventHandlers) {
|
|
|
60865
61592
|
for (const [eventType, handlers] of eventHandlers) {
|
|
60866
61593
|
lines.push(` ${isFirst ? "if" : "} else if"} (event.type === "${eventType}") {`);
|
|
60867
61594
|
isFirst = false;
|
|
61595
|
+
lines.push(...buildPayloadClosureLines({
|
|
61596
|
+
handlers,
|
|
61597
|
+
cwdExpression: "directory"
|
|
61598
|
+
}).map((line) => ` ${line}`));
|
|
60868
61599
|
for (const handler of handlers) {
|
|
60869
61600
|
lines.push(" try {");
|
|
60870
61601
|
lines.push(...wrapInConditions(handler, buildRunStatement(handler), " "));
|
|
60871
61602
|
lines.push(" } catch (error) {");
|
|
60872
|
-
|
|
61603
|
+
const message = JSON.stringify(`[rulesync-hooks] ${handler.event} hook failed:`);
|
|
61604
|
+
lines.push(` console.error(${message}, error);`);
|
|
60873
61605
|
lines.push(" }");
|
|
60874
61606
|
}
|
|
60875
61607
|
}
|
|
@@ -60878,10 +61610,17 @@ function buildEventLoopLines(eventHandlers) {
|
|
|
60878
61610
|
lines.push("})().catch(() => {});");
|
|
60879
61611
|
return lines;
|
|
60880
61612
|
}
|
|
61613
|
+
/**
|
|
61614
|
+
* Every hook point but `execute.after` runs before its action, which a throw
|
|
61615
|
+
* aborts; the event stream only observes.
|
|
61616
|
+
*/
|
|
61617
|
+
function isBlockingOpencodeV2Target(target) {
|
|
61618
|
+
return !target.startsWith("event:") && target !== "tool:execute.after";
|
|
61619
|
+
}
|
|
60881
61620
|
/** Build the handlers of one canonical event's command definitions. */
|
|
60882
61621
|
function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
60883
61622
|
const gate = OPENCODE_V2_HANDLER_GATES[canonicalEvent];
|
|
60884
|
-
const
|
|
61623
|
+
const payload = OPENCODE_V2_STDIN_PAYLOADS[canonicalEvent];
|
|
60885
61624
|
const matcherSupported = !(canonicalEvent === "beforeShellExecution" || canonicalEvent === "afterShellExecution") && OPENCODE_V2_MATCHABLE_HOOKS.has(target);
|
|
60886
61625
|
const handlers = [];
|
|
60887
61626
|
for (const def of definitions) {
|
|
@@ -60890,9 +61629,12 @@ function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
|
60890
61629
|
if (def.matcher && !matcherSupported) continue;
|
|
60891
61630
|
handlers.push({
|
|
60892
61631
|
command: def.command,
|
|
61632
|
+
event: canonicalEvent,
|
|
61633
|
+
blocking: isBlockingOpencodeV2Target(target),
|
|
61634
|
+
...hookTimingOf(def),
|
|
60893
61635
|
...def.matcher ? { matcher: def.matcher } : {},
|
|
60894
61636
|
...gate ? { gate } : {},
|
|
60895
|
-
...
|
|
61637
|
+
...payload ? { payload } : {}
|
|
60896
61638
|
});
|
|
60897
61639
|
}
|
|
60898
61640
|
return handlers;
|
|
@@ -60900,13 +61642,14 @@ function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
|
60900
61642
|
/** Emit the statements of the `setup` function body. */
|
|
60901
61643
|
function buildSetupBodyLines({ hookHandlers, eventHandlers }) {
|
|
60902
61644
|
if (hookHandlers.size === 0 && eventHandlers.size === 0) return [];
|
|
60903
|
-
const usesStdinPayload = [...hookHandlers.values()].some((handlers) => handlers.some((handler) => handler.stdinEvent !== void 0));
|
|
60904
61645
|
const body = [
|
|
60905
61646
|
"const directory = ctx.location?.directory ?? process.cwd();",
|
|
60906
|
-
"
|
|
60907
|
-
|
|
61647
|
+
"",
|
|
61648
|
+
...buildRunHelperLines({
|
|
61649
|
+
handlers: [...hookHandlers.values(), ...eventHandlers.values()].flat(),
|
|
61650
|
+
cwdExpression: "directory"
|
|
61651
|
+
})
|
|
60908
61652
|
];
|
|
60909
|
-
if (usesStdinPayload) body.push("", ...PRE_TOOL_USE_RESULT_HELPER_LINES);
|
|
60910
61653
|
if ([...hookHandlers.values()].some((handlers) => handlers.some((handler) => handler.matcher !== void 0))) body.push("", ...TOOL_MATCHER_HELPER_LINES);
|
|
60911
61654
|
const cleanup = [];
|
|
60912
61655
|
if (hookHandlers.size > 0) {
|
|
@@ -60979,8 +61722,14 @@ var OpencodeHooks = class extends ToolHooks {
|
|
|
60979
61722
|
validate
|
|
60980
61723
|
});
|
|
60981
61724
|
}
|
|
60982
|
-
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false }) {
|
|
61725
|
+
static fromRulesyncHooks({ outputRoot = process.cwd(), rulesyncHooks, validate = true, global = false, logger }) {
|
|
60983
61726
|
const config = rulesyncHooks.getJson();
|
|
61727
|
+
warnIgnoredFailClosed({
|
|
61728
|
+
config,
|
|
61729
|
+
supportedEvents: this.layout.configVersion === "v2" ? OPENCODE_V2_HOOK_EVENTS : OPENCODE_HOOK_EVENTS,
|
|
61730
|
+
toolConfigKey: this.layout.toolTarget,
|
|
61731
|
+
logger
|
|
61732
|
+
});
|
|
60984
61733
|
const fileContent = this.layout.configVersion === "v2" ? generateOpencodeV2PluginCode({
|
|
60985
61734
|
config,
|
|
60986
61735
|
supportedEvents: OPENCODE_V2_HOOK_EVENTS,
|
|
@@ -61733,9 +62482,10 @@ var PoolHooks = class PoolHooks extends ToolHooks {
|
|
|
61733
62482
|
global
|
|
61734
62483
|
});
|
|
61735
62484
|
}
|
|
61736
|
-
toRulesyncHooks() {
|
|
62485
|
+
toRulesyncHooks({ logger } = {}) {
|
|
61737
62486
|
const hooks = poolHooksToCanonical(this.settings[POOL_HOOKS_KEY]);
|
|
61738
62487
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
62488
|
+
logger,
|
|
61739
62489
|
hooks,
|
|
61740
62490
|
overrideKey: "pool"
|
|
61741
62491
|
}), null, 2) });
|
|
@@ -62132,12 +62882,13 @@ var QwencodeHooks = class QwencodeHooks extends ToolHooks {
|
|
|
62132
62882
|
static supportsPreserveUnowned() {
|
|
62133
62883
|
return true;
|
|
62134
62884
|
}
|
|
62135
|
-
toRulesyncHooks() {
|
|
62885
|
+
toRulesyncHooks({ logger } = {}) {
|
|
62136
62886
|
const settings = this.parseFileContentOrThrow({
|
|
62137
62887
|
displayName: "Qwen Code",
|
|
62138
62888
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
62139
62889
|
});
|
|
62140
62890
|
const canonical = buildImportedHooksConfig({
|
|
62891
|
+
logger,
|
|
62141
62892
|
hooks: qwencodeHooksToCanonical(settings.hooks),
|
|
62142
62893
|
overrideKey: "qwencode",
|
|
62143
62894
|
...typeof settings.disableAllHooks === "boolean" && { extraOverride: { disableAllHooks: settings.disableAllHooks } }
|
|
@@ -62342,12 +63093,13 @@ var ReasonixHooks = class ReasonixHooks extends ToolHooks {
|
|
|
62342
63093
|
validate
|
|
62343
63094
|
});
|
|
62344
63095
|
}
|
|
62345
|
-
toRulesyncHooks() {
|
|
63096
|
+
toRulesyncHooks({ logger } = {}) {
|
|
62346
63097
|
const hooks = reasonixHooksToCanonical(this.parseFileContentOrThrow({
|
|
62347
63098
|
displayName: "Reasonix",
|
|
62348
63099
|
parse: (fileContent) => JSON.parse(fileContent)
|
|
62349
63100
|
}).hooks);
|
|
62350
63101
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
63102
|
+
logger,
|
|
62351
63103
|
hooks,
|
|
62352
63104
|
overrideKey: "reasonix"
|
|
62353
63105
|
}), null, 2) });
|
|
@@ -62572,13 +63324,14 @@ var TabnineHooks = class TabnineHooks extends ToolHooks {
|
|
|
62572
63324
|
validate
|
|
62573
63325
|
});
|
|
62574
63326
|
}
|
|
62575
|
-
toRulesyncHooks() {
|
|
63327
|
+
toRulesyncHooks({ logger } = {}) {
|
|
62576
63328
|
const configPath = (0, node_path.join)(this.getRelativeDirPath(), this.getRelativeFilePath());
|
|
62577
63329
|
const hooks = tabnineHooksToCanonical(this.parseFileContentOrThrow({
|
|
62578
63330
|
displayName: "Tabnine CLI",
|
|
62579
63331
|
parse: (fileContent) => parseTabnineSettings(fileContent, configPath)
|
|
62580
63332
|
}).hooks);
|
|
62581
63333
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
63334
|
+
logger,
|
|
62582
63335
|
hooks,
|
|
62583
63336
|
overrideKey: "tabnine"
|
|
62584
63337
|
}), null, 2) });
|
|
@@ -62643,13 +63396,31 @@ var TraeHooks = class extends SettingsJsonHooks {
|
|
|
62643
63396
|
const VIBE_DIR = ".vibe";
|
|
62644
63397
|
const VIBE_HOOKS_FILE_NAME = "hooks.toml";
|
|
62645
63398
|
/**
|
|
62646
|
-
* Vibe scopes the tool-name `match` glob
|
|
62647
|
-
*
|
|
62648
|
-
*
|
|
62649
|
-
*
|
|
62650
|
-
*
|
|
63399
|
+
* Vibe scopes the tool-name `match` glob to tool hooks (`pre_tool` /
|
|
63400
|
+
* `post_tool`). The other events take a `match` too, on something other than a
|
|
63401
|
+
* tool name: the agent whose turn it is on `post_agent` / `pre_agent` /
|
|
63402
|
+
* `pre_llm` / `post_llm`, and the source, reason or notification type on
|
|
63403
|
+
* `session_start` / `session_end` / `notification`.
|
|
63404
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/plugins/builtins/vibe/skills/vibe/SKILL.md
|
|
62651
63405
|
*/
|
|
62652
63406
|
const VIBE_TOOL_EVENTS = /* @__PURE__ */ new Set(["pre_tool", "post_tool"]);
|
|
63407
|
+
/**
|
|
63408
|
+
* The events where a failing hook may block, and so the only ones that accept
|
|
63409
|
+
* `strict`. Vibe's `HookConfig` validator rejects a `strict` entry of any
|
|
63410
|
+
* other type.
|
|
63411
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/core/hooks/models.py
|
|
63412
|
+
*/
|
|
63413
|
+
const VIBE_STRICT_EVENTS = /* @__PURE__ */ new Set([
|
|
63414
|
+
"pre_tool",
|
|
63415
|
+
"post_tool",
|
|
63416
|
+
"pre_agent",
|
|
63417
|
+
"pre_llm",
|
|
63418
|
+
"post_llm"
|
|
63419
|
+
]);
|
|
63420
|
+
/** The canonical matcher for a `pre_agent` hook that runs for every agent. */
|
|
63421
|
+
const VIBE_ANY_AGENT_MATCHER = "*";
|
|
63422
|
+
/** The Vibe event canonical `beforeSubmitPrompt` becomes. */
|
|
63423
|
+
const VIBE_PRE_AGENT_EVENT = "pre_agent";
|
|
62653
63424
|
/** The Vibe event both canonical `stop` and `subagentStop` become. */
|
|
62654
63425
|
const VIBE_POST_AGENT_EVENT = "post_agent";
|
|
62655
63426
|
/**
|
|
@@ -62697,11 +63468,69 @@ function fromVibeHookMatch(match) {
|
|
|
62697
63468
|
return match.toLowerCase() === VIBE_SHELL_HOOK_MATCH ? "Bash" : match;
|
|
62698
63469
|
}
|
|
62699
63470
|
/**
|
|
63471
|
+
* The `match` for an event whose matcher is not a tool name, or `undefined`
|
|
63472
|
+
* when the canonical matcher selects everything.
|
|
63473
|
+
*/
|
|
63474
|
+
function toVibeOptionalMatch(matcher) {
|
|
63475
|
+
if (typeof matcher !== "string" || matcher === "" || matcher === "*") return;
|
|
63476
|
+
return matcher;
|
|
63477
|
+
}
|
|
63478
|
+
/**
|
|
63479
|
+
* The `match` of the Vibe entry a canonical hook becomes: a string, `undefined`
|
|
63480
|
+
* to leave the key out, or null to skip the hook.
|
|
63481
|
+
*/
|
|
63482
|
+
function toVibeEntryMatch({ event, vibeEvent, matcher, logger }) {
|
|
63483
|
+
if (VIBE_TOOL_EVENTS.has(vibeEvent)) return toVibeHookMatch(matcher);
|
|
63484
|
+
if (event === "subagentStop") return toVibeSubagentMatch({
|
|
63485
|
+
matcher,
|
|
63486
|
+
logger
|
|
63487
|
+
});
|
|
63488
|
+
if (vibeEvent === VIBE_POST_AGENT_EVENT) return VIBE_MAIN_AGENT_MATCH;
|
|
63489
|
+
if (vibeEvent === VIBE_PRE_AGENT_EVENT) {
|
|
63490
|
+
if (typeof matcher !== "string" || matcher === "") return VIBE_MAIN_AGENT_MATCH;
|
|
63491
|
+
return toVibeOptionalMatch(matcher);
|
|
63492
|
+
}
|
|
63493
|
+
return toVibeOptionalMatch(matcher);
|
|
63494
|
+
}
|
|
63495
|
+
/**
|
|
63496
|
+
* The canonical event and matcher a Vibe entry's `type` and `match` become.
|
|
63497
|
+
*/
|
|
63498
|
+
function fromVibeEntryMatch({ vibeEvent, canonicalEvent, match }) {
|
|
63499
|
+
if (VIBE_TOOL_EVENTS.has(vibeEvent)) return {
|
|
63500
|
+
canonicalEvent,
|
|
63501
|
+
matcher: fromVibeHookMatch(match)
|
|
63502
|
+
};
|
|
63503
|
+
const optionalMatch = toVibeOptionalMatch(match);
|
|
63504
|
+
const isMainAgent = optionalMatch === void 0 || optionalMatch.toLowerCase() === VIBE_MAIN_AGENT_MATCH;
|
|
63505
|
+
if (vibeEvent === VIBE_POST_AGENT_EVENT) return isMainAgent ? {
|
|
63506
|
+
canonicalEvent,
|
|
63507
|
+
matcher: void 0
|
|
63508
|
+
} : {
|
|
63509
|
+
canonicalEvent: "subagentStop",
|
|
63510
|
+
matcher: optionalMatch
|
|
63511
|
+
};
|
|
63512
|
+
if (vibeEvent === VIBE_PRE_AGENT_EVENT) {
|
|
63513
|
+
if (optionalMatch === void 0) return {
|
|
63514
|
+
canonicalEvent,
|
|
63515
|
+
matcher: VIBE_ANY_AGENT_MATCHER
|
|
63516
|
+
};
|
|
63517
|
+
return {
|
|
63518
|
+
canonicalEvent,
|
|
63519
|
+
matcher: isMainAgent ? void 0 : optionalMatch
|
|
63520
|
+
};
|
|
63521
|
+
}
|
|
63522
|
+
return {
|
|
63523
|
+
canonicalEvent,
|
|
63524
|
+
matcher: optionalMatch
|
|
63525
|
+
};
|
|
63526
|
+
}
|
|
63527
|
+
/**
|
|
62700
63528
|
* Build the flat `[[hooks]]` array for `.vibe/hooks.toml` from a canonical
|
|
62701
63529
|
* hooks config. Vibe uses a flat array where each entry carries its own event
|
|
62702
|
-
* `type`, `match` glob/regex (a tool name for tool hooks, an agent name
|
|
62703
|
-
*
|
|
62704
|
-
*
|
|
63530
|
+
* `type`, `match` glob/regex (a tool name for tool hooks, an agent name for
|
|
63531
|
+
* `post_agent` / `pre_agent` / `pre_llm` / `post_llm`, a source, reason or
|
|
63532
|
+
* notification type for the session and notification hooks), and `command`.
|
|
63533
|
+
* Only `type: "command"` canonical hooks are emitted: a Vibe hook is a shell command line. (v2.25.1
|
|
62705
63534
|
* to v2.25.4 briefly exec'd it without a shell under the unified harness and
|
|
62706
63535
|
* skipped any command containing a backslash; v2.25.5 restored shell
|
|
62707
63536
|
* execution — "Hook commands using pipes, `&&`, redirects, globs or `$VAR`
|
|
@@ -62726,27 +63555,23 @@ function canonicalToVibeHooks({ config, toolOverride, logger }) {
|
|
|
62726
63555
|
for (const def of defs) {
|
|
62727
63556
|
if ((def.type ?? "command") !== "command") continue;
|
|
62728
63557
|
if (typeof def.command !== "string") continue;
|
|
62729
|
-
const
|
|
62730
|
-
|
|
62731
|
-
|
|
62732
|
-
|
|
62733
|
-
|
|
62734
|
-
|
|
62735
|
-
|
|
62736
|
-
});
|
|
62737
|
-
if (subagentMatch === null) continue;
|
|
62738
|
-
match = subagentMatch;
|
|
62739
|
-
} else match = VIBE_MAIN_AGENT_MATCH;
|
|
63558
|
+
const match = toVibeEntryMatch({
|
|
63559
|
+
event,
|
|
63560
|
+
vibeEvent,
|
|
63561
|
+
matcher: def.matcher,
|
|
63562
|
+
logger
|
|
63563
|
+
});
|
|
63564
|
+
if (match === null) continue;
|
|
62740
63565
|
const index = nextIndexByVibeEvent.get(vibeEvent) ?? 0;
|
|
62741
63566
|
const entry = {
|
|
62742
63567
|
name: typeof def.name === "string" ? def.name : `${vibeEvent}-${index}`,
|
|
62743
63568
|
type: vibeEvent,
|
|
62744
|
-
match,
|
|
63569
|
+
...match !== void 0 && { match },
|
|
62745
63570
|
command: def.command
|
|
62746
63571
|
};
|
|
62747
63572
|
if (typeof def.timeout === "number") entry.timeout = def.timeout;
|
|
62748
63573
|
const strict = def.strict;
|
|
62749
|
-
if (
|
|
63574
|
+
if (VIBE_STRICT_EVENTS.has(vibeEvent) && typeof strict === "boolean") entry.strict = strict;
|
|
62750
63575
|
if (typeof def.description === "string") entry.description = def.description;
|
|
62751
63576
|
hooks.push(entry);
|
|
62752
63577
|
nextIndexByVibeEvent.set(vibeEvent, index + 1);
|
|
@@ -62761,22 +63586,22 @@ function vibeEntryToCanonicalDef(raw) {
|
|
|
62761
63586
|
const vibeEvent = typeof entry.type === "string" ? entry.type : void 0;
|
|
62762
63587
|
if (vibeEvent === void 0) return null;
|
|
62763
63588
|
if (isPrototypePollutionKey(vibeEvent)) return null;
|
|
62764
|
-
|
|
63589
|
+
const mappedEvent = lookupOwn({
|
|
62765
63590
|
record: VIBE_TO_CANONICAL_EVENT_NAMES,
|
|
62766
63591
|
key: vibeEvent
|
|
62767
63592
|
}) ?? vibeEvent;
|
|
62768
63593
|
const def = { type: "command" };
|
|
62769
63594
|
if (typeof entry.command === "string") def.command = entry.command;
|
|
62770
|
-
|
|
62771
|
-
|
|
62772
|
-
|
|
62773
|
-
|
|
62774
|
-
|
|
62775
|
-
|
|
62776
|
-
|
|
62777
|
-
|
|
62778
|
-
|
|
62779
|
-
|
|
63595
|
+
const resolved = fromVibeEntryMatch({
|
|
63596
|
+
vibeEvent: lookupOwn({
|
|
63597
|
+
record: CANONICAL_TO_VIBE_EVENT_NAMES,
|
|
63598
|
+
key: mappedEvent
|
|
63599
|
+
}) ?? vibeEvent,
|
|
63600
|
+
canonicalEvent: mappedEvent,
|
|
63601
|
+
match: entry.match
|
|
63602
|
+
});
|
|
63603
|
+
const canonicalEvent = resolved.canonicalEvent;
|
|
63604
|
+
if (resolved.matcher !== void 0) def.matcher = resolved.matcher;
|
|
62780
63605
|
if (typeof entry.timeout === "number") def.timeout = entry.timeout;
|
|
62781
63606
|
if (typeof entry.name === "string") def.name = entry.name;
|
|
62782
63607
|
if (typeof entry.description === "string") def.description = entry.description;
|
|
@@ -62810,22 +63635,55 @@ function vibeHooksToCanonical(parsed) {
|
|
|
62810
63635
|
/** Vibe reads a `match` with a `re:` prefix or glob metacharacters as a pattern. */
|
|
62811
63636
|
const VIBE_PATTERN_MATCH = /^re:|[*?[]/;
|
|
62812
63637
|
/**
|
|
62813
|
-
*
|
|
62814
|
-
* them
|
|
62815
|
-
*
|
|
62816
|
-
*
|
|
62817
|
-
*
|
|
63638
|
+
* The canonical events whose imported hooks are kept Vibe-only once any of
|
|
63639
|
+
* them carries a matcher, with the reason for the warning. Their matcher
|
|
63640
|
+
* selects Vibe agents, which other tools either drop (Claude Code, with a
|
|
63641
|
+
* warning) or read as their own matcher syntax, so a hook scoped to one agent
|
|
63642
|
+
* — or, for `pre_agent`, to every agent including subagents — would fire
|
|
63643
|
+
* everywhere there. A `subagentStop` hook needs a matcher anyway, so only a
|
|
63644
|
+
* pattern (which may also select the main agent) moves it.
|
|
63645
|
+
*/
|
|
63646
|
+
const VIBE_ONLY_AGENT_SCOPED_EVENTS = [
|
|
63647
|
+
{
|
|
63648
|
+
event: "subagentStop",
|
|
63649
|
+
vibeEvent: "post_agent",
|
|
63650
|
+
isVibeOnly: (matcher) => VIBE_PATTERN_MATCH.test(matcher)
|
|
63651
|
+
},
|
|
63652
|
+
{
|
|
63653
|
+
event: "beforeSubmitPrompt",
|
|
63654
|
+
vibeEvent: "pre_agent",
|
|
63655
|
+
isVibeOnly: () => true
|
|
63656
|
+
},
|
|
63657
|
+
{
|
|
63658
|
+
event: "preModelInvocation",
|
|
63659
|
+
vibeEvent: "pre_llm",
|
|
63660
|
+
isVibeOnly: () => true
|
|
63661
|
+
},
|
|
63662
|
+
{
|
|
63663
|
+
event: "postModelInvocation",
|
|
63664
|
+
vibeEvent: "post_llm",
|
|
63665
|
+
isVibeOnly: () => true
|
|
63666
|
+
}
|
|
63667
|
+
];
|
|
63668
|
+
/**
|
|
63669
|
+
* Move the imported hooks of an agent-matched event into the `vibe` override
|
|
63670
|
+
* when any of them is scoped in a way other tools cannot express (see
|
|
63671
|
+
* {@link VIBE_ONLY_AGENT_SCOPED_EVENTS}). The override replaces the shared
|
|
62818
63672
|
* list for its event, so the whole list moves to keep every entry on Vibe.
|
|
62819
63673
|
*/
|
|
62820
|
-
function
|
|
62821
|
-
const
|
|
62822
|
-
|
|
62823
|
-
|
|
62824
|
-
|
|
62825
|
-
|
|
62826
|
-
|
|
62827
|
-
|
|
62828
|
-
|
|
63674
|
+
function takeVibeOnlyAgentScopedHooks({ hooks, logger }) {
|
|
63675
|
+
const taken = {};
|
|
63676
|
+
for (const { event, vibeEvent, isVibeOnly } of VIBE_ONLY_AGENT_SCOPED_EVENTS) {
|
|
63677
|
+
const defs = lookupOwn({
|
|
63678
|
+
record: hooks,
|
|
63679
|
+
key: event
|
|
63680
|
+
});
|
|
63681
|
+
if (defs === void 0 || !defs.some((def) => typeof def.matcher === "string" && isVibeOnly(def.matcher))) continue;
|
|
63682
|
+
delete hooks[event];
|
|
63683
|
+
taken[event] = defs;
|
|
63684
|
+
logger?.warn(`Vibe hooks: a ${vibeEvent} hook is scoped by agent in a way other tools cannot express, so its ${event} hooks are imported into the vibe override instead of the shared hooks.`);
|
|
63685
|
+
}
|
|
63686
|
+
return taken;
|
|
62829
63687
|
}
|
|
62830
63688
|
function parseVibeToml(fileContent) {
|
|
62831
63689
|
const parsed = smol_toml.parse(fileContent || smol_toml.stringify({}));
|
|
@@ -62877,21 +63735,22 @@ var VibeHooks = class extends ToolHooks {
|
|
|
62877
63735
|
displayName: "Vibe",
|
|
62878
63736
|
parse: (fileContent) => parseVibeToml(fileContent)
|
|
62879
63737
|
}));
|
|
62880
|
-
const
|
|
63738
|
+
const vibeOnly = takeVibeOnlyAgentScopedHooks({
|
|
62881
63739
|
hooks,
|
|
62882
63740
|
logger: options.logger
|
|
62883
63741
|
});
|
|
62884
63742
|
const config = buildImportedHooksConfig({
|
|
63743
|
+
logger: options.logger,
|
|
62885
63744
|
hooks,
|
|
62886
63745
|
overrideKey: "vibe"
|
|
62887
63746
|
});
|
|
62888
|
-
if (
|
|
63747
|
+
if (Object.keys(vibeOnly).length > 0) {
|
|
62889
63748
|
const override = config.vibe ?? {};
|
|
62890
63749
|
config.vibe = {
|
|
62891
63750
|
...override,
|
|
62892
63751
|
hooks: {
|
|
62893
63752
|
...override.hooks,
|
|
62894
|
-
|
|
63753
|
+
...vibeOnly
|
|
62895
63754
|
}
|
|
62896
63755
|
};
|
|
62897
63756
|
}
|
|
@@ -63099,6 +63958,7 @@ var ZcodeHooks = class ZcodeHooks extends ToolHooks {
|
|
|
63099
63958
|
logger
|
|
63100
63959
|
});
|
|
63101
63960
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
63961
|
+
logger,
|
|
63102
63962
|
hooks,
|
|
63103
63963
|
overrideKey: "zcode"
|
|
63104
63964
|
}), null, 2) });
|
|
@@ -63183,6 +64043,7 @@ var ZcodePluginHooks = class ZcodePluginHooks extends ToolHooks {
|
|
|
63183
64043
|
logger
|
|
63184
64044
|
});
|
|
63185
64045
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
64046
|
+
logger,
|
|
63186
64047
|
hooks,
|
|
63187
64048
|
overrideKey: "zcode"
|
|
63188
64049
|
}), null, 2) });
|
|
@@ -78748,6 +79609,15 @@ const PERMISSION_ACTION_PRIORITY = {
|
|
|
78748
79609
|
deny: 2
|
|
78749
79610
|
};
|
|
78750
79611
|
/**
|
|
79612
|
+
* A pattern map reordered allow, then ask, then deny, keeping the authored
|
|
79613
|
+
* order within each action. A tool that applies the last matching pattern
|
|
79614
|
+
* then lets the strictest matching rule win. `Object.fromEntries` defines own
|
|
79615
|
+
* properties, so even a `__proto__` pattern survives.
|
|
79616
|
+
*/
|
|
79617
|
+
function sortRulesByActionPriority(rules) {
|
|
79618
|
+
return Object.fromEntries(Object.entries(rules).toSorted(([, a], [, b]) => PERMISSION_ACTION_PRIORITY[a] - PERMISSION_ACTION_PRIORITY[b]));
|
|
79619
|
+
}
|
|
79620
|
+
/**
|
|
78751
79621
|
* Whether `action` should replace `existing` when two canonical rules collapse
|
|
78752
79622
|
* onto one entry: an empty slot always takes it, otherwise only a strictly
|
|
78753
79623
|
* stricter action (deny > ask > allow) does.
|
|
@@ -80418,7 +81288,13 @@ function splitUrlPattern(withoutScheme) {
|
|
|
80418
81288
|
* (so an allowed `example.com` overlaps a restricted `*.pdf`), and an overlap
|
|
80419
81289
|
* from any of them counts. A host ending in a DNS root dot (`example.com.`)
|
|
80420
81290
|
* is also compared with one and with all trailing dots removed, in addition
|
|
80421
|
-
* to its original reading, so this only ever adds overlaps.
|
|
81291
|
+
* to its original reading, so this only ever adds overlaps. The allow is also
|
|
81292
|
+
* compared without its userinfo, query and fragment
|
|
81293
|
+
* (`https://user@example.com/x?y=1#z` as `example.com/x`), which name no other
|
|
81294
|
+
* host or path, again in addition to its original reading. Only a `?` or `#`
|
|
81295
|
+
* in the path counts as a query or fragment start there, so a `?` glob in the
|
|
81296
|
+
* host is left alone (one in the path is read as a query start for this extra
|
|
81297
|
+
* reading, which can only add overlaps). A pattern holding
|
|
80422
81298
|
* whitespace names no URL. Callers pass the restriction as `left` and the
|
|
80423
81299
|
* allow as `right`.
|
|
80424
81300
|
*/
|
|
@@ -80441,12 +81317,7 @@ function urlPatternsOverlap(left, right) {
|
|
|
80441
81317
|
*/
|
|
80442
81318
|
function wholeStringsOverlap(left, right) {
|
|
80443
81319
|
const normalizedLeft = normalizeUrlPattern(left);
|
|
80444
|
-
|
|
80445
|
-
return [
|
|
80446
|
-
[left, right],
|
|
80447
|
-
[normalizedLeft, normalizedRight],
|
|
80448
|
-
...normalizedLeft.includes("/") ? [] : [[normalizedLeft, withAnyPath(normalizedRight)]]
|
|
80449
|
-
].some(([restriction = "", allow = ""]) => createShadowingRestrictionsTest([{
|
|
81320
|
+
return [[left, right], ...allowReadings(normalizeUrlPattern(right)).flatMap((normalizedRight) => [[normalizedLeft, normalizedRight], ...normalizedLeft.includes("/") ? [] : [[normalizedLeft, withAnyPath(normalizedRight)]]])].some(([restriction = "", allow = ""]) => createShadowingRestrictionsTest([{
|
|
80450
81321
|
pattern: restriction,
|
|
80451
81322
|
fromAllToolsCategory: false
|
|
80452
81323
|
}])(allow).length > 0);
|
|
@@ -80455,8 +81326,25 @@ function wholeStringsOverlap(left, right) {
|
|
|
80455
81326
|
function withAnyPath(withoutScheme) {
|
|
80456
81327
|
return stripUrlSchemeKeepingPathCase(withoutScheme).includes("/") ? withoutScheme : `${withoutScheme}/*`;
|
|
80457
81328
|
}
|
|
81329
|
+
/**
|
|
81330
|
+
* A scheme-less allow pattern as written, plus (when they differ) the same
|
|
81331
|
+
* pattern without the userinfo before its host and the query and fragment
|
|
81332
|
+
* after its path, so `user:pass@example.com/x?y=1` is also read as
|
|
81333
|
+
* `example.com/x`. A `?` is a single-character glob in Rulesync patterns, so
|
|
81334
|
+
* only a `?` or `#` in the path (after the first `/`) is read as a query or
|
|
81335
|
+
* fragment start; the host keeps it (`git?ub.com` is not cut to `git`). The
|
|
81336
|
+
* original reading stays first, so a caller that ORs the readings only ever
|
|
81337
|
+
* gains overlaps.
|
|
81338
|
+
*/
|
|
81339
|
+
function allowReadings(withoutScheme) {
|
|
81340
|
+
const slash = withoutScheme.indexOf("/");
|
|
81341
|
+
const hostPort = slash === -1 ? withoutScheme : withoutScheme.slice(0, slash);
|
|
81342
|
+
const path = slash === -1 ? "" : withoutScheme.slice(slash).replace(/[?#].*$/s, "");
|
|
81343
|
+
const stripped = `${hostPort.slice(hostPort.lastIndexOf("@") + 1)}${path}`;
|
|
81344
|
+
return stripped === withoutScheme || stripped === "" ? [withoutScheme] : [withoutScheme, stripped];
|
|
81345
|
+
}
|
|
80458
81346
|
function urlPartsOverlap(left, right) {
|
|
80459
|
-
const readings = (pattern) => [.../* @__PURE__ */ new Set([stripUrlSchemeKeepingPathCase(pattern), stripUrlSchemeLoosely(pattern)])].map(splitUrlPattern).flatMap((parts) => parts.host.endsWith(".") ? [
|
|
81347
|
+
const readings = (pattern, { asAllow = false } = {}) => [.../* @__PURE__ */ new Set([stripUrlSchemeKeepingPathCase(pattern), stripUrlSchemeLoosely(pattern)])].flatMap((withoutScheme) => asAllow ? allowReadings(withoutScheme) : [withoutScheme]).map(splitUrlPattern).flatMap((parts) => parts.host.endsWith(".") ? [
|
|
80460
81348
|
parts,
|
|
80461
81349
|
{
|
|
80462
81350
|
...parts,
|
|
@@ -80467,7 +81355,8 @@ function urlPartsOverlap(left, right) {
|
|
|
80467
81355
|
host: parts.host.replace(/\.+$/, "")
|
|
80468
81356
|
}
|
|
80469
81357
|
] : [parts]);
|
|
80470
|
-
|
|
81358
|
+
const allowParts = readings(right, { asAllow: true });
|
|
81359
|
+
return readings(left).some((a) => allowParts.some((b) => urlPartsPairOverlap(a, b)));
|
|
80471
81360
|
}
|
|
80472
81361
|
function urlPartsPairOverlap(a, b) {
|
|
80473
81362
|
const hosts = (host) => [host, `*.${host}`];
|
|
@@ -81971,8 +82860,11 @@ var AugmentcodePermissions = class AugmentcodePermissions extends ToolPermission
|
|
|
81971
82860
|
* does nothing.
|
|
81972
82861
|
*
|
|
81973
82862
|
* Only Auggie 0.x reads `recommendedMarketplaces`: the 1.x plugin settings
|
|
81974
|
-
* reference lists `enabledPlugins` alone
|
|
81975
|
-
* stable CLI
|
|
82863
|
+
* reference lists `enabledPlugins` alone, and the 1.x settings loader never
|
|
82864
|
+
* reads the key. 1.x is the stable CLI since 1.2.0, so the key now reaches only
|
|
82865
|
+
* users pinned to 0.x (npm `v0-release` with auto-update off). It is still
|
|
82866
|
+
* written for them, and the write warning says so.
|
|
82867
|
+
* @see https://www.augmentcode.com/changelog
|
|
81976
82868
|
*
|
|
81977
82869
|
* Both make Auggie load code the repository did not ship — a recommended
|
|
81978
82870
|
* marketplace is one prompt away from being cloned, and an enabled plugin can
|
|
@@ -81993,7 +82885,7 @@ function buildPluginConsumptionPatch({ override, existing, global, logger }) {
|
|
|
81993
82885
|
else {
|
|
81994
82886
|
patch.recommendedMarketplaces = recommendedMarketplaces;
|
|
81995
82887
|
const existingMarketplaces = existingKeys.recommendedMarketplaces;
|
|
81996
|
-
if (recommendedMarketplaces.length > 0 && !(0, node_util.isDeepStrictEqual)(recommendedMarketplaces, existingMarketplaces)) logger?.warn(`Writing AugmentCode \`recommendedMarketplaces\` (${recommendedMarketplaces.map(quoteValueForWarning).join(", ")}): Auggie 0.x prompts everyone who opens this workspace to install these plugin marketplaces (Auggie 1.x no longer reads this key).`);
|
|
82888
|
+
if (recommendedMarketplaces.length > 0 && !(0, node_util.isDeepStrictEqual)(recommendedMarketplaces, existingMarketplaces)) logger?.warn(`Writing AugmentCode \`recommendedMarketplaces\` (${recommendedMarketplaces.map(quoteValueForWarning).join(", ")}): Auggie 0.x prompts everyone who opens this workspace to install these plugin marketplaces (Auggie 1.x no longer reads this key, so only users pinned to Auggie 0.x see the prompt).`);
|
|
81997
82889
|
warnAboutRemovedPluginIds({
|
|
81998
82890
|
key: "recommendedMarketplaces",
|
|
81999
82891
|
removed: (existingMarketplaces ?? []).filter((marketplace) => !recommendedMarketplaces.includes(marketplace)),
|
|
@@ -87536,6 +88428,173 @@ function parseCommandcodeRuleLists(permissions) {
|
|
|
87536
88428
|
return permission;
|
|
87537
88429
|
}
|
|
87538
88430
|
/**
|
|
88431
|
+
* The non-list `permissions` fields rulesync authors through the
|
|
88432
|
+
* `commandcode.permissions` override and imports back. Every other key of the
|
|
88433
|
+
* file's `permissions` object is kept as it is, never written from the source.
|
|
88434
|
+
*/
|
|
88435
|
+
const COMMANDCODE_PERMISSIONS_FIELD_KEYS = [
|
|
88436
|
+
"defaultMode",
|
|
88437
|
+
"additionalDirectories",
|
|
88438
|
+
"disableBypass"
|
|
88439
|
+
];
|
|
88440
|
+
const ACCEPT_EDITS_REASON = "workspace edits and safe filesystem shell commands then run without a prompt";
|
|
88441
|
+
const YOLO_REASON = "every session then starts in permission bypass, where only deny and ask rules still stop a tool";
|
|
88442
|
+
/**
|
|
88443
|
+
* The `permissions.defaultMode` values (aliases included) that start a session
|
|
88444
|
+
* with fewer prompts than `default`. `plan` and `dont-ask` are absent: `plan`
|
|
88445
|
+
* is read-only, and `dont-ask` is a fail-closed allowlist that denies whatever
|
|
88446
|
+
* policy does not already allow, so neither widens anything.
|
|
88447
|
+
*
|
|
88448
|
+
* @see https://commandcode.ai/docs/permissions
|
|
88449
|
+
*/
|
|
88450
|
+
const COMMANDCODE_WIDENING_DEFAULT_MODES = {
|
|
88451
|
+
"accept-edits": ACCEPT_EDITS_REASON,
|
|
88452
|
+
"auto-accept": ACCEPT_EDITS_REASON,
|
|
88453
|
+
acceptEdits: ACCEPT_EDITS_REASON,
|
|
88454
|
+
yolo: YOLO_REASON,
|
|
88455
|
+
bypass: YOLO_REASON,
|
|
88456
|
+
bypassPermissions: YOLO_REASON
|
|
88457
|
+
};
|
|
88458
|
+
/**
|
|
88459
|
+
* How many prompts each documented `defaultMode` (aliases included) removes:
|
|
88460
|
+
* `plan` and `dont-ask` (fail-closed) < `default` < `accept-edits` < `yolo`.
|
|
88461
|
+
* Used to notice an override that replaces a stricter mode already in the file.
|
|
88462
|
+
*/
|
|
88463
|
+
const COMMANDCODE_DEFAULT_MODE_LOOSENESS = {
|
|
88464
|
+
plan: 0,
|
|
88465
|
+
"dont-ask": 0,
|
|
88466
|
+
dontAsk: 0,
|
|
88467
|
+
default: 1,
|
|
88468
|
+
manual: 1,
|
|
88469
|
+
standard: 1,
|
|
88470
|
+
"accept-edits": 2,
|
|
88471
|
+
"auto-accept": 2,
|
|
88472
|
+
acceptEdits: 2,
|
|
88473
|
+
yolo: 3,
|
|
88474
|
+
bypass: 3,
|
|
88475
|
+
bypassPermissions: 3
|
|
88476
|
+
};
|
|
88477
|
+
/**
|
|
88478
|
+
* Command Code resolves settings project-local > project > user-global, and a
|
|
88479
|
+
* scalar from the more specific file overwrites the others (only the rule
|
|
88480
|
+
* lists and `additionalDirectories` union across files). A project-scope
|
|
88481
|
+
* `defaultMode` or `disableBypass` therefore replaces whatever the user set in
|
|
88482
|
+
* `~/.commandcode/settings.json`.
|
|
88483
|
+
*
|
|
88484
|
+
* @see https://commandcode.ai/docs/settings
|
|
88485
|
+
*/
|
|
88486
|
+
const PROJECT_SCALAR_OVERRIDES_GLOBAL = "a project value overrides ~/.commandcode/settings.json, so it also replaces a stricter user-global mode such as dont-ask or plan";
|
|
88487
|
+
/**
|
|
88488
|
+
* The widening entry for a `commandcode.permissions.defaultMode`, or `null`
|
|
88489
|
+
* when it does not widen. A mode that removes prompts always widens; at
|
|
88490
|
+
* project scope so does any mode looser than the strictest ones (`plan`,
|
|
88491
|
+
* `dont-ask`), because it overrides the user-global mode; and so does a mode
|
|
88492
|
+
* looser than the one already in the file. An undocumented mode is warned
|
|
88493
|
+
* about on its own.
|
|
88494
|
+
*/
|
|
88495
|
+
function defaultModeWideningEntry({ defaultMode, replaced, global, logger }) {
|
|
88496
|
+
const label = `permissions.defaultMode: "${defaultMode}"`;
|
|
88497
|
+
const projectNote = global ? [] : [PROJECT_SCALAR_OVERRIDES_GLOBAL];
|
|
88498
|
+
const reason = lookupOwn({
|
|
88499
|
+
record: COMMANDCODE_WIDENING_DEFAULT_MODES,
|
|
88500
|
+
key: defaultMode
|
|
88501
|
+
});
|
|
88502
|
+
if (reason !== void 0) return `${label} (${[reason, ...projectNote].join("; ")})`;
|
|
88503
|
+
const looseness = lookupOwn({
|
|
88504
|
+
record: COMMANDCODE_DEFAULT_MODE_LOOSENESS,
|
|
88505
|
+
key: defaultMode
|
|
88506
|
+
});
|
|
88507
|
+
if (looseness === void 0) {
|
|
88508
|
+
logger?.warn(`Command Code permissions: '${label}' is not a mode Command Code documents (default, accept-edits, plan, yolo, dont-ask and their aliases); it was written as authored.`);
|
|
88509
|
+
return null;
|
|
88510
|
+
}
|
|
88511
|
+
const replacedLooseness = typeof replaced === "string" ? lookupOwn({
|
|
88512
|
+
record: COMMANDCODE_DEFAULT_MODE_LOOSENESS,
|
|
88513
|
+
key: replaced
|
|
88514
|
+
}) : void 0;
|
|
88515
|
+
const notes = replacedLooseness !== void 0 && looseness > replacedLooseness ? [`replaces the stricter "${String(replaced)}" already in the file`] : [];
|
|
88516
|
+
if (looseness > 0) notes.push(...projectNote);
|
|
88517
|
+
return notes.length > 0 ? `${label} (${notes.join("; ")})` : null;
|
|
88518
|
+
}
|
|
88519
|
+
/**
|
|
88520
|
+
* Name, in one warning, every `commandcode.permissions` value that widens what
|
|
88521
|
+
* Command Code trusts. At project scope the scalars also override the
|
|
88522
|
+
* user-global file, which the warning says explicitly.
|
|
88523
|
+
*/
|
|
88524
|
+
function warnWideningCommandcodeFields({ fields, existingPermissions, global, logger }) {
|
|
88525
|
+
const widening = [];
|
|
88526
|
+
const { defaultMode, additionalDirectories, disableBypass } = fields;
|
|
88527
|
+
if (typeof defaultMode === "string") {
|
|
88528
|
+
const entry = defaultModeWideningEntry({
|
|
88529
|
+
defaultMode,
|
|
88530
|
+
replaced: existingPermissions.defaultMode,
|
|
88531
|
+
global,
|
|
88532
|
+
logger
|
|
88533
|
+
});
|
|
88534
|
+
if (entry !== null) widening.push(entry);
|
|
88535
|
+
}
|
|
88536
|
+
if (Array.isArray(additionalDirectories) && additionalDirectories.length > 0) widening.push("permissions.additionalDirectories (each directory then counts as inside the workspace for reads and writes)");
|
|
88537
|
+
if (disableBypass !== void 0 && disableBypass !== true && disableBypass !== "disable") widening.push(`permissions.disableBypass: ${JSON.stringify(disableBypass)} (` + (global ? "yolo mode then stays enterable from this file" : "a project value overrides the user-global setting, so yolo becomes enterable again even if ~/.commandcode/settings.json disables it") + ")");
|
|
88538
|
+
if (widening.length > 0) logger?.warn(`Command Code permissions: the commandcode override widens what Command Code trusts: ${widening.join("; ")}.`);
|
|
88539
|
+
}
|
|
88540
|
+
/**
|
|
88541
|
+
* The fields of the `commandcode.permissions` override to merge into the
|
|
88542
|
+
* settings file's `permissions` object. Only the documented
|
|
88543
|
+
* `COMMANDCODE_PERMISSIONS_FIELD_KEYS` are written: the `allow`/`ask`/`deny`
|
|
88544
|
+
* lists are rulesync's (built from the shared `permission` block) and any
|
|
88545
|
+
* other key is ignored, so the override can never smuggle a grant past the
|
|
88546
|
+
* list handling. A value that widens trust — a `defaultMode` that removes
|
|
88547
|
+
* prompts (or replaces a stricter one already in the file or, at project
|
|
88548
|
+
* scope, in the user-global file), a non-empty `additionalDirectories`, a
|
|
88549
|
+
* `disableBypass` that does not disable — is still written, but named in one
|
|
88550
|
+
* warning: this file is
|
|
88551
|
+
* shareable through `rulesync fetch`, and a loosening should not be silent.
|
|
88552
|
+
*/
|
|
88553
|
+
function commandcodePermissionsFields({ config, existingPermissions, global, logger }) {
|
|
88554
|
+
const override = config.commandcode?.permissions;
|
|
88555
|
+
if (!isRecord(override)) return {};
|
|
88556
|
+
const fields = {};
|
|
88557
|
+
for (const [key, value] of Object.entries(override)) {
|
|
88558
|
+
if (isPrototypePollutionKey(key) || value === void 0) continue;
|
|
88559
|
+
if (!COMMANDCODE_PERMISSIONS_FIELD_KEYS.includes(key)) {
|
|
88560
|
+
logger?.warn(`Command Code permissions: 'commandcode.permissions.${key}' is not written; only ${COMMANDCODE_PERMISSIONS_FIELD_KEYS.join(", ")} are authored there${key === "allow" || key === "ask" || key === "deny" ? " (the shared 'permission' block drives the allow/ask/deny lists)" : ""}.`);
|
|
88561
|
+
continue;
|
|
88562
|
+
}
|
|
88563
|
+
fields[key] = value;
|
|
88564
|
+
}
|
|
88565
|
+
warnWideningCommandcodeFields({
|
|
88566
|
+
fields,
|
|
88567
|
+
existingPermissions,
|
|
88568
|
+
global,
|
|
88569
|
+
logger
|
|
88570
|
+
});
|
|
88571
|
+
return fields;
|
|
88572
|
+
}
|
|
88573
|
+
/**
|
|
88574
|
+
* Read the documented non-list `permissions` fields back for the
|
|
88575
|
+
* `commandcode.permissions` override, verbatim. A value of a type Command Code
|
|
88576
|
+
* does not document is skipped with a warning rather than imported into a
|
|
88577
|
+
* source that would then fail validation; it stays in the settings file,
|
|
88578
|
+
* which a regenerate leaves untouched. Nothing here reaches the shared
|
|
88579
|
+
* `permission` block, so a mode or directory set for Command Code never turns
|
|
88580
|
+
* into a grant for another target.
|
|
88581
|
+
*/
|
|
88582
|
+
function importCommandcodePermissionsFields(permissions) {
|
|
88583
|
+
const fields = {};
|
|
88584
|
+
const skip = (key) => fallbackLogger.warn(`Command Code permissions: 'permissions.${key}' holds a value of a type Command Code does not document, so it was not imported; it stays in the Command Code settings.`);
|
|
88585
|
+
const { defaultMode, additionalDirectories, disableBypass } = permissions;
|
|
88586
|
+
if (typeof defaultMode === "string") fields.defaultMode = defaultMode;
|
|
88587
|
+
else if (defaultMode !== void 0) skip("defaultMode");
|
|
88588
|
+
if (Array.isArray(additionalDirectories)) {
|
|
88589
|
+
const directories = additionalDirectories.filter((entry) => typeof entry === "string");
|
|
88590
|
+
if (directories.length < additionalDirectories.length) fallbackLogger.warn("Command Code permissions: 'permissions.additionalDirectories' holds entries that are not strings; only the string entries were imported.");
|
|
88591
|
+
fields.additionalDirectories = directories;
|
|
88592
|
+
} else if (additionalDirectories !== void 0) skip("additionalDirectories");
|
|
88593
|
+
if (typeof disableBypass === "boolean" || disableBypass === "disable") fields.disableBypass = disableBypass;
|
|
88594
|
+
else if (disableBypass !== void 0) skip("disableBypass");
|
|
88595
|
+
return fields;
|
|
88596
|
+
}
|
|
88597
|
+
/**
|
|
87539
88598
|
* Permissions generator for Command Code.
|
|
87540
88599
|
*
|
|
87541
88600
|
* Rules live under the `permissions` key of `.commandcode/settings.json`
|
|
@@ -87543,8 +88602,10 @@ function parseCommandcodeRuleLists(permissions) {
|
|
|
87543
88602
|
* Claude-style entries: `deny` (always wins), `ask`, `allow`. The same key
|
|
87544
88603
|
* also carries `defaultMode`, `additionalDirectories` and `disableBypass`,
|
|
87545
88604
|
* and the file holds `hooks` and other settings, so writes go through the
|
|
87546
|
-
* shared-config gateway: rulesync replaces the three lists,
|
|
87547
|
-
*
|
|
88605
|
+
* shared-config gateway: rulesync replaces the three lists, merges those
|
|
88606
|
+
* three fields from the `commandcode.permissions` override (warning on values
|
|
88607
|
+
* that widen trust), keeps every other sibling key, and never deletes the
|
|
88608
|
+
* file. Import reads the three fields back into that override.
|
|
87548
88609
|
*
|
|
87549
88610
|
* Generate: `permission.<category>.<pattern>` becomes `Tool(pattern)` with
|
|
87550
88611
|
* the friendly names (`Shell`, `Read`, `Edit`, `Write`, `WebFetch`,
|
|
@@ -87595,12 +88656,21 @@ var CommandcodePermissions = class CommandcodePermissions extends ToolPermission
|
|
|
87595
88656
|
relativePath: (0, node_path.join)(paths.relativeDirPath, paths.relativeFilePath)
|
|
87596
88657
|
});
|
|
87597
88658
|
const existingPermissions = isRecord(existing[COMMANDCODE_PERMISSIONS_KEY]) ? existing[COMMANDCODE_PERMISSIONS_KEY] : {};
|
|
88659
|
+
const config = rulesyncPermissions.getJson();
|
|
87598
88660
|
const lists = buildCommandcodeRuleLists({
|
|
87599
|
-
config
|
|
88661
|
+
config,
|
|
87600
88662
|
existingPermissions,
|
|
87601
88663
|
logger
|
|
87602
88664
|
});
|
|
87603
|
-
const permissions = {
|
|
88665
|
+
const permissions = {
|
|
88666
|
+
...existingPermissions,
|
|
88667
|
+
...commandcodePermissionsFields({
|
|
88668
|
+
config,
|
|
88669
|
+
existingPermissions,
|
|
88670
|
+
global,
|
|
88671
|
+
logger
|
|
88672
|
+
})
|
|
88673
|
+
};
|
|
87604
88674
|
for (const key of [
|
|
87605
88675
|
"allow",
|
|
87606
88676
|
"ask",
|
|
@@ -87628,7 +88698,10 @@ var CommandcodePermissions = class CommandcodePermissions extends ToolPermission
|
|
|
87628
88698
|
relativePath: (0, node_path.join)(this.getRelativeDirPath(), this.getRelativeFilePath())
|
|
87629
88699
|
});
|
|
87630
88700
|
const permissions = isRecord(settings[COMMANDCODE_PERMISSIONS_KEY]) ? settings[COMMANDCODE_PERMISSIONS_KEY] : {};
|
|
87631
|
-
|
|
88701
|
+
const imported = { permission: parseCommandcodeRuleLists(permissions) };
|
|
88702
|
+
const fields = importCommandcodePermissionsFields(permissions);
|
|
88703
|
+
if (Object.keys(fields).length > 0) imported.commandcode = { permissions: fields };
|
|
88704
|
+
return this.toRulesyncPermissionsDefault({ fileContent: JSON.stringify(imported, null, 2) });
|
|
87632
88705
|
}
|
|
87633
88706
|
};
|
|
87634
88707
|
/**
|
|
@@ -88728,9 +89801,11 @@ function effectiveSafeCommandLine(entry) {
|
|
|
88728
89801
|
* and without a Windows executable suffix. A `*` in the command word may
|
|
88729
89802
|
* stand for a directory and part of a name, so when what follows it is the
|
|
88730
89803
|
* tail of a wrapper name, everything before it collapses into `*`
|
|
88731
|
-
* (`b*nice` -> `*nice`, `/u*v` -> `*v`; `rm*` is left alone). The rest of
|
|
88732
|
-
*
|
|
88733
|
-
*
|
|
89804
|
+
* (`b*nice` -> `*nice`, `/u*v` -> `*v`; `rm*` is left alone). The rest of
|
|
89805
|
+
* the pattern is lower-cased as well, for a nested wrapper spelled in another
|
|
89806
|
+
* case. Used only to compare against a lower-cased safe line, its `--` form
|
|
89807
|
+
* and its wrapper spellings. Lower-casing the arguments too can only withhold
|
|
89808
|
+
* more: a `go BUILD` deny also withholds `go build` (fail-closed).
|
|
88734
89809
|
*/
|
|
88735
89810
|
function normalizeRestrictionCommandWord(pattern) {
|
|
88736
89811
|
const space = pattern.indexOf(" ");
|
|
@@ -88747,9 +89822,9 @@ function normalizeRestrictionCommandWord(pattern) {
|
|
|
88747
89822
|
* rules govern a command Crush would approve through it? Besides the line
|
|
88748
89823
|
* itself, Crush approves it followed by `--` and behind a wrapper (or the
|
|
88749
89824
|
* `time` keyword), whose name it normalizes (`./nice`, `/usr/bin/env`, `NICE`,
|
|
88750
|
-
* `nohup.exe`). The line and its wrapper spellings are compared
|
|
88751
|
-
* restrictions as written
|
|
88752
|
-
*
|
|
89825
|
+
* `nohup.exe`). The line, its `--` form and its wrapper spellings are compared
|
|
89826
|
+
* against both the restrictions as written and those with their command word
|
|
89827
|
+
* normalized like Crush (including executable paths and case) — which keeps
|
|
88753
89828
|
* an unrelated `rm *` from withholding the line, as a leading wildcard on the
|
|
88754
89829
|
* spelling would. Canonically the stricter rule wins whatever its width
|
|
88755
89830
|
* (`deny > ask > allow`), so any overlap withholds the line.
|
|
@@ -88773,7 +89848,7 @@ function createSafeCommandShadowTest(permission) {
|
|
|
88773
89848
|
});
|
|
88774
89849
|
const withSeparator = (spellings) => spellings.flatMap((spelling) => [spelling, `${spelling} --*`]);
|
|
88775
89850
|
const wrapped = (base) => CRUSH_COMMAND_PREFIXES.map((prefix) => `${prefix}*${base}`);
|
|
88776
|
-
return (line) => uniq$11([...withSeparator([line, ...wrapped(line)]).flatMap((spelling) => test(spelling)), ...withSeparator(wrapped(line.toLowerCase())).flatMap((spelling) => testNormalized(spelling).map((pattern) => originalOf.get(pattern) ?? pattern))]);
|
|
89851
|
+
return (line) => uniq$11([...withSeparator([line, ...wrapped(line)]).flatMap((spelling) => test(spelling)), ...withSeparator([line.toLowerCase(), ...wrapped(line.toLowerCase())]).flatMap((spelling) => testNormalized(spelling).map((pattern) => originalOf.get(pattern) ?? pattern))]);
|
|
88777
89852
|
}
|
|
88778
89853
|
function uniq$11(values) {
|
|
88779
89854
|
return [...new Set(values)];
|
|
@@ -92544,7 +93619,14 @@ function convertJunieToRulesyncPermissions({ allowlist }) {
|
|
|
92544
93619
|
* restriction is restated at the end of every other key that holds a looser
|
|
92545
93620
|
* rule it overlaps, where it is matched after that rule. A `*` catch-all
|
|
92546
93621
|
* (`{"*": {"*": "ask"}}` followed by per-tool allows) is the documented way to
|
|
92547
|
-
* set an OpenCode default, so it is
|
|
93622
|
+
* set an OpenCode default, so it is not restated in the later keys.
|
|
93623
|
+
*
|
|
93624
|
+
* The `*` key's own patterns are reordered allow, then ask, then deny, so the
|
|
93625
|
+
* strictest matching one wins there too. This disables an allow carve-out
|
|
93626
|
+
* under a broader ask or deny in that key (`{"*": "deny", "src/**": "allow"}`
|
|
93627
|
+
* denies `src/**` as well), so a warning is logged whenever the order changes,
|
|
93628
|
+
* unless `<target>.permission["*"]` (`allToolsOverridden`) replaces the key
|
|
93629
|
+
* with an exact order anyway.
|
|
92548
93630
|
*
|
|
92549
93631
|
* A restated rule must never land after an overlapping stricter one, or it
|
|
92550
93632
|
* would loosen what that rule says. The tail of a key is therefore written
|
|
@@ -92553,15 +93635,23 @@ function convertJunieToRulesyncPermissions({ allowlist }) {
|
|
|
92553
93635
|
* then the restated `*` denies. A key whose own catch-all is a deny covers
|
|
92554
93636
|
* every input of a restated ask already, so such an ask is restated as a deny.
|
|
92555
93637
|
*/
|
|
92556
|
-
function restateAllToolsRestrictionsLast(sharedPermission) {
|
|
93638
|
+
function restateAllToolsRestrictionsLast({ sharedPermission, toolTarget, allToolsOverridden = false, logger }) {
|
|
92557
93639
|
const allToolsRules = Object.hasOwn(sharedPermission, "*") ? sharedPermission["*"] : void 0;
|
|
92558
93640
|
const restrictions = Object.entries(allToolsRules ?? {}).filter(([pattern, action]) => action !== "allow" && pattern !== "*" && !isPrototypePollutionKey(pattern));
|
|
92559
|
-
if (restrictions.length === 0) return sharedPermission;
|
|
93641
|
+
if (restrictions.length === 0 && !allToolsRules) return sharedPermission;
|
|
92560
93642
|
const result = {};
|
|
92561
|
-
for (const [key, rules] of Object.entries(sharedPermission))
|
|
92562
|
-
|
|
92563
|
-
|
|
92564
|
-
|
|
93643
|
+
for (const [key, rules] of Object.entries(sharedPermission)) {
|
|
93644
|
+
if (key !== "*") {
|
|
93645
|
+
result[key] = restateInKey({
|
|
93646
|
+
rules,
|
|
93647
|
+
restrictions
|
|
93648
|
+
});
|
|
93649
|
+
continue;
|
|
93650
|
+
}
|
|
93651
|
+
const sorted = sortRulesByActionPriority(rules);
|
|
93652
|
+
if (!allToolsOverridden && !(0, node_util.isDeepStrictEqual)(Object.keys(sorted), Object.keys(rules))) logger?.warn(`The all-tools "*" permission patterns were reordered allow, ask, deny because ${toolTarget} applies the last matching pattern and the stricter rule must win, which may disable a looser carve-out under a broader ask or deny pattern (e.g. "*": "deny", "src/**": "allow"). Set ${toolTarget}.permission["*"] to control the exact order.`);
|
|
93653
|
+
result[key] = sorted;
|
|
93654
|
+
}
|
|
92565
93655
|
return result;
|
|
92566
93656
|
}
|
|
92567
93657
|
function globsOverlap(left, right) {
|
|
@@ -92813,7 +93903,12 @@ var KiloPermissions = class KiloPermissions extends ToolPermissions {
|
|
|
92813
93903
|
const rulesyncJson = rulesyncPermissions.getJson();
|
|
92814
93904
|
const kiloOverride = rulesyncJson.kilo;
|
|
92815
93905
|
const incomingPermission = {
|
|
92816
|
-
...restateAllToolsRestrictionsLast(
|
|
93906
|
+
...restateAllToolsRestrictionsLast({
|
|
93907
|
+
sharedPermission: honorAllToolsOnBash(rulesyncJson.permission),
|
|
93908
|
+
toolTarget: "kilo",
|
|
93909
|
+
allToolsOverridden: Object.hasOwn(kiloOverride?.permission ?? {}, "*"),
|
|
93910
|
+
logger
|
|
93911
|
+
}),
|
|
92817
93912
|
...kiloOverride?.permission
|
|
92818
93913
|
};
|
|
92819
93914
|
if (!global && Object.hasOwn(incomingPermission, KILO_MARKDOWN_SOURCE_KEY)) {
|
|
@@ -94425,7 +95520,7 @@ function mergePatternRules(base, incoming) {
|
|
|
94425
95520
|
action,
|
|
94426
95521
|
existing: Object.hasOwn(merged, pattern) ? merged[pattern] : void 0
|
|
94427
95522
|
})) merged[pattern] = action;
|
|
94428
|
-
return
|
|
95523
|
+
return sortRulesByActionPriority(merged);
|
|
94429
95524
|
}
|
|
94430
95525
|
function toCanonicalPermissionKey(opencodeKey) {
|
|
94431
95526
|
return lookupOwn({
|
|
@@ -94486,7 +95581,7 @@ function fromOpencodeV2PermissionRules(rules) {
|
|
|
94486
95581
|
* written under the key OpenCode actually reads. A folded `write` is merged
|
|
94487
95582
|
* with any canonical `edit` rules rather than replacing them.
|
|
94488
95583
|
*/
|
|
94489
|
-
function toOpencodeSharedPermission({ permission, toolTarget, logger }) {
|
|
95584
|
+
function toOpencodeSharedPermission({ permission, toolTarget, allToolsOverridden, logger }) {
|
|
94490
95585
|
const sharedPermission = {};
|
|
94491
95586
|
for (const [category, value] of Object.entries(honorAllToolsOnBash(permission))) {
|
|
94492
95587
|
if (OPENCODE_UNSUPPORTED_PERMISSION_CATEGORIES.has(category)) {
|
|
@@ -94507,7 +95602,12 @@ function toOpencodeSharedPermission({ permission, toolTarget, logger }) {
|
|
|
94507
95602
|
sharedPermission[key] = merged;
|
|
94508
95603
|
} else sharedPermission[key] = value;
|
|
94509
95604
|
}
|
|
94510
|
-
return restateAllToolsRestrictionsLast(
|
|
95605
|
+
return restateAllToolsRestrictionsLast({
|
|
95606
|
+
sharedPermission,
|
|
95607
|
+
toolTarget,
|
|
95608
|
+
allToolsOverridden,
|
|
95609
|
+
logger
|
|
95610
|
+
});
|
|
94511
95611
|
}
|
|
94512
95612
|
const OpencodePermissionsConfigSchema = zod_mini.z.looseObject({
|
|
94513
95613
|
permission: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.enum([
|
|
@@ -94611,6 +95711,7 @@ var OpencodePermissions = class extends ToolPermissions {
|
|
|
94611
95711
|
const sharedPermission = toOpencodeSharedPermission({
|
|
94612
95712
|
permission: rulesyncJson.permission ?? {},
|
|
94613
95713
|
toolTarget: this.layout.toolTarget,
|
|
95714
|
+
allToolsOverridden: Object.hasOwn(overridePermission, "*"),
|
|
94614
95715
|
logger
|
|
94615
95716
|
});
|
|
94616
95717
|
const isV2 = this.layout.configVersion === "v2";
|
|
@@ -100212,28 +101313,31 @@ function parseTraePermissionConfig({ fileContent, relativePath }) {
|
|
|
100212
101313
|
const moduleLogger = fallbackLogger;
|
|
100213
101314
|
/**
|
|
100214
101315
|
* Vibe's builtin tool names are the snake_case of each tool class
|
|
100215
|
-
* (`BaseTool.get_name()`): `Edit` → `edit`,
|
|
100216
|
-
* `
|
|
101316
|
+
* (`BaseTool.get_name()`): `Edit` → `edit`, alongside `read_file`,
|
|
101317
|
+
* `write_file` and `bash`.
|
|
100217
101318
|
* `edit` and `write_file` are distinct tools — `write_file` has been
|
|
100218
101319
|
* create-only since v2.14.0 — so the canonical `edit` and `write` categories
|
|
100219
101320
|
* must not collapse onto one name.
|
|
100220
101321
|
*
|
|
100221
|
-
* `grep` and `
|
|
100222
|
-
* the Unified Harness, which reads `[tools.*]`
|
|
100223
|
-
* (`RUST_BUILTIN_TOOL_SOURCES`). There is no grep
|
|
100224
|
-
* goes through the shell — and subagents are
|
|
100225
|
-
* `agents.spawn` tool, which the `enable_subagents`
|
|
100226
|
-
* a `[tools.task]` table.
|
|
101322
|
+
* `grep`, `agent`, `webfetch` and `websearch` have no table here: since
|
|
101323
|
+
* v3.0.0 every session runs on the Unified Harness, which reads `[tools.*]`
|
|
101324
|
+
* only for its Rust builtins (`RUST_BUILTIN_TOOL_SOURCES`). There is no grep
|
|
101325
|
+
* tool any more — searching goes through the shell — and subagents are
|
|
101326
|
+
* spawned by the built-in `agents.spawn` tool, which the `enable_subagents`
|
|
101327
|
+
* switch governs instead of a `[tools.task]` table. `web_fetch` and
|
|
101328
|
+
* `web_search` are in Vibe's `RETIRED_TOOL_NAMES`: pages are fetched and the
|
|
101329
|
+
* web searched by the `connector_web_search_open_url` /
|
|
101330
|
+
* `connector_web_search_web_search` connector tools. See
|
|
101331
|
+
* {@link VIBE_RETIRED_TOOL_TABLES}.
|
|
100227
101332
|
* @see https://github.com/mistralai/mistral-vibe/blob/v3.0.2/vibe/app_server/_unified_permissions.py
|
|
100228
101333
|
* @see https://github.com/mistralai/mistral-vibe/blob/v3.0.2/vibe/app_server/_ignored_tool_settings.py
|
|
101334
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/core/config/_setting_keys.py
|
|
100229
101335
|
*/
|
|
100230
101336
|
const CANONICAL_TO_VIBE_TOOL_NAMES = {
|
|
100231
101337
|
bash: "bash",
|
|
100232
101338
|
read: "read_file",
|
|
100233
101339
|
edit: "edit",
|
|
100234
|
-
write: "write_file"
|
|
100235
|
-
webfetch: "web_fetch",
|
|
100236
|
-
websearch: "web_search"
|
|
101340
|
+
write: "write_file"
|
|
100237
101341
|
};
|
|
100238
101342
|
/**
|
|
100239
101343
|
* The tables earlier rulesync versions wrote for canonical categories that
|
|
@@ -100241,15 +101345,38 @@ const CANONICAL_TO_VIBE_TOOL_NAMES = {
|
|
|
100241
101345
|
* effect"), `[tools.task]` for the subagent tool v3.0.0 renamed to
|
|
100242
101346
|
* `agents.*`, and `[tools.external_directory]` — Vibe has no such tool, and
|
|
100243
101347
|
* its unused-settings check skips unknown tool names as custom/MCP tools, so
|
|
100244
|
-
* that deny was silently inert.
|
|
100245
|
-
* the
|
|
101348
|
+
* that deny was silently inert. `[tools.web_fetch]` / `[tools.web_search]`
|
|
101349
|
+
* are inert for the same reason: Vibe 3.x retired both tools, and v3.1.3 warns
|
|
101350
|
+
* about a tool filter naming them. A regenerate that configures the category
|
|
101351
|
+
* removes them — and the matching `disabled_tools` entry — instead of leaving
|
|
101352
|
+
* an inert table.
|
|
100246
101353
|
* Import still reads them (see {@link VIBE_TO_CANONICAL_TOOL_NAMES}), so a
|
|
100247
101354
|
* Vibe 2.x config is lifted into the canonical categories rather than lost.
|
|
100248
101355
|
*/
|
|
100249
101356
|
const VIBE_RETIRED_TOOL_TABLES = {
|
|
100250
101357
|
grep: "grep",
|
|
100251
101358
|
agent: "task",
|
|
100252
|
-
external_directory: "external_directory"
|
|
101359
|
+
external_directory: "external_directory",
|
|
101360
|
+
webfetch: "web_fetch",
|
|
101361
|
+
websearch: "web_search"
|
|
101362
|
+
};
|
|
101363
|
+
/**
|
|
101364
|
+
* The connector tools that replaced Vibe's retired web builtins, by canonical
|
|
101365
|
+
* category, so the skip warning can say where to write the rule instead.
|
|
101366
|
+
* rulesync does not write them itself: whether their `allowlist` / `denylist`
|
|
101367
|
+
* keys carry the old tools' semantics is not documented upstream.
|
|
101368
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/core/config/_setting_keys.py
|
|
101369
|
+
* @see https://github.com/mistralai/mistral-vibe/blob/v3.1.3/vibe/plugins/builtins/vibe/skills/vibe/SKILL.md
|
|
101370
|
+
*/
|
|
101371
|
+
const VIBE_WEB_CONNECTOR_TOOLS = {
|
|
101372
|
+
webfetch: {
|
|
101373
|
+
retired: "web_fetch",
|
|
101374
|
+
connector: "connector_web_search_open_url"
|
|
101375
|
+
},
|
|
101376
|
+
websearch: {
|
|
101377
|
+
retired: "web_search",
|
|
101378
|
+
connector: "connector_web_search_web_search"
|
|
101379
|
+
}
|
|
100253
101380
|
};
|
|
100254
101381
|
/** The canonical category Vibe's `enable_subagents` switch expresses. */
|
|
100255
101382
|
const VIBE_SUBAGENT_CATEGORY = "agent";
|
|
@@ -100625,7 +101752,7 @@ function retireLegacyToolTables({ permission, tools, disabledTools, logger }) {
|
|
|
100625
101752
|
}
|
|
100626
101753
|
if (disabledTools.delete(legacyToolName)) removed.push(`disabled_tools entry '${legacyToolName}'`);
|
|
100627
101754
|
}
|
|
100628
|
-
if (removed.length > 0) logger?.warn(`Removed ${removed.join(", ")} from the Vibe config: Vibe 3.x does not read [tools.grep], the former 'task' subagent tool
|
|
101755
|
+
if (removed.length > 0) logger?.warn(`Removed ${removed.join(", ")} from the Vibe config: Vibe 3.x does not read [tools.grep], the former 'task' subagent tool, an 'external_directory' tool (the 'external_directory' category is written to outside_workdir instead) or the retired 'web_fetch' / 'web_search' tools, so those entries had no effect.`);
|
|
100629
101756
|
}
|
|
100630
101757
|
/**
|
|
100631
101758
|
* Report the rules of a category that has no Vibe tool table. `grep` gets its
|
|
@@ -100641,6 +101768,14 @@ function warnOnUnmappedCategory({ category, rules, logger }) {
|
|
|
100641
101768
|
logger?.warn(`Vibe has no grep tool (searching goes through the shell, so 'rg' and 'grep' follow [tools.bash]); skipping ${ruleCount} 'grep' rule(s). Author a 'bash' rule such as "grep *" or "rg *" to restrict searching on Vibe.`);
|
|
100642
101769
|
return;
|
|
100643
101770
|
}
|
|
101771
|
+
const webTool = lookupOwn({
|
|
101772
|
+
record: VIBE_WEB_CONNECTOR_TOOLS,
|
|
101773
|
+
key: category
|
|
101774
|
+
});
|
|
101775
|
+
if (webTool !== void 0) {
|
|
101776
|
+
logger?.warn(`Vibe 3.x retired its '${webTool.retired}' tool (web access goes through the '${webTool.connector}' connector tool); skipping ${ruleCount} '${category}' rule(s) instead of emitting an inert [tools.${webTool.retired}] table. Author a '${webTool.connector}' rule (a '*' deny adds it to disabled_tools) to restrict it on Vibe.`);
|
|
101777
|
+
return;
|
|
101778
|
+
}
|
|
100644
101779
|
logger?.warn(`Vibe has no tool table for the '${category}' category; skipping ${ruleCount} rule(s) instead of emitting an inert [tools.${category}] table.`);
|
|
100645
101780
|
}
|
|
100646
101781
|
/**
|
|
@@ -100851,7 +101986,7 @@ function retireWithheldAllows({ source, permission, tools, resolveNames }) {
|
|
|
100851
101986
|
fromAllToolsCategory: false
|
|
100852
101987
|
}));
|
|
100853
101988
|
const globShadowed = createShadowingRestrictionsTest(restrictions);
|
|
100854
|
-
const shadowed = (pattern) =>
|
|
101989
|
+
const shadowed = (pattern) => globShadowed(pattern).length > 0;
|
|
100855
101990
|
const retires = (pattern) => withheld.has(pattern) || restrictions.length > 0 && honored[pattern] !== "allow" && shadowed(pattern);
|
|
100856
101991
|
for (const vibeToolName of resolveNames(category) ?? []) {
|
|
100857
101992
|
if (!Object.hasOwn(tools, vibeToolName)) continue;
|