rulesync 43.11.0 → 43.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cli/index.cjs +4 -4
- package/dist/cli/index.js +4 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-1cdCo1uU.cjs → import-Bp-dK2hr.cjs} +728 -123
- package/dist/{import-BVWVIY-6.js → import-Ctgal4jT.js} +729 -124
- package/dist/{import-BVWVIY-6.js.map → import-Ctgal4jT.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
|
@@ -5888,16 +5888,17 @@ const CONTINUE_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_CONTINUE_EVE
|
|
|
5888
5888
|
* observers, `gateway_platform_event` and `transform_api_error_classification`.
|
|
5889
5889
|
* Shell hooks are gated on the same set.
|
|
5890
5890
|
*
|
|
5891
|
-
* Verified against the tag `v0.
|
|
5891
|
+
* Verified against the tag `v0.23.2`: `VALID_HOOKS` holds 48 entries, grown
|
|
5892
5892
|
* from 23 at `v2026.8.3` (v0.20.0) and 37 at `v2026.8.16` (v0.20.2) — v0.21
|
|
5893
5893
|
* added `agent_loop_stopped` and `on_room_member_activity`, v0.21.5 added
|
|
5894
5894
|
* `pre_auxiliary_call` and `post_auxiliary_call`, v0.21.6 added
|
|
5895
5895
|
* `post_gateway_admission`, `on_human_input_request` and
|
|
5896
|
-
* `on_human_input_resolved`,
|
|
5897
|
-
* `post_compaction
|
|
5896
|
+
* `on_human_input_resolved`, v0.22.3 added `on_session_delete` and
|
|
5897
|
+
* `post_compaction`, and v0.23.1 added `on_session_open` and
|
|
5898
|
+
* `post_curator_run`. This list holds 47 of them — see
|
|
5898
5899
|
* {@link HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS} for the exclusion.
|
|
5899
5900
|
*
|
|
5900
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5901
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/hermes_cli/plugins.py
|
|
5901
5902
|
*/
|
|
5902
5903
|
const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
5903
5904
|
"pre_tool_call",
|
|
@@ -5922,6 +5923,7 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5922
5923
|
"on_session_finalize",
|
|
5923
5924
|
"on_session_reset",
|
|
5924
5925
|
"on_session_delete",
|
|
5926
|
+
"on_session_open",
|
|
5925
5927
|
"on_skill_lifecycle",
|
|
5926
5928
|
"subagent_start",
|
|
5927
5929
|
"subagent_stop",
|
|
@@ -5944,7 +5946,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5944
5946
|
"on_kanban_dispatch_tick",
|
|
5945
5947
|
"gateway_platform_event",
|
|
5946
5948
|
"pre_command",
|
|
5947
|
-
"post_compaction"
|
|
5949
|
+
"post_compaction",
|
|
5950
|
+
"post_curator_run"
|
|
5948
5951
|
];
|
|
5949
5952
|
/**
|
|
5950
5953
|
* `VALID_HOOKS` entries a SHELL hook may not register for. `VALID_HOOKS` doubles
|
|
@@ -5956,8 +5959,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5956
5959
|
* rulesync only ever writes shell hooks, so these are excluded from
|
|
5957
5960
|
* {@link HERMESAGENT_NATIVE_HOOK_EVENTS} and warned about with their own message.
|
|
5958
5961
|
*
|
|
5959
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5960
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5962
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/hermes_cli/plugins.py — `SHELL_UNSUPPORTED_HOOKS`
|
|
5963
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/agent/shell_hooks.py — `_parse_hooks_block`
|
|
5961
5964
|
*/
|
|
5962
5965
|
const HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS = ["transform_api_error_classification"];
|
|
5963
5966
|
/**
|
|
@@ -5977,8 +5980,8 @@ const CANONICAL_TO_HERMESAGENT_EVENT_NAMES = {
|
|
|
5977
5980
|
/**
|
|
5978
5981
|
* Hook events supported by Hermes Agent's native Shell Hooks system.
|
|
5979
5982
|
*
|
|
5980
|
-
* Hermes validates hook events against a fixed `VALID_HOOKS` set —
|
|
5981
|
-
* of v0.
|
|
5983
|
+
* Hermes validates hook events against a fixed `VALID_HOOKS` set — 48 entries as
|
|
5984
|
+
* of v0.23.2 (tag `v0.23.2`); see {@link HERMESAGENT_NATIVE_HOOK_EVENTS} for the
|
|
5982
5985
|
* full list. Only the events with a clean 1:1 canonical equivalent are mapped
|
|
5983
5986
|
* here. All other native events round-trip through `hermesagent.hooks`.
|
|
5984
5987
|
* @see https://github.com/NousResearch/hermes-agent/blob/main/website/docs/user-guide/features/hooks.md
|
|
@@ -6771,6 +6774,7 @@ const CANONICAL_TO_KIRO_IDE_EVENT_NAMES = {
|
|
|
6771
6774
|
beforeSubmitPrompt: "UserPromptSubmit",
|
|
6772
6775
|
preToolUse: "PreToolUse",
|
|
6773
6776
|
postToolUse: "PostToolUse",
|
|
6777
|
+
permissionRequest: "PermissionRequest",
|
|
6774
6778
|
stop: "Stop"
|
|
6775
6779
|
};
|
|
6776
6780
|
/**
|
|
@@ -6779,7 +6783,9 @@ const CANONICAL_TO_KIRO_IDE_EVENT_NAMES = {
|
|
|
6779
6783
|
*
|
|
6780
6784
|
* Kiro exposes PascalCase triggers. rulesync maps the canonical lifecycle
|
|
6781
6785
|
* events that have a clean 1:1 equivalent: `SessionStart`, `Stop`,
|
|
6782
|
-
* `UserPromptSubmit`, `PreToolUse`,
|
|
6786
|
+
* `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, and `PermissionRequest`
|
|
6787
|
+
* (Kiro IDE 1.4.236+ and CLI V3 3.4.0+; it takes a Pre Tool Use–style tool
|
|
6788
|
+
* matcher). Kiro also documents
|
|
6783
6789
|
* file-event (`PostFileCreate`/`PostFileSave`/`PostFileDelete`) and spec-task
|
|
6784
6790
|
* (`PreTaskExec`/`PostTaskExec`) triggers that have no canonical equivalent;
|
|
6785
6791
|
* those can still be emitted verbatim via the shared `kiro` override block
|
|
@@ -8208,6 +8214,15 @@ const CopilotSandboxUserConfiguredPathsSchema = zod_mini.z.strictObject({
|
|
|
8208
8214
|
deniedPaths: zod_mini.z.optional(zod_mini.z.array(zod_mini.z.string()))
|
|
8209
8215
|
});
|
|
8210
8216
|
/**
|
|
8217
|
+
* `chat.agent.sandbox.credentials.envVars` (VS Code 1.146+): environment
|
|
8218
|
+
* variable names (never their secret values) mapped to the HTTPS hosts the
|
|
8219
|
+
* Agent Host sandbox may inject each value into. Inside the sandbox the
|
|
8220
|
+
* variable is masked.
|
|
8221
|
+
*
|
|
8222
|
+
* @see https://code.visualstudio.com/docs/agents/run/agent-sandboxing
|
|
8223
|
+
*/
|
|
8224
|
+
const CopilotSandboxCredentialEnvVarsSchema = zod_mini.z.record(zod_mini.z.string(), zod_mini.z.strictObject({ injectHosts: zod_mini.z.array(zod_mini.z.string()) }));
|
|
8225
|
+
/**
|
|
8211
8226
|
* The Agent Host sandbox settings VS Code 1.141 settled on, as a nested object
|
|
8212
8227
|
* whose path mirrors the dotted setting key under `chat.agent.sandbox.` — e.g.
|
|
8213
8228
|
* `network.allowNetwork` writes `chat.agent.sandbox.network.allowNetwork`.
|
|
@@ -8229,7 +8244,8 @@ const CopilotSandboxSchema = zod_mini.z.strictObject({
|
|
|
8229
8244
|
lspServers: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
8230
8245
|
credentials: zod_mini.z.optional(zod_mini.z.strictObject({
|
|
8231
8246
|
authenticategit: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
8232
|
-
authenticategh: zod_mini.z.optional(zod_mini.z.boolean())
|
|
8247
|
+
authenticategh: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
8248
|
+
envVars: zod_mini.z.optional(CopilotSandboxCredentialEnvVarsSchema)
|
|
8233
8249
|
})),
|
|
8234
8250
|
fileSystem: zod_mini.z.optional(zod_mini.z.strictObject({
|
|
8235
8251
|
allowDevToolAccess: zod_mini.z.optional(zod_mini.z.boolean()),
|
|
@@ -9548,15 +9564,20 @@ const CodexcliPermissionsOverrideSchema = zod_mini.z.looseObject({
|
|
|
9548
9564
|
/**
|
|
9549
9565
|
* The `[auto_review]` table of `config.toml`, which configures the reviewer
|
|
9550
9566
|
* that `approvals_reviewer = "auto_review"` (Rulesync's default) selects:
|
|
9551
|
-
* `policy` / `extra_policy` (text inserted into the reviewer prompt
|
|
9567
|
+
* `policy` / `extra_policy` (text inserted into the reviewer prompt;
|
|
9568
|
+
* `extra_policy` only up to Codex 0.168.0),
|
|
9552
9569
|
* `timeout_ms` (the review budget, Codex 0.165.0+; `0` waits without a
|
|
9553
9570
|
* deadline), `circuit_break_action` (`default` | `strict`) and
|
|
9554
9571
|
* `conversation_history_max_output_tokens` (a positive token cap). Codex
|
|
9555
9572
|
* rejects the whole config file when one of these has the wrong type or is
|
|
9556
9573
|
* out of range (`timeout_ms` is a `u32`, the token cap a `NonZeroUsize`), so
|
|
9557
9574
|
* they are checked here; every other key passes through verbatim.
|
|
9575
|
+
* `extra_policy` and `experimental_policy_template` were removed in Codex
|
|
9576
|
+
* 0.169.0 (openai/codex PR #60646): newer Codex ignores them and warns at
|
|
9577
|
+
* startup (only `--strict-config` rejects them), so they are still accepted
|
|
9578
|
+
* and written for older Codex, and generate warns when they are authored.
|
|
9558
9579
|
*
|
|
9559
|
-
* @see https://github.com/openai/codex/blob/rust-v0.
|
|
9580
|
+
* @see https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/config/src/config_toml.rs (`AutoReviewToml`)
|
|
9560
9581
|
*/
|
|
9561
9582
|
auto_review: zod_mini.z.optional(zod_mini.z.looseObject({
|
|
9562
9583
|
policy: zod_mini.z.optional(zod_mini.z.string()),
|
|
@@ -14023,6 +14044,7 @@ const SHARED_CONFIG_OWNERSHIP = {
|
|
|
14023
14044
|
"chat.agent.sandbox.lspServers",
|
|
14024
14045
|
"chat.agent.sandbox.credentials.authenticategit",
|
|
14025
14046
|
"chat.agent.sandbox.credentials.authenticategh",
|
|
14047
|
+
"chat.agent.sandbox.credentials.envVars",
|
|
14026
14048
|
"chat.agent.sandbox.fileSystem.allowDevToolAccess",
|
|
14027
14049
|
"chat.agent.sandbox.fileSystem.userConfiguredPaths",
|
|
14028
14050
|
"zoo-code.allowedCommands",
|
|
@@ -51941,9 +51963,14 @@ const GooseCheckFrontmatterSchema = zod_mini.z.extend(AmpCheckFrontmatterSchema,
|
|
|
51941
51963
|
"turn-limit": zod_mini.z.optional(zod_mini.z.int().check(zod_mini.z.nonnegative()))
|
|
51942
51964
|
});
|
|
51943
51965
|
/**
|
|
51944
|
-
* Represents a Goose review check
|
|
51966
|
+
* Represents a Goose review check, written to the user-wide
|
|
51945
51967
|
* `~/.config/goose/checks/` (global scope only).
|
|
51946
51968
|
*
|
|
51969
|
+
* Goose v1.60.0 removed the `goose review` subcommand that ran these checks
|
|
51970
|
+
* (aaif-goose/goose#13469). Goose still discovers them, but only lists them as
|
|
51971
|
+
* agent sources (`properties.kind = "check"`), so `model` and `turn-limit`
|
|
51972
|
+
* have no runtime effect there.
|
|
51973
|
+
*
|
|
51947
51974
|
* Goose discovers repository checks in `.agents/checks/*.md`, the same
|
|
51948
51975
|
* cross-tool directory the `amp` checks target already writes (Goose's
|
|
51949
51976
|
* `tools` and `severity-default` fields exist for parity with Amp's), so the
|
|
@@ -56546,7 +56573,11 @@ const CLAUDE_SPEC = {
|
|
|
56546
56573
|
tool: "onFailure",
|
|
56547
56574
|
trueValue: "block",
|
|
56548
56575
|
falseValue: "continue",
|
|
56549
|
-
hookTypes: /* @__PURE__ */ new Set([
|
|
56576
|
+
hookTypes: /* @__PURE__ */ new Set([
|
|
56577
|
+
"command",
|
|
56578
|
+
"http",
|
|
56579
|
+
"mcp_tool"
|
|
56580
|
+
]),
|
|
56550
56581
|
ignoredEvents: /* @__PURE__ */ new Set([
|
|
56551
56582
|
"stop",
|
|
56552
56583
|
"subagentStop",
|
|
@@ -59858,7 +59889,7 @@ function canonicalToHermesHooks({ config, toolOverrideHooks, logger }) {
|
|
|
59858
59889
|
for (const [nativeEvent, definitions] of Object.entries(toolOverrideHooks ?? {})) {
|
|
59859
59890
|
if (HERMESAGENT_CANONICAL_EVENTS.has(nativeEvent)) continue;
|
|
59860
59891
|
if (HERMESAGENT_SHELL_UNSUPPORTED_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is Python-plugin-only; Hermes Agent refuses it for shell hooks, so the generated entry will never run.`);
|
|
59861
|
-
else if (!HERMESAGENT_NATIVE_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is not documented by Hermes Agent v0.
|
|
59892
|
+
else if (!HERMESAGENT_NATIVE_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is not documented by Hermes Agent v0.23.2; preserving it for forward compatibility.`);
|
|
59862
59893
|
setHermesHookEntries({
|
|
59863
59894
|
result,
|
|
59864
59895
|
event: nativeEvent,
|
|
@@ -60334,7 +60365,8 @@ const BLOCKING_HOOKS = new Set(Object.keys(NAMED_HOOK_MATCHER_SUBJECTS).filter((
|
|
|
60334
60365
|
* 5 minutes). Ordinary commands write to the host's stdout and stderr, as Bun
|
|
60335
60366
|
* Shell echoed them; a `preToolUse` command's are read, 1 MiB each kept (more
|
|
60336
60367
|
* stdout denies; on the Bun Shell fallback the whole output is buffered before
|
|
60337
|
-
* that check)
|
|
60368
|
+
* that check), and a `sessionStart` command's stdout is read the same way while
|
|
60369
|
+
* its stderr goes to the host's (after the command, on Bun Shell). Output
|
|
60338
60370
|
* pipes a background process keeps open are read for 1 s after the command
|
|
60339
60371
|
* exits; what arrived by then is kept, and the reads are then cancelled, as
|
|
60340
60372
|
* they are at a timeout. The OpenCode 1.x-style `event` hooks (`inProcess`)
|
|
@@ -60482,15 +60514,18 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60482
60514
|
" const timeout = () => new Promise((resolve) => (timer = setTimeout(resolve, seconds * 1000, null)));",
|
|
60483
60515
|
" if (inProcess || !(await __rulesyncCanExec)) {",
|
|
60484
60516
|
` const run = Bun.$\`echo \${input} | \${{ raw: command }}\`.cwd(${cwdExpression}).nothrow();`,
|
|
60485
|
-
"
|
|
60486
|
-
"
|
|
60517
|
+
" // A sessionStart command's stderr reaches the host when it ends, even after its timeout.",
|
|
60518
|
+
" const finished = echo === true ? run : run.quiet().then((done) => (echo && process.stderr.write(done.stderr), done));",
|
|
60519
|
+
" const result = await Promise.race([finished, timeout()]).finally(() => clearTimeout(timer));",
|
|
60520
|
+
" if (!result || echo === true) return result && { exitCode: result.exitCode };",
|
|
60487
60521
|
" const { exitCode, stdout, stderr } = result;",
|
|
60488
60522
|
" return { exitCode, stdout: stdout.toString(), stderr: stderr.toString(), overflow: stdout.length > 1048576 };",
|
|
60489
60523
|
" }",
|
|
60490
|
-
" // An ordinary command writes to the host's stdout and stderr; a preToolUse one is read
|
|
60491
|
-
"
|
|
60492
|
-
` const proc = ${spawn("\"export BUN_BE_BUN=\\n\" + command", "new TextEncoder().encode(input + \"\\n\")", "
|
|
60493
|
-
" const
|
|
60524
|
+
" // An ordinary command writes to the host's stdout and stderr; a preToolUse one is read, and",
|
|
60525
|
+
" // a sessionStart one (`echo: \"stderr\"`) has its stdout read.",
|
|
60526
|
+
` const proc = ${spawn("\"export BUN_BE_BUN=\\n\" + command", "new TextEncoder().encode(input + \"\\n\")", "echo === true ? \"inherit\" : \"pipe\"", "echo ? \"inherit\" : \"pipe\"")};`,
|
|
60527
|
+
" const stdout = echo === true ? undefined : __rulesyncRead(proc.stdout);",
|
|
60528
|
+
" const stderr = echo ? undefined : __rulesyncRead(proc.stderr);",
|
|
60494
60529
|
" const exitCode = await Promise.race([proc.exited, timeout()]).finally(() => clearTimeout(timer));",
|
|
60495
60530
|
" if (exitCode === null) {",
|
|
60496
60531
|
" stdout?.stop(), stderr?.stop();",
|
|
@@ -60498,15 +60533,15 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60498
60533
|
" else __rulesyncKillTree(proc);",
|
|
60499
60534
|
" return null;",
|
|
60500
60535
|
" }",
|
|
60501
|
-
" if (echo) return { exitCode };",
|
|
60502
|
-
" await Promise.race([Promise.all([stdout.done, stderr
|
|
60503
|
-
" stdout.stop(), stderr
|
|
60504
|
-
" return { exitCode, stdout: stdout.text(), stderr: stderr
|
|
60536
|
+
" if (echo === true) return { exitCode };",
|
|
60537
|
+
" await Promise.race([Promise.all([stdout.done, stderr?.done]), Bun.sleep(1000)]);",
|
|
60538
|
+
" stdout.stop(), stderr?.stop();",
|
|
60539
|
+
" return { exitCode, stdout: stdout.text(), stderr: stderr?.text() ?? \"\", overflow: stdout.overflow() };",
|
|
60505
60540
|
"};",
|
|
60506
|
-
"const __rulesyncRunHook = async ({ label, command, input, blocking, seconds, inProcess = false }) => {",
|
|
60541
|
+
"const __rulesyncRunHook = async ({ label, command, input, blocking, seconds, inProcess = false, context = false }) => {",
|
|
60507
60542
|
" let result;",
|
|
60508
60543
|
" try {",
|
|
60509
|
-
" result = await __rulesyncRunCommand({ command, input, seconds, inProcess, echo: true });",
|
|
60544
|
+
" result = await __rulesyncRunCommand({ command, input, seconds, inProcess, echo: context ? \"stderr\" : true });",
|
|
60510
60545
|
" } catch (error) {",
|
|
60511
60546
|
" if (blocking) throw error;",
|
|
60512
60547
|
" console.error(\"[rulesync-hooks] \" + label + \" hook failed:\", error);",
|
|
@@ -60517,7 +60552,7 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60517
60552
|
" if (blocking) throw new Error(message);",
|
|
60518
60553
|
" return console.error(message);",
|
|
60519
60554
|
" }",
|
|
60520
|
-
" if (result.exitCode === 0) return;",
|
|
60555
|
+
" if (result.exitCode === 0) return result;",
|
|
60521
60556
|
" const message = \"[rulesync-hooks] \" + label + \" hook exited with code \" + result.exitCode;",
|
|
60522
60557
|
" if (blocking) throw new Error(message);",
|
|
60523
60558
|
" console.error(message);",
|
|
@@ -60585,6 +60620,85 @@ const PRE_TOOL_USE_RESULT_HELPER_LINES = [
|
|
|
60585
60620
|
" );",
|
|
60586
60621
|
"};"
|
|
60587
60622
|
];
|
|
60623
|
+
/**
|
|
60624
|
+
* Helpers the generated plugin defines when a `sessionStart` handler is
|
|
60625
|
+
* present, so the command's stdout reaches the model as Claude Code's
|
|
60626
|
+
* `SessionStart` stdout does:
|
|
60627
|
+
* - `__rulesyncSessionStart(sessionID, run)` runs a session's `sessionStart`
|
|
60628
|
+
* commands (`run` pushes each command's result) and keeps the pending context
|
|
60629
|
+
* for that session. It always settles, since every command is bounded by its
|
|
60630
|
+
* timeout.
|
|
60631
|
+
* - `__rulesyncSessionContext(sessionID)` waits for that context, which the
|
|
60632
|
+
* host's system-prompt hook then adds to each model request of the session.
|
|
60633
|
+
*
|
|
60634
|
+
* A command's context is its stdout on exit code 0, or the
|
|
60635
|
+
* `hookSpecificOutput.additionalContext` string of a JSON object it prints,
|
|
60636
|
+
* trimmed and capped at Claude Code's 10,000 characters; more than 1 MiB of
|
|
60637
|
+
* stdout is logged and ignored. Only sessions whose context is not empty are
|
|
60638
|
+
* kept, the 100 whose context was used or became ready most recently, and a
|
|
60639
|
+
* deleted session is dropped.
|
|
60640
|
+
*/
|
|
60641
|
+
const SESSION_CONTEXT_HELPER_LINES = [
|
|
60642
|
+
"const __rulesyncSessionContexts = new Map();",
|
|
60643
|
+
"const __rulesyncKept = new WeakSet();",
|
|
60644
|
+
"const __rulesyncContextOf = (result) => {",
|
|
60645
|
+
" if (typeof result?.stdout !== \"string\") return \"\";",
|
|
60646
|
+
" if (result.overflow) {",
|
|
60647
|
+
" console.error(\"[rulesync-hooks] sessionStart hook wrote more than 1 MiB to stdout; it is ignored\");",
|
|
60648
|
+
" return \"\";",
|
|
60649
|
+
" }",
|
|
60650
|
+
" let text = result.stdout;",
|
|
60651
|
+
" try {",
|
|
60652
|
+
" const parsed = JSON.parse(text);",
|
|
60653
|
+
" // Like Claude Code, only a JSON object counts as JSON output; anything else is plain text.",
|
|
60654
|
+
" if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) text = parsed.hookSpecificOutput?.additionalContext;",
|
|
60655
|
+
" } catch {}",
|
|
60656
|
+
" return typeof text === \"string\" ? text.trim().slice(0, 10000) : \"\";",
|
|
60657
|
+
"};",
|
|
60658
|
+
"const __rulesyncSessionStart = (sessionID, run) => {",
|
|
60659
|
+
" const results = [];",
|
|
60660
|
+
" const pending = run(results)",
|
|
60661
|
+
" .catch(() => {})",
|
|
60662
|
+
" .then(() => results.map(__rulesyncContextOf).filter(Boolean).join(\"\\n\\n\"));",
|
|
60663
|
+
" if (typeof sessionID === \"string\") {",
|
|
60664
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60665
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60666
|
+
" // Only a non-empty context is kept, and only it counts towards the 100: a running",
|
|
60667
|
+
" // or empty one never evicts another session's context.",
|
|
60668
|
+
" pending.then((context) => {",
|
|
60669
|
+
" if (__rulesyncSessionContexts.get(sessionID) !== pending) return;",
|
|
60670
|
+
" if (!context) return void __rulesyncSessionContexts.delete(sessionID);",
|
|
60671
|
+
" __rulesyncKept.add(pending);",
|
|
60672
|
+
" // Evict in completion order: a context counts as used once it is ready.",
|
|
60673
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60674
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60675
|
+
" const kept = [...__rulesyncSessionContexts].filter(([, entry]) => __rulesyncKept.has(entry));",
|
|
60676
|
+
" if (kept.length > 100) __rulesyncSessionContexts.delete(kept[0][0]);",
|
|
60677
|
+
" });",
|
|
60678
|
+
" }",
|
|
60679
|
+
" return pending;",
|
|
60680
|
+
"};",
|
|
60681
|
+
"const __rulesyncSessionContext = async (sessionID) => {",
|
|
60682
|
+
" const pending = __rulesyncSessionContexts.get(sessionID);",
|
|
60683
|
+
" if (!pending) return \"\";",
|
|
60684
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60685
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60686
|
+
" return pending;",
|
|
60687
|
+
"};"
|
|
60688
|
+
];
|
|
60689
|
+
/**
|
|
60690
|
+
* The statements of a `sessionStart` group, run through `__rulesyncSessionStart`.
|
|
60691
|
+
* `__rulesyncSessionStart` registers the session's pending context before its
|
|
60692
|
+
* first `await`, so `"void"` (used by the serial V2 event loop) registers it
|
|
60693
|
+
* as soon as the event is read without waiting for the commands.
|
|
60694
|
+
*/
|
|
60695
|
+
function wrapSessionStartLines(sessionIdExpression, statements, operator = "await") {
|
|
60696
|
+
return [
|
|
60697
|
+
`${operator} __rulesyncSessionStart(${sessionIdExpression}, async (__rulesyncResults) => {`,
|
|
60698
|
+
...statements.map((line) => ` ${line}`),
|
|
60699
|
+
"});"
|
|
60700
|
+
];
|
|
60701
|
+
}
|
|
60588
60702
|
function escapeForTemplateLiteral(command) {
|
|
60589
60703
|
return command.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
60590
60704
|
}
|
|
@@ -60645,6 +60759,14 @@ function warnIgnoredFailClosed({ config, supportedEvents, toolConfigKey, logger
|
|
|
60645
60759
|
}
|
|
60646
60760
|
}
|
|
60647
60761
|
}
|
|
60762
|
+
/** Whether any handler is a `sessionStart` one, whose stdout becomes session context. */
|
|
60763
|
+
function usesSessionContext(handlers) {
|
|
60764
|
+
return handlers.some((handler) => handler.context);
|
|
60765
|
+
}
|
|
60766
|
+
/** The handler fields a canonical event's `sessionStart`-ness adds. */
|
|
60767
|
+
function sessionContextExtrasFor(canonicalEvent) {
|
|
60768
|
+
return canonicalEvent === "sessionStart" ? { context: true } : {};
|
|
60769
|
+
}
|
|
60648
60770
|
/** The per-canonical-event gates and payload every handler of it carries. */
|
|
60649
60771
|
function handlerExtrasFor(canonicalEvent) {
|
|
60650
60772
|
const shellGate = SHELL_EVENT_TOOL_GATES[canonicalEvent];
|
|
@@ -60654,7 +60776,8 @@ function handlerExtrasFor(canonicalEvent) {
|
|
|
60654
60776
|
event: canonicalEvent,
|
|
60655
60777
|
...shellGate ? { toolGate: shellGate.tool } : {},
|
|
60656
60778
|
...propertyGate ? { propertyGate } : {},
|
|
60657
|
-
...payload ? { payload } : {}
|
|
60779
|
+
...payload ? { payload } : {},
|
|
60780
|
+
...sessionContextExtrasFor(canonicalEvent)
|
|
60658
60781
|
};
|
|
60659
60782
|
}
|
|
60660
60783
|
/**
|
|
@@ -60696,22 +60819,22 @@ function buildGenericEventBodyLines(genericEventHandlers) {
|
|
|
60696
60819
|
const bodyLines = [];
|
|
60697
60820
|
if (Object.keys(genericEventHandlers).length === 0) return bodyLines;
|
|
60698
60821
|
bodyLines.push(" event: async ({ event }) => {");
|
|
60822
|
+
if (Object.values(genericEventHandlers).some(usesSessionContext)) bodyLines.push(` if (event.type === "session.deleted") __rulesyncSessionContexts.delete(${V1_SESSION_ID_EXPRESSION});`);
|
|
60699
60823
|
let isFirst = true;
|
|
60700
60824
|
for (const [eventName, handlers] of Object.entries(genericEventHandlers)) {
|
|
60701
60825
|
bodyLines.push(` ${isFirst ? "if" : "else if"} (event.type === "${eventName}") {`);
|
|
60702
60826
|
isFirst = false;
|
|
60703
|
-
|
|
60827
|
+
const statements = buildPayloadClosureLines({
|
|
60704
60828
|
handlers,
|
|
60705
60829
|
cwdExpression: V1_CWD_EXPRESSION
|
|
60706
|
-
})
|
|
60830
|
+
});
|
|
60707
60831
|
for (const handler of handlers) {
|
|
60708
60832
|
const runStatement = buildRunStatement(handler);
|
|
60709
|
-
if (handler.propertyGate) {
|
|
60710
|
-
|
|
60711
|
-
bodyLines.push(` ${runStatement}`);
|
|
60712
|
-
bodyLines.push(" }");
|
|
60713
|
-
} else bodyLines.push(` ${runStatement}`);
|
|
60833
|
+
if (handler.propertyGate) statements.push(`if (${handler.propertyGate}) {`, ` ${runStatement}`, "}");
|
|
60834
|
+
else statements.push(runStatement);
|
|
60714
60835
|
}
|
|
60836
|
+
const lines = usesSessionContext(handlers) ? wrapSessionStartLines(V1_SESSION_ID_EXPRESSION, statements) : statements;
|
|
60837
|
+
bodyLines.push(...lines.map((line) => ` ${line}`));
|
|
60715
60838
|
bodyLines.push(" }");
|
|
60716
60839
|
}
|
|
60717
60840
|
bodyLines.push(" },");
|
|
@@ -60722,6 +60845,19 @@ function stdinPayloadVariable(stdinEvent) {
|
|
|
60722
60845
|
}
|
|
60723
60846
|
/** The `cwd` a V1 payload reports: the session directory, else the process's. */
|
|
60724
60847
|
const V1_CWD_EXPRESSION = "directory ?? process.cwd()";
|
|
60848
|
+
/** The session a V1 `session.created` / `session.deleted` event is about. */
|
|
60849
|
+
const V1_SESSION_ID_EXPRESSION = "event.properties?.info?.id";
|
|
60850
|
+
/**
|
|
60851
|
+
* The V1 named hook that adds a session's `sessionStart` context to the system
|
|
60852
|
+
* prompt of each of its model requests. OpenCode 1.x, Kilo and MiMo Code all
|
|
60853
|
+
* call it with the request's `sessionID`.
|
|
60854
|
+
*/
|
|
60855
|
+
const V1_SYSTEM_TRANSFORM_LINES = [
|
|
60856
|
+
" \"experimental.chat.system.transform\": async (input, output) => {",
|
|
60857
|
+
" const context = await __rulesyncSessionContext(input?.sessionID);",
|
|
60858
|
+
" if (context && Array.isArray(output?.system)) output.system.push(context);",
|
|
60859
|
+
" },"
|
|
60860
|
+
];
|
|
60725
60861
|
/** Lazily serialized closures for the payloads the handlers use (internal tables only). */
|
|
60726
60862
|
function buildPayloadClosureLines({ handlers, cwdExpression }) {
|
|
60727
60863
|
const payloads = /* @__PURE__ */ new Map();
|
|
@@ -60749,20 +60885,27 @@ function buildRunStatement(handler) {
|
|
|
60749
60885
|
const failClosed = handler.failClosed === void 0 ? "" : `, ${handler.failClosed}`;
|
|
60750
60886
|
return `${PRE_TOOL_USE_RESULT_HELPER}(await __rulesyncRunCommand({ command: ${command}, input: ${input}, seconds: ${handler.timeout} })${failClosed});`;
|
|
60751
60887
|
}
|
|
60752
|
-
|
|
60888
|
+
const run = `await __rulesyncRunHook({ ${[
|
|
60753
60889
|
`label: ${JSON.stringify(handler.event)}`,
|
|
60754
60890
|
`command: ${command}`,
|
|
60755
60891
|
`input: ${input}`,
|
|
60756
60892
|
`blocking: ${handler.blocking}`,
|
|
60757
60893
|
`seconds: ${handler.timeout}`,
|
|
60758
|
-
...handler.inProcess ? ["inProcess: true"] : []
|
|
60759
|
-
|
|
60894
|
+
...handler.inProcess ? ["inProcess: true"] : [],
|
|
60895
|
+
...handler.context ? ["context: true"] : []
|
|
60896
|
+
].join(", ")} })`;
|
|
60897
|
+
return handler.context ? `__rulesyncResults.push(${run});` : `${run};`;
|
|
60760
60898
|
}
|
|
60761
60899
|
/** The helpers a plugin body defines before its handlers, run in `cwdExpression`. */
|
|
60762
60900
|
function buildRunHelperLines({ handlers, cwdExpression }) {
|
|
60763
60901
|
if (handlers.length === 0) return [];
|
|
60764
60902
|
const usesPreToolUse = handlers.some((handler) => handler.payload?.name === "PreToolUse");
|
|
60765
|
-
|
|
60903
|
+
const usesContext = usesSessionContext(handlers);
|
|
60904
|
+
return [
|
|
60905
|
+
...buildRunHelperLinesFor(cwdExpression),
|
|
60906
|
+
...usesPreToolUse ? ["", ...PRE_TOOL_USE_RESULT_HELPER_LINES] : [],
|
|
60907
|
+
...usesContext ? ["", ...SESSION_CONTEXT_HELPER_LINES] : []
|
|
60908
|
+
];
|
|
60766
60909
|
}
|
|
60767
60910
|
/** Emit the named (`tool.execute.*`) handler blocks. */
|
|
60768
60911
|
function buildNamedEventBodyLines(namedEventHandlers) {
|
|
@@ -60836,7 +60979,12 @@ function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey,
|
|
|
60836
60979
|
namedEventHandlers,
|
|
60837
60980
|
genericEventHandlers
|
|
60838
60981
|
});
|
|
60839
|
-
const
|
|
60982
|
+
const usesContext = Object.values(genericEventHandlers).some(usesSessionContext);
|
|
60983
|
+
const bodyLines = [
|
|
60984
|
+
...buildGenericEventBodyLines(genericEventHandlers),
|
|
60985
|
+
...buildNamedEventBodyLines(namedEventHandlers),
|
|
60986
|
+
...usesContext ? V1_SYSTEM_TRANSFORM_LINES : []
|
|
60987
|
+
];
|
|
60840
60988
|
return wrapInExportShape({
|
|
60841
60989
|
preambleLines: buildRunHelperLines({
|
|
60842
60990
|
handlers: [...Object.values(namedEventHandlers), ...Object.values(genericEventHandlers)].flat(),
|
|
@@ -61149,6 +61297,37 @@ const KiroIdeHooksFileSchema = zod_mini.z.looseObject({
|
|
|
61149
61297
|
hooks: zod_mini.z.optional(zod_mini.z.array(KiroIdeHookEntrySchema))
|
|
61150
61298
|
});
|
|
61151
61299
|
/**
|
|
61300
|
+
* Triggers on which Kiro runs only `command` actions.
|
|
61301
|
+
* @see https://kiro.dev/docs/hooks/types/#permission-request
|
|
61302
|
+
*/
|
|
61303
|
+
const KIRO_COMMAND_ONLY_TRIGGERS = /* @__PURE__ */ new Set(["PermissionRequest"]);
|
|
61304
|
+
/**
|
|
61305
|
+
* Whether an imported entry is an `agent` action on a command-only trigger
|
|
61306
|
+
* (Kiro also accepts the camelCase `permissionRequest` spelling). Kiro never
|
|
61307
|
+
* runs such a hook, so importing it would hand other targets an LLM
|
|
61308
|
+
* permission hook the user never had in effect.
|
|
61309
|
+
*/
|
|
61310
|
+
function isAgentActionOnCommandOnlyTrigger(entry) {
|
|
61311
|
+
if (entry.action?.type !== "agent" || entry.trigger === void 0) return false;
|
|
61312
|
+
const trigger = lookupOwn({
|
|
61313
|
+
record: CANONICAL_TO_KIRO_IDE_EVENT_NAMES,
|
|
61314
|
+
key: entry.trigger
|
|
61315
|
+
}) ?? entry.trigger;
|
|
61316
|
+
return KIRO_COMMAND_ONLY_TRIGGERS.has(trigger);
|
|
61317
|
+
}
|
|
61318
|
+
/**
|
|
61319
|
+
* Drop `prompt` definitions on a {@link KIRO_COMMAND_ONLY_TRIGGERS} trigger with
|
|
61320
|
+
* a warning, rather than writing an `agent` action Kiro never runs.
|
|
61321
|
+
*/
|
|
61322
|
+
function dropPromptHooksOnCommandOnlyTrigger(trigger, definitions, logger) {
|
|
61323
|
+
if (!KIRO_COMMAND_ONLY_TRIGGERS.has(trigger)) return definitions;
|
|
61324
|
+
return definitions.filter((def) => {
|
|
61325
|
+
if (def.type !== "prompt") return true;
|
|
61326
|
+
logger?.warn(`Skipped a prompt hook on Kiro's "${trigger}" trigger: Kiro runs only command actions on it.`);
|
|
61327
|
+
return false;
|
|
61328
|
+
});
|
|
61329
|
+
}
|
|
61330
|
+
/**
|
|
61152
61331
|
* Build the Kiro IDE hook entries for a single canonical event's definitions.
|
|
61153
61332
|
*
|
|
61154
61333
|
* `command`-type definitions become `{ type: "command", command }` actions and
|
|
@@ -61203,7 +61382,7 @@ const KIRO_HOOKS_OVERRIDE_KEY = "kiro";
|
|
|
61203
61382
|
* that is actually read.
|
|
61204
61383
|
*/
|
|
61205
61384
|
const KIRO_HOOKS_IGNORED_OVERRIDE_KEYS = ["kiro-ide", "kiro-cli"];
|
|
61206
|
-
function canonicalToKiroIdeHooks(config) {
|
|
61385
|
+
function canonicalToKiroIdeHooks(config, logger) {
|
|
61207
61386
|
const kiroIdeSupported = new Set(KIRO_IDE_HOOK_EVENTS);
|
|
61208
61387
|
const sharedHooks = {};
|
|
61209
61388
|
for (const [event, defs] of Object.entries(config.hooks)) if (kiroIdeSupported.has(event)) sharedHooks[event] = defs;
|
|
@@ -61220,7 +61399,7 @@ function canonicalToKiroIdeHooks(config) {
|
|
|
61220
61399
|
record: KIRO_LEGACY_TO_KIRO_IDE_TRIGGER_NAMES,
|
|
61221
61400
|
key: eventName
|
|
61222
61401
|
}) ?? eventName;
|
|
61223
|
-
entries.push(...buildKiroIdeEntriesForEvent(trigger, definitions));
|
|
61402
|
+
entries.push(...buildKiroIdeEntriesForEvent(trigger, dropPromptHooksOnCommandOnlyTrigger(trigger, definitions, logger)));
|
|
61224
61403
|
}
|
|
61225
61404
|
return entries;
|
|
61226
61405
|
}
|
|
@@ -61232,25 +61411,35 @@ function copyOptionalHookFields({ entry, def }) {
|
|
|
61232
61411
|
if (entry.enabled === false) def.enabled = false;
|
|
61233
61412
|
if (entry.confirm !== void 0 && entry.confirm !== null) def.confirm = omitPrototypePollutionKeysDeep(entry.confirm);
|
|
61234
61413
|
}
|
|
61235
|
-
|
|
61414
|
+
/**
|
|
61415
|
+
* The canonical `type` plus `command` / `prompt` of an imported Kiro action, or
|
|
61416
|
+
* `undefined` when the action carries nothing to run.
|
|
61417
|
+
*/
|
|
61418
|
+
function toCanonicalAction(action) {
|
|
61419
|
+
if (action.type === "command") return action.command ? {
|
|
61420
|
+
type: "command",
|
|
61421
|
+
command: action.command
|
|
61422
|
+
} : void 0;
|
|
61423
|
+
return action.prompt ? {
|
|
61424
|
+
type: "prompt",
|
|
61425
|
+
prompt: action.prompt
|
|
61426
|
+
} : void 0;
|
|
61427
|
+
}
|
|
61428
|
+
function kiroIdeHooksToCanonical(entries, logger) {
|
|
61236
61429
|
const canonical = {};
|
|
61237
61430
|
for (const entry of entries) {
|
|
61238
61431
|
if (entry.trigger === void 0 || entry.action === void 0) continue;
|
|
61432
|
+
if (isAgentActionOnCommandOnlyTrigger(entry)) {
|
|
61433
|
+
logger?.warn(`Skipped an agent hook on Kiro's "${entry.trigger}" trigger: Kiro runs only command actions on it.`);
|
|
61434
|
+
continue;
|
|
61435
|
+
}
|
|
61239
61436
|
const eventName = lookupOwn({
|
|
61240
61437
|
record: KIRO_IDE_TO_CANONICAL_EVENT_NAMES,
|
|
61241
61438
|
key: entry.trigger
|
|
61242
61439
|
}) ?? entry.trigger;
|
|
61243
61440
|
if (isPrototypePollutionKey(eventName)) continue;
|
|
61244
|
-
const def =
|
|
61245
|
-
if (
|
|
61246
|
-
if (!entry.action.command) continue;
|
|
61247
|
-
def.type = "command";
|
|
61248
|
-
def.command = entry.action.command;
|
|
61249
|
-
} else {
|
|
61250
|
-
if (!entry.action.prompt) continue;
|
|
61251
|
-
def.type = "prompt";
|
|
61252
|
-
def.prompt = entry.action.prompt;
|
|
61253
|
-
}
|
|
61441
|
+
const def = toCanonicalAction(entry.action);
|
|
61442
|
+
if (def === void 0) continue;
|
|
61254
61443
|
if (entry.name !== void 0 && entry.name !== null) def.name = entry.name;
|
|
61255
61444
|
if (entry.description !== void 0 && entry.description !== null) def.description = entry.description;
|
|
61256
61445
|
if (entry.matcher !== void 0 && entry.matcher !== null && entry.matcher !== "") def.matcher = entry.matcher;
|
|
@@ -61316,7 +61505,7 @@ var KiroIdeHooks = class extends ToolHooks {
|
|
|
61316
61505
|
if (config[ignoredKey]?.hooks === void 0) continue;
|
|
61317
61506
|
logger?.warn(`The "${ignoredKey}.hooks" block in ${(0, node_path.join)(rulesyncHooks.getRelativeDirPath(), rulesyncHooks.getRelativeFilePath())} is ignored. Author it under the "${KIRO_HOOKS_OVERRIDE_KEY}.hooks" key instead: the Kiro IDE and Kiro CLI targets write the same hooks file, so they read one shared block.`);
|
|
61318
61507
|
}
|
|
61319
|
-
const hooks = canonicalToKiroIdeHooks(config);
|
|
61508
|
+
const hooks = canonicalToKiroIdeHooks(config, logger);
|
|
61320
61509
|
const fileContent = JSON.stringify({
|
|
61321
61510
|
version: "v1",
|
|
61322
61511
|
hooks
|
|
@@ -61333,7 +61522,7 @@ var KiroIdeHooks = class extends ToolHooks {
|
|
|
61333
61522
|
const hooks = kiroIdeHooksToCanonical(this.parseFileContentOrThrow({
|
|
61334
61523
|
displayName: "Kiro IDE",
|
|
61335
61524
|
parse: (fileContent) => KiroIdeHooksFileSchema.parse(JSON.parse(fileContent))
|
|
61336
|
-
}).hooks ?? []);
|
|
61525
|
+
}).hooks ?? [], logger);
|
|
61337
61526
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
61338
61527
|
logger,
|
|
61339
61528
|
hooks,
|
|
@@ -61765,6 +61954,27 @@ const TOOL_MATCHER_HELPER_LINES = [
|
|
|
61765
61954
|
];
|
|
61766
61955
|
/** Hook points whose `matcher` is tested against the tool name. */
|
|
61767
61956
|
const OPENCODE_V2_MATCHABLE_HOOKS = /* @__PURE__ */ new Set(["tool:execute.before", "tool:execute.after"]);
|
|
61957
|
+
/** The session a V2 `session.created` / `session.deleted` event is about. */
|
|
61958
|
+
const V2_SESSION_ID_EXPRESSION = "event.data?.sessionID";
|
|
61959
|
+
/**
|
|
61960
|
+
* The `session:context` registration that adds a session's `sessionStart`
|
|
61961
|
+
* context to the system prompt of each of its agent-loop model requests. A
|
|
61962
|
+
* host that cannot register it (no `ctx.session.hook`, or no `context` hook
|
|
61963
|
+
* point) gets a logged error instead of a setup throw, so the plugin's other
|
|
61964
|
+
* hooks, `preToolUse` guards included, still load.
|
|
61965
|
+
*/
|
|
61966
|
+
const SESSION_CONTEXT_HOOK_LINES = [
|
|
61967
|
+
"try {",
|
|
61968
|
+
" __rulesyncRegistrations.push(",
|
|
61969
|
+
" await ctx.session.hook(\"context\", async (event) => {",
|
|
61970
|
+
" const context = await __rulesyncSessionContext(event?.sessionID);",
|
|
61971
|
+
" if (context && Array.isArray(event?.system)) event.system.push({ type: \"text\", text: context });",
|
|
61972
|
+
" }),",
|
|
61973
|
+
" );",
|
|
61974
|
+
"} catch (error) {",
|
|
61975
|
+
" console.error(\"[rulesync-hooks] could not register the session context hook; sessionStart output does not reach the model:\", error);",
|
|
61976
|
+
"}"
|
|
61977
|
+
];
|
|
61768
61978
|
/** Wrap a statement in the handler's gate and matcher conditions. */
|
|
61769
61979
|
function wrapInConditions(handler, statement, indent) {
|
|
61770
61980
|
const conditions = [];
|
|
@@ -61801,32 +62011,52 @@ function buildHookRegistrationLines(hookPoint, handlers) {
|
|
|
61801
62011
|
* in its own try/catch, so a throw while evaluating its gate or building its
|
|
61802
62012
|
* payload, outside `__rulesyncRunHook`, is logged the same way. The
|
|
61803
62013
|
* subscription passes `types` so the server delivers only the handled events.
|
|
62014
|
+
*
|
|
62015
|
+
* The loop itself never waits for a command, so a slow handler cannot hold back
|
|
62016
|
+
* the events after it: handlers run one after another on
|
|
62017
|
+
* `__rulesyncEventQueue`, in event order, while `sessionStart` starts right
|
|
62018
|
+
* away, outside the queue (so it can overlap other event commands), and its
|
|
62019
|
+
* session's pending context is registered before that session's first model
|
|
62020
|
+
* request asks for it. Handlers still queued at dispose are skipped.
|
|
61804
62021
|
*/
|
|
61805
|
-
function buildEventLoopLines(eventHandlers) {
|
|
62022
|
+
function buildEventLoopLines(eventHandlers, usesContext) {
|
|
61806
62023
|
const lines = [];
|
|
61807
|
-
const
|
|
62024
|
+
const eventTypes = new Set(eventHandlers.keys());
|
|
62025
|
+
if (usesContext) eventTypes.add("session.deleted");
|
|
62026
|
+
const types = [...eventTypes].map((eventType) => JSON.stringify(eventType)).join(", ");
|
|
61808
62027
|
lines.push("const __rulesyncEvents = new AbortController();");
|
|
62028
|
+
lines.push("let __rulesyncEventQueue = Promise.resolve();");
|
|
61809
62029
|
lines.push("void (async () => {");
|
|
61810
62030
|
lines.push(" for await (const event of ctx.event.subscribe({");
|
|
61811
62031
|
lines.push(` types: [${types}],`);
|
|
61812
62032
|
lines.push(" signal: __rulesyncEvents.signal,");
|
|
61813
62033
|
lines.push(" })) {");
|
|
62034
|
+
if (usesContext) lines.push(` if (event.type === "session.deleted") __rulesyncSessionContexts.delete(${V2_SESSION_ID_EXPRESSION});`);
|
|
61814
62035
|
let isFirst = true;
|
|
61815
62036
|
for (const [eventType, handlers] of eventHandlers) {
|
|
61816
62037
|
lines.push(` ${isFirst ? "if" : "} else if"} (event.type === "${eventType}") {`);
|
|
61817
62038
|
isFirst = false;
|
|
61818
|
-
|
|
62039
|
+
const statements = buildPayloadClosureLines({
|
|
61819
62040
|
handlers,
|
|
61820
62041
|
cwdExpression: "directory"
|
|
61821
|
-
})
|
|
62042
|
+
});
|
|
61822
62043
|
for (const handler of handlers) {
|
|
61823
|
-
|
|
61824
|
-
|
|
61825
|
-
|
|
62044
|
+
statements.push("try {");
|
|
62045
|
+
statements.push(...wrapInConditions(handler, buildRunStatement(handler), " "));
|
|
62046
|
+
statements.push("} catch (error) {");
|
|
61826
62047
|
const message = JSON.stringify(`[rulesync-hooks] ${handler.event} hook failed:`);
|
|
61827
|
-
|
|
61828
|
-
|
|
61829
|
-
}
|
|
62048
|
+
statements.push(` console.error(${message}, error);`);
|
|
62049
|
+
statements.push("}");
|
|
62050
|
+
}
|
|
62051
|
+
const body = usesSessionContext(handlers) ? wrapSessionStartLines(V2_SESSION_ID_EXPRESSION, statements, "void") : [
|
|
62052
|
+
"__rulesyncEventQueue = __rulesyncEventQueue",
|
|
62053
|
+
" .then(async () => {",
|
|
62054
|
+
" if (__rulesyncEvents.signal.aborted) return;",
|
|
62055
|
+
...statements.map((line) => ` ${line}`),
|
|
62056
|
+
" })",
|
|
62057
|
+
` .catch((error) => console.error(${JSON.stringify(`[rulesync-hooks] ${eventType} event hook failed:`)}, error));`
|
|
62058
|
+
];
|
|
62059
|
+
lines.push(...body.map((line) => ` ${line}`));
|
|
61830
62060
|
}
|
|
61831
62061
|
lines.push(" }");
|
|
61832
62062
|
lines.push(" }");
|
|
@@ -61857,7 +62087,8 @@ function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
|
61857
62087
|
...hookTimingOf(def),
|
|
61858
62088
|
...def.matcher ? { matcher: def.matcher } : {},
|
|
61859
62089
|
...gate ? { gate } : {},
|
|
61860
|
-
...payload ? { payload } : {}
|
|
62090
|
+
...payload ? { payload } : {},
|
|
62091
|
+
...sessionContextExtrasFor(canonicalEvent)
|
|
61861
62092
|
});
|
|
61862
62093
|
}
|
|
61863
62094
|
return handlers;
|
|
@@ -61874,16 +62105,19 @@ function buildSetupBodyLines({ hookHandlers, eventHandlers }) {
|
|
|
61874
62105
|
})
|
|
61875
62106
|
];
|
|
61876
62107
|
if ([...hookHandlers.values()].some((handlers) => handlers.some((handler) => handler.matcher !== void 0))) body.push("", ...TOOL_MATCHER_HELPER_LINES);
|
|
62108
|
+
const usesContext = [...eventHandlers.values()].some(usesSessionContext);
|
|
62109
|
+
const registers = hookHandlers.size > 0 || usesContext;
|
|
61877
62110
|
const cleanup = [];
|
|
61878
|
-
if (
|
|
62111
|
+
if (registers) {
|
|
61879
62112
|
body.push("", "const __rulesyncRegistrations = [];");
|
|
61880
62113
|
for (const [hookPoint, handlers] of hookHandlers) body.push(...buildHookRegistrationLines(hookPoint, handlers));
|
|
62114
|
+
if (usesContext) body.push(...SESSION_CONTEXT_HOOK_LINES);
|
|
61881
62115
|
}
|
|
61882
62116
|
if (eventHandlers.size > 0) {
|
|
61883
|
-
body.push("", ...buildEventLoopLines(eventHandlers));
|
|
62117
|
+
body.push("", ...buildEventLoopLines(eventHandlers, usesContext));
|
|
61884
62118
|
cleanup.push(" __rulesyncEvents.abort();");
|
|
61885
62119
|
}
|
|
61886
|
-
if (
|
|
62120
|
+
if (registers) cleanup.push(" await Promise.all(__rulesyncRegistrations.map((registration) => registration.dispose()));");
|
|
61887
62121
|
body.push("", "return async () => {", ...cleanup, "};");
|
|
61888
62122
|
return body;
|
|
61889
62123
|
}
|
|
@@ -72723,12 +72957,22 @@ const MAX_REMOVE_EMPTY_ENTRIES_DEPTH = 32;
|
|
|
72723
72957
|
*/
|
|
72724
72958
|
const GROK_DISABLED_MCP_TOOLS_KEY = "disabled_mcp_tools";
|
|
72725
72959
|
/**
|
|
72960
|
+
* Grok 1.0.88+ runs a command that prints JSON headers at every connect of an
|
|
72961
|
+
* HTTP/SSE server. In `config.toml` the key is `headers_helper`; the camelCase
|
|
72962
|
+
* `headersHelper` (rulesync's canonical spelling) is documented for
|
|
72963
|
+
* `.mcp.json` only, so it is renamed in both directions.
|
|
72964
|
+
* (Grok user guide `07-mcp-servers.md`, "Headers from a command".)
|
|
72965
|
+
*/
|
|
72966
|
+
const CANONICAL_HEADERS_HELPER_KEY = "headersHelper";
|
|
72967
|
+
const GROK_HEADERS_HELPER_KEY = "headers_helper";
|
|
72968
|
+
/**
|
|
72726
72969
|
* Grok Build stores MCP servers in `config.toml` under a `[mcp_servers.<name>]`
|
|
72727
72970
|
* table. Verified against `grok mcp add` (grok 0.2.54): a stdio server emits
|
|
72728
72971
|
* `command`, `args`, `enabled = true`, and an `[mcp_servers.<name>.env]` table;
|
|
72729
72972
|
* a remote server emits `url` and `enabled`. Unlike Codex CLI, Grok uses a
|
|
72730
|
-
* literal `env` table (not the `env_vars` passthrough list), so the
|
|
72731
|
-
*
|
|
72973
|
+
* literal `env` table (not the `env_vars` passthrough list), so the field
|
|
72974
|
+
* renames are `disabled` (rulesync) ↔ `enabled = false` (grok) and
|
|
72975
|
+
* `headersHelper` ↔ `headers_helper`. `disabledTools`
|
|
72732
72976
|
* never lands in the server table: it is lifted into the top-level
|
|
72733
72977
|
* `[disabled_mcp_tools]` table by `buildDisabledMcpTools`.
|
|
72734
72978
|
*/
|
|
@@ -72742,6 +72986,8 @@ function convertToGrokFormat(mcpServers) {
|
|
|
72742
72986
|
if (PROTOTYPE_POLLUTION_KEYS.has(key) || key === "disabledTools") continue;
|
|
72743
72987
|
if (key === "disabled") {
|
|
72744
72988
|
if (value === true) converted["enabled"] = false;
|
|
72989
|
+
} else if (key === CANONICAL_HEADERS_HELPER_KEY) {
|
|
72990
|
+
if (!Object.hasOwn(config, GROK_HEADERS_HELPER_KEY)) converted[GROK_HEADERS_HELPER_KEY] = value;
|
|
72745
72991
|
} else converted[key] = value;
|
|
72746
72992
|
}
|
|
72747
72993
|
result[name] = converted;
|
|
@@ -72757,6 +73003,9 @@ function convertFromGrokFormat(grokMcp) {
|
|
|
72757
73003
|
if (PROTOTYPE_POLLUTION_KEYS.has(key)) continue;
|
|
72758
73004
|
if (key === "enabled") {
|
|
72759
73005
|
if (value === false) converted["disabled"] = true;
|
|
73006
|
+
} else if (key === GROK_HEADERS_HELPER_KEY) converted[CANONICAL_HEADERS_HELPER_KEY] = value;
|
|
73007
|
+
else if (key === CANONICAL_HEADERS_HELPER_KEY) {
|
|
73008
|
+
if (!Object.hasOwn(config, GROK_HEADERS_HELPER_KEY)) converted[CANONICAL_HEADERS_HELPER_KEY] = value;
|
|
72760
73009
|
} else converted[key] = value;
|
|
72761
73010
|
}
|
|
72762
73011
|
result[name] = converted;
|
|
@@ -73872,6 +74121,21 @@ function fromKiroMcpServers(servers) {
|
|
|
73872
74121
|
}];
|
|
73873
74122
|
}));
|
|
73874
74123
|
}
|
|
74124
|
+
/**
|
|
74125
|
+
* Parse an existing user-level `~/.kiro/settings/mcp.json` so a global generate
|
|
74126
|
+
* can merge into it. An unparseable file is refused instead of overwritten:
|
|
74127
|
+
* it is unversioned, so replacing it would lose whatever the user had there.
|
|
74128
|
+
*/
|
|
74129
|
+
function parseExistingKiroMcpConfig(fileContent, configPath) {
|
|
74130
|
+
let parsed;
|
|
74131
|
+
try {
|
|
74132
|
+
parsed = JSON.parse(fileContent);
|
|
74133
|
+
} catch (error) {
|
|
74134
|
+
throw new Error(`Failed to parse Kiro MCP config at ${configPath}: ${formatError(error)}`, { cause: error });
|
|
74135
|
+
}
|
|
74136
|
+
if (!isPlainObject(parsed)) throw new Error(`Failed to parse Kiro MCP config at ${configPath}: expected a JSON object`);
|
|
74137
|
+
return parsed;
|
|
74138
|
+
}
|
|
73875
74139
|
var KiroMcp = class KiroMcp extends ToolMcp {
|
|
73876
74140
|
json;
|
|
73877
74141
|
constructor(params) {
|
|
@@ -73881,13 +74145,26 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73881
74145
|
getJson() {
|
|
73882
74146
|
return this.json;
|
|
73883
74147
|
}
|
|
74148
|
+
/**
|
|
74149
|
+
* The user-level `~/.kiro/settings/mcp.json` also holds settings rulesync
|
|
74150
|
+
* does not manage (such as the top-level `identityProvider` block for
|
|
74151
|
+
* organization sign-in, which Kiro reads only from this file), so it is never
|
|
74152
|
+
* deleted in global mode. The project file is rulesync-managed and may be.
|
|
74153
|
+
* The sweep has no in-place retraction, so a global `--delete` run without a
|
|
74154
|
+
* source leaves the generated `mcpServers` behind; an empty source
|
|
74155
|
+
* (`{ "mcpServers": {} }`) retracts them through the normal merge.
|
|
74156
|
+
* @see https://kiro.dev/docs/mcp/configuration/
|
|
74157
|
+
*/
|
|
74158
|
+
isDeletable() {
|
|
74159
|
+
return !this.global;
|
|
74160
|
+
}
|
|
73884
74161
|
static getSettablePaths() {
|
|
73885
74162
|
return {
|
|
73886
74163
|
relativeDirPath: KIRO_SETTINGS_DIR_PATH,
|
|
73887
74164
|
relativeFilePath: KIRO_MCP_FILE_NAME
|
|
73888
74165
|
};
|
|
73889
74166
|
}
|
|
73890
|
-
static async fromFile({ outputRoot = process.cwd(), validate = true }) {
|
|
74167
|
+
static async fromFile({ outputRoot = process.cwd(), validate = true, global = false }) {
|
|
73891
74168
|
const paths = this.getSettablePaths();
|
|
73892
74169
|
const fileContent = await readFileContentOrNull((0, node_path.join)(outputRoot, paths.relativeDirPath, paths.relativeFilePath)) ?? "{\"mcpServers\":{}}";
|
|
73893
74170
|
return new KiroMcp({
|
|
@@ -73895,18 +74172,34 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73895
74172
|
relativeDirPath: paths.relativeDirPath,
|
|
73896
74173
|
relativeFilePath: paths.relativeFilePath,
|
|
73897
74174
|
fileContent,
|
|
73898
|
-
validate
|
|
74175
|
+
validate,
|
|
74176
|
+
global
|
|
73899
74177
|
});
|
|
73900
74178
|
}
|
|
73901
|
-
|
|
74179
|
+
/**
|
|
74180
|
+
* In global mode the generated `mcpServers` are merged into the existing
|
|
74181
|
+
* user-level file, keeping every other top-level key (for example
|
|
74182
|
+
* `identityProvider`). The project file is written from scratch.
|
|
74183
|
+
*/
|
|
74184
|
+
static async fromRulesyncMcp({ outputRoot = process.cwd(), rulesyncMcp, validate = true, global = false }) {
|
|
73902
74185
|
const paths = this.getSettablePaths();
|
|
73903
|
-
const
|
|
74186
|
+
const mcpServers = toKiroMcpServers(rulesyncMcp.getMcpServers());
|
|
74187
|
+
let existing = {};
|
|
74188
|
+
if (global) {
|
|
74189
|
+
const configPath = (0, node_path.join)(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
74190
|
+
const existingContent = await readFileContentOrNull(configPath);
|
|
74191
|
+
if (existingContent !== null) existing = parseExistingKiroMcpConfig(existingContent, configPath);
|
|
74192
|
+
}
|
|
73904
74193
|
return new KiroMcp({
|
|
73905
74194
|
outputRoot,
|
|
73906
74195
|
relativeDirPath: paths.relativeDirPath,
|
|
73907
74196
|
relativeFilePath: paths.relativeFilePath,
|
|
73908
|
-
fileContent
|
|
73909
|
-
|
|
74197
|
+
fileContent: JSON.stringify({
|
|
74198
|
+
...existing,
|
|
74199
|
+
mcpServers
|
|
74200
|
+
}, null, 2),
|
|
74201
|
+
validate,
|
|
74202
|
+
global
|
|
73910
74203
|
});
|
|
73911
74204
|
}
|
|
73912
74205
|
toRulesyncMcp() {
|
|
@@ -73914,13 +74207,14 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73914
74207
|
const translated = isMcpServers(mcpServers) ? fromKiroMcpServers(mcpServers) : {};
|
|
73915
74208
|
return this.toRulesyncMcpDefault({ fileContent: JSON.stringify({ mcpServers: translated }, null, 2) });
|
|
73916
74209
|
}
|
|
73917
|
-
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath }) {
|
|
74210
|
+
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath, global = false }) {
|
|
73918
74211
|
return new KiroMcp({
|
|
73919
74212
|
outputRoot,
|
|
73920
74213
|
relativeDirPath,
|
|
73921
74214
|
relativeFilePath,
|
|
73922
74215
|
fileContent: "{}",
|
|
73923
|
-
validate: false
|
|
74216
|
+
validate: false,
|
|
74217
|
+
global
|
|
73924
74218
|
});
|
|
73925
74219
|
}
|
|
73926
74220
|
};
|
|
@@ -84370,6 +84664,29 @@ const CLAUDECODE_WIDENING_DEFAULT_MODES = {
|
|
|
84370
84664
|
*/
|
|
84371
84665
|
const CLAUDECODE_PROJECT_SCOPE_IGNORED_DEFAULT_MODES = /* @__PURE__ */ new Set(["auto", "bypassPermissions"]);
|
|
84372
84666
|
/**
|
|
84667
|
+
* The `permissions` fields Claude Code reads only from user or managed settings
|
|
84668
|
+
* (and `--settings`), never from a repository's `.claude/settings.json`, so
|
|
84669
|
+
* they are dropped at project scope and written only under `--global`.
|
|
84670
|
+
* `denyInsteadOfPrompting` (v2.1.319+) only restricts, but committing it to a
|
|
84671
|
+
* project file would promise unattended denials that never happen.
|
|
84672
|
+
*
|
|
84673
|
+
* @see https://code.claude.com/docs/en/settings-reference#permissions-denyinsteadofprompting
|
|
84674
|
+
*/
|
|
84675
|
+
const CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS = /* @__PURE__ */ new Set(["denyInsteadOfPrompting"]);
|
|
84676
|
+
/**
|
|
84677
|
+
* Drop the project-scope `permissions` fields in
|
|
84678
|
+
* {@link CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS}, warning once per field
|
|
84679
|
+
* in the same voice as the user-scope-only top-level keys.
|
|
84680
|
+
*/
|
|
84681
|
+
function stripUserScopeOnlyPermissionsFields({ fields, global, relativeFilePath, logger }) {
|
|
84682
|
+
if (global) return;
|
|
84683
|
+
for (const key of CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS) {
|
|
84684
|
+
if (!Object.hasOwn(fields, key)) continue;
|
|
84685
|
+
logger?.warn(`Claude Code permissions: 'permissions.${key}' is not honored in the project-scoped ${relativeFilePath}, so it is not written there — Claude Code reads it from user or managed settings only. Author it in the global scope instead, and remove any value an earlier generate may have left in ${relativeFilePath}.`);
|
|
84686
|
+
delete fields[key];
|
|
84687
|
+
}
|
|
84688
|
+
}
|
|
84689
|
+
/**
|
|
84373
84690
|
* Drop a project-scope `permissions.defaultMode` Claude Code ignores there (see
|
|
84374
84691
|
* {@link CLAUDECODE_PROJECT_SCOPE_IGNORED_DEFAULT_MODES}), warning in the same
|
|
84375
84692
|
* voice as the other values the project-scoped file cannot honor.
|
|
@@ -84463,7 +84780,7 @@ const CLAUDECODE_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
84463
84780
|
},
|
|
84464
84781
|
{
|
|
84465
84782
|
path: ["enabled"],
|
|
84466
|
-
reason: "turns the sandbox on, and sandboxed Bash commands then run without a permission prompt
|
|
84783
|
+
reason: "turns the sandbox on, and sandboxed Bash commands then run without a permission prompt wherever `autoAllowBashIfSandboxed` is true (it defaults to false since Claude Code v2.1.324)",
|
|
84467
84784
|
widens: isNotFalse
|
|
84468
84785
|
},
|
|
84469
84786
|
{
|
|
@@ -84766,6 +85083,7 @@ const CLAUDECODE_UNHONORED_KEY_SOURCES = {
|
|
|
84766
85083
|
disableCommandPluginSources: "managed settings",
|
|
84767
85084
|
disableDesktopLocalSessions: "managed settings",
|
|
84768
85085
|
disableMobileSimulatorTools: "managed settings",
|
|
85086
|
+
disableRemotePreviewScripts: "managed settings",
|
|
84769
85087
|
disableSideloadFlags: "managed settings",
|
|
84770
85088
|
externalEditorContext: "~/.claude.json",
|
|
84771
85089
|
forceRemoteSettingsRefresh: "managed settings",
|
|
@@ -85259,6 +85577,12 @@ var ClaudecodePermissions = class ClaudecodePermissions extends ToolPermissions
|
|
|
85259
85577
|
relativeFilePath: paths.relativeFilePath,
|
|
85260
85578
|
logger
|
|
85261
85579
|
});
|
|
85580
|
+
stripUserScopeOnlyPermissionsFields({
|
|
85581
|
+
fields: nonListFields,
|
|
85582
|
+
global,
|
|
85583
|
+
relativeFilePath: paths.relativeFilePath,
|
|
85584
|
+
logger
|
|
85585
|
+
});
|
|
85262
85586
|
trustAffecting.push(...collectWideningPermissionFields({ fields: nonListFields }));
|
|
85263
85587
|
settings.permissions = {
|
|
85264
85588
|
...settings.permissions,
|
|
@@ -87236,6 +87560,7 @@ const CODEX_DEFAULT_APPROVAL_POLICY = "on-request";
|
|
|
87236
87560
|
const CODEX_DEFAULT_APPROVALS_REVIEWER = "auto_review";
|
|
87237
87561
|
const CODEX_RETIRED_APPROVAL_POLICY = "untrusted";
|
|
87238
87562
|
const CODEX_DEPRECATED_APPROVAL_POLICY = "on-failure";
|
|
87563
|
+
const CODEX_REMOVED_AUTO_REVIEW_KEYS = ["extra_policy", "experimental_policy_template"];
|
|
87239
87564
|
const CODEX_GLOB_SCAN_MAX_DEPTH = 8;
|
|
87240
87565
|
const CODEX_MINIMAL_KEY = ":minimal";
|
|
87241
87566
|
const CODEX_GIT_WRITE_RULES = { ".git/**": "write" };
|
|
@@ -87837,6 +88162,10 @@ function computeCodexcliOverridePatch({ existing, override, logger }) {
|
|
|
87837
88162
|
value,
|
|
87838
88163
|
logger
|
|
87839
88164
|
})) continue;
|
|
88165
|
+
if (key === "auto_review" && isRecord(value)) warnAboutRemovedAutoReviewKeys({
|
|
88166
|
+
value,
|
|
88167
|
+
logger
|
|
88168
|
+
});
|
|
87840
88169
|
if (key === "sandbox_mode" || key === "sandbox_workspace_write") logger?.warn(`Codex CLI permission override key "${key}" is deprecated. Codex prioritizes the legacy sandbox settings over permission profiles when both are present, so it disables the generated "${RULESYNC_PROFILE_NAME}" permissions profile. Use "base_permission_profile" and the shared "permission" block instead.`);
|
|
87841
88170
|
const existingValue = existing[key];
|
|
87842
88171
|
patch[key] = isRecord(existingValue) && isRecord(value) ? {
|
|
@@ -87876,6 +88205,12 @@ function isWritableApprovalPolicy({ value, logger }) {
|
|
|
87876
88205
|
if (value === CODEX_DEPRECATED_APPROVAL_POLICY) logger?.warn(`Codex CLI permission override "approval_policy": "${CODEX_DEPRECATED_APPROVAL_POLICY}" is deprecated; Codex reads it as "${CODEX_DEFAULT_APPROVAL_POLICY}". Use "${CODEX_DEFAULT_APPROVAL_POLICY}" instead.`);
|
|
87877
88206
|
return true;
|
|
87878
88207
|
}
|
|
88208
|
+
function warnAboutRemovedAutoReviewKeys({ value, logger }) {
|
|
88209
|
+
for (const key of CODEX_REMOVED_AUTO_REVIEW_KEYS) {
|
|
88210
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
88211
|
+
logger?.warn(`Codex CLI permission override "auto_review.${key}" was removed in Codex 0.169.0: newer Codex ignores it and warns at startup (it is rejected only under --strict-config). It is still written for older Codex. Move the text to "auto_review.policy", or to guardian_extra_policy in a managed requirements.toml.`);
|
|
88212
|
+
}
|
|
88213
|
+
}
|
|
87879
88214
|
function extractCodexcliOverride(table) {
|
|
87880
88215
|
const override = {};
|
|
87881
88216
|
for (const key of CODEXCLI_OVERRIDE_KEYS) if (table[key] !== void 0) override[key] = table[key];
|
|
@@ -89250,6 +89585,17 @@ const AUTO_APPROVE_KEYS = {
|
|
|
89250
89585
|
webfetch: "chat.tools.urls.autoApprove"
|
|
89251
89586
|
};
|
|
89252
89587
|
/**
|
|
89588
|
+
* VS Code registers `chat.tools.edits.autoApprove` with
|
|
89589
|
+
* `ConfigurationScope.APPLICATION` (user settings only) and ignores the value
|
|
89590
|
+
* in a workspace `.vscode/settings.json`, so canonical `edit` rules written
|
|
89591
|
+
* there have no effect. The terminal and URL maps are honored in the workspace
|
|
89592
|
+
* only by the Local harness, which VS Code removes in February 2027.
|
|
89593
|
+
*
|
|
89594
|
+
* @see https://github.com/microsoft/vscode/blob/1.147.0/src/vs/workbench/contrib/chat/browser/chat.shared.contribution.ts
|
|
89595
|
+
* @see https://code.visualstudio.com/docs/agents/run/approvals
|
|
89596
|
+
*/
|
|
89597
|
+
const EDITS_KEY_IGNORED_WARNING = "GitHub Copilot: canonical `edit` rules are written to `chat.tools.edits.autoApprove` in .vscode/settings.json, but VS Code reads that setting from user settings only and ignores it in the workspace. Set edit approvals in your VS Code user settings instead.";
|
|
89598
|
+
/**
|
|
89253
89599
|
* The workspace setting holding the starting permission level of new Local
|
|
89254
89600
|
* (`local` harness) chat sessions, authored through the
|
|
89255
89601
|
* `copilot.defaultPermissionMode` override. VS Code 1.144 narrowed it to Local
|
|
@@ -89407,6 +89753,10 @@ const SANDBOX_LEAVES = [
|
|
|
89407
89753
|
path: ["credentials", "authenticategh"],
|
|
89408
89754
|
schema: zod_mini.z.boolean()
|
|
89409
89755
|
},
|
|
89756
|
+
{
|
|
89757
|
+
path: ["credentials", "envVars"],
|
|
89758
|
+
schema: CopilotSandboxCredentialEnvVarsSchema
|
|
89759
|
+
},
|
|
89410
89760
|
{
|
|
89411
89761
|
path: ["fileSystem", "allowDevToolAccess"],
|
|
89412
89762
|
schema: zod_mini.z.boolean()
|
|
@@ -89466,6 +89816,11 @@ const COPILOT_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
89466
89816
|
reason: "hands your GitHub CLI authentication to sandboxed commands",
|
|
89467
89817
|
widens: isNotFalse
|
|
89468
89818
|
},
|
|
89819
|
+
{
|
|
89820
|
+
path: ["credentials", "envVars"],
|
|
89821
|
+
reason: "lets the sandbox send the named environment variables' values to the listed hosts",
|
|
89822
|
+
widens: isNonEmptyMap
|
|
89823
|
+
},
|
|
89469
89824
|
{
|
|
89470
89825
|
path: ["fileSystem", "allowDevToolAccess"],
|
|
89471
89826
|
reason: "grants sandboxed commands developer-tool directories, which can hold credentials such as registry tokens",
|
|
@@ -89491,6 +89846,27 @@ const COPILOT_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
89491
89846
|
}
|
|
89492
89847
|
];
|
|
89493
89848
|
const COPILOT_TOOL_LABEL = "GitHub Copilot";
|
|
89849
|
+
/** The trust-warning label of the `credentials.envVars` leaf. */
|
|
89850
|
+
const ENV_VARS_LABEL = "sandbox.credentials.envVars";
|
|
89851
|
+
/**
|
|
89852
|
+
* Every `VAR -> host, host` pair of a `credentials.envVars` map, so a
|
|
89853
|
+
* developer generating from a cloned repository can spot an unexpected host
|
|
89854
|
+
* without opening the file. Names and hosts are JSON-quoted so control
|
|
89855
|
+
* characters in authored values cannot forge log lines.
|
|
89856
|
+
*/
|
|
89857
|
+
function describeEnvVars(envVars) {
|
|
89858
|
+
return Object.entries(envVars).map(([name, { injectHosts }]) => `${JSON.stringify(name)} -> ${injectHosts.length > 0 ? injectHosts.map((host) => JSON.stringify(host)).join(", ") : "(no hosts)"}`).join("; ");
|
|
89859
|
+
}
|
|
89860
|
+
/**
|
|
89861
|
+
* A separate, stronger warning for `injectHosts` entries containing `*`: the
|
|
89862
|
+
* sandbox may then send the credential to any host the pattern matches.
|
|
89863
|
+
*/
|
|
89864
|
+
function warnOnWildcardInjectHosts({ envVars, relativeFilePath, logger }) {
|
|
89865
|
+
if (envVars === void 0) return;
|
|
89866
|
+
const wildcards = Object.entries(envVars).flatMap(([name, { injectHosts }]) => injectHosts.filter((host) => host.includes("*")).map((host) => `${JSON.stringify(name)} -> ${JSON.stringify(host)}`));
|
|
89867
|
+
if (wildcards.length === 0) return;
|
|
89868
|
+
logger?.warn(`${COPILOT_TOOL_LABEL}: '${ENV_VARS_LABEL}' in ${relativeFilePath} lets the sandbox send credentials to any host matching a wildcard: ${wildcards.join("; ")}. Review these patterns, since the credential can reach every matching host.`);
|
|
89869
|
+
}
|
|
89494
89870
|
function sandboxKey(path) {
|
|
89495
89871
|
return `${SANDBOX_KEY_PREFIX}${path.join(".")}`;
|
|
89496
89872
|
}
|
|
@@ -89683,14 +90059,16 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
89683
90059
|
const patch = {};
|
|
89684
90060
|
for (const [category, settingKey] of Object.entries(AUTO_APPROVE_KEYS)) {
|
|
89685
90061
|
if (!Object.hasOwn(config.permission, category)) continue;
|
|
90062
|
+
const rules = category === "bash" ? bashRulesHonoringAllTools(config.permission) : honorCopilotAllToolsRestrictions({
|
|
90063
|
+
permission: config.permission,
|
|
90064
|
+
category,
|
|
90065
|
+
logger
|
|
90066
|
+
});
|
|
89686
90067
|
patch[settingKey] = buildAutoApproveValue({
|
|
89687
90068
|
category,
|
|
89688
|
-
rules
|
|
89689
|
-
permission: config.permission,
|
|
89690
|
-
category,
|
|
89691
|
-
logger
|
|
89692
|
-
})
|
|
90069
|
+
rules
|
|
89693
90070
|
});
|
|
90071
|
+
if (category === "edit" && Object.keys(rules).length > 0) logger?.warn(EDITS_KEY_IGNORED_WARNING);
|
|
89694
90072
|
}
|
|
89695
90073
|
const existingSettings = () => parseSharedConfig({
|
|
89696
90074
|
format: "jsonc",
|
|
@@ -89711,13 +90089,23 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
89711
90089
|
sandbox,
|
|
89712
90090
|
existingSettings: existingSettings()
|
|
89713
90091
|
}));
|
|
90092
|
+
const relativeFilePath = (0, node_path.join)(paths.relativeDirPath, paths.relativeFilePath);
|
|
90093
|
+
const envVars = sandbox.credentials?.envVars;
|
|
89714
90094
|
warnOnTrustAffectingEntries({
|
|
89715
90095
|
toolLabel: COPILOT_TOOL_LABEL,
|
|
89716
90096
|
entries: collectTrustAffectingSandboxPaths({
|
|
89717
90097
|
sandbox,
|
|
89718
90098
|
paths: COPILOT_TRUST_AFFECTING_SANDBOX_PATHS
|
|
89719
|
-
})
|
|
89720
|
-
|
|
90099
|
+
}).map((entry) => entry.label === ENV_VARS_LABEL && envVars !== void 0 ? {
|
|
90100
|
+
...entry,
|
|
90101
|
+
reason: `${entry.reason}: ${describeEnvVars(envVars)}`
|
|
90102
|
+
} : entry),
|
|
90103
|
+
relativeFilePath,
|
|
90104
|
+
logger
|
|
90105
|
+
});
|
|
90106
|
+
warnOnWildcardInjectHosts({
|
|
90107
|
+
envVars,
|
|
90108
|
+
relativeFilePath,
|
|
89721
90109
|
logger
|
|
89722
90110
|
});
|
|
89723
90111
|
}
|
|
@@ -92605,7 +92993,7 @@ function convertGoosePermissionConfigToRulesync(userPermission) {
|
|
|
92605
92993
|
const GROKCLI_UI_KEY = "ui";
|
|
92606
92994
|
const GROKCLI_PERMISSION_MODE_KEY = "permission_mode";
|
|
92607
92995
|
const GROKCLI_PERMISSION_KEY = "permission";
|
|
92608
|
-
const
|
|
92996
|
+
const GROKCLI_DERIVED_PERMISSION_MODES = /* @__PURE__ */ new Set(["ask", "always-approve"]);
|
|
92609
92997
|
const CATEGORY_TO_GROK_TOOL = {
|
|
92610
92998
|
bash: "Bash",
|
|
92611
92999
|
read: "Read",
|
|
@@ -92832,12 +93220,15 @@ function parseGrokRule(rule) {
|
|
|
92832
93220
|
* compact arrays, so a user-authored `rules` array is preserved verbatim
|
|
92833
93221
|
* but not reconciled against them.
|
|
92834
93222
|
*
|
|
92835
|
-
* The coarse `[ui] permission_mode` toggle is
|
|
92836
|
-
* compatibility with older Grok versions
|
|
92837
|
-
*
|
|
93223
|
+
* The coarse `[ui] permission_mode` toggle is kept in sync for backward
|
|
93224
|
+
* compatibility with older Grok versions, but only when the config already
|
|
93225
|
+
* sets it to `ask` or `always-approve`: `always-approve` only when the config
|
|
93226
|
+
* has the all-tools catch-all allow (`"*": { "*": "allow" }`) and no
|
|
93227
|
+
* `deny`/`ask` rule, otherwise `ask` (conservative — it is never `always-approve`
|
|
92838
93228
|
* while any `deny`/`ask` rule exists, so it never contradicts the fine-grained
|
|
92839
|
-
* arrays).
|
|
92840
|
-
* (see
|
|
93229
|
+
* arrays). A missing key is not added, so Grok's own default mode applies. It
|
|
93230
|
+
* is a user-level UI setting, so it is only touched in global scope (see
|
|
93231
|
+
* below).
|
|
92841
93232
|
*
|
|
92842
93233
|
* Both scopes are supported: the adapter syncs the project-level
|
|
92843
93234
|
* `./.grok/config.toml` (default) and the user-level `~/.grok/config.toml`
|
|
@@ -92898,7 +93289,7 @@ var GrokcliPermissions = class GrokcliPermissions extends ToolPermissions {
|
|
|
92898
93289
|
ask: buckets.ask
|
|
92899
93290
|
};
|
|
92900
93291
|
const existingUi = toRecord(parsed[GROKCLI_UI_KEY]);
|
|
92901
|
-
const uiPatch = global && existingUi[GROKCLI_PERMISSION_MODE_KEY]
|
|
93292
|
+
const uiPatch = global && GROKCLI_DERIVED_PERMISSION_MODES.has(existingUi[GROKCLI_PERMISSION_MODE_KEY]) ? { [GROKCLI_UI_KEY]: {
|
|
92902
93293
|
...existingUi,
|
|
92903
93294
|
[GROKCLI_PERMISSION_MODE_KEY]: deriveGrokPermissionMode(config)
|
|
92904
93295
|
} } : {};
|
|
@@ -93079,22 +93470,30 @@ function parseGrokPermissionArrays(permission) {
|
|
|
93079
93470
|
/**
|
|
93080
93471
|
* Legacy coarse fallback: map `[ui] permission_mode` to a canonical action.
|
|
93081
93472
|
* `always-approve` ⇒ `allow`; anything else (including a missing mode) ⇒ `ask`.
|
|
93473
|
+
* A missing mode now means Grok's own default (`auto` in the TUI since 1.0.80),
|
|
93474
|
+
* which has no canonical counterpart, so the narrower `ask` reading is kept.
|
|
93082
93475
|
*/
|
|
93083
93476
|
function legacyModeAction(parsed) {
|
|
93084
93477
|
return toRecord(parsed[GROKCLI_UI_KEY])[GROKCLI_PERMISSION_MODE_KEY] === "always-approve" ? "allow" : "ask";
|
|
93085
93478
|
}
|
|
93086
93479
|
/**
|
|
93087
93480
|
* Collapse a rulesync permissions config into Grok's single coarse mode.
|
|
93088
|
-
*
|
|
93089
|
-
*
|
|
93481
|
+
* `always-approve` lets every tool run without a prompt, so it is derived only
|
|
93482
|
+
* from a true catch-all allow — the all-tools rule `"*": { "*": "allow" }` —
|
|
93483
|
+
* with no `deny`/`ask` rule anywhere. Narrow allows (e.g. `bash: { "git *":
|
|
93484
|
+
* "allow" }`, or even `bash: { "*": "allow" }`) never widen into it; they and
|
|
93485
|
+
* an empty config map to `ask`.
|
|
93090
93486
|
*/
|
|
93091
93487
|
function deriveGrokPermissionMode(config) {
|
|
93092
|
-
|
|
93093
|
-
|
|
93094
|
-
|
|
93095
|
-
|
|
93096
|
-
}
|
|
93097
|
-
return
|
|
93488
|
+
for (const rules of Object.values(config.permission)) for (const action of Object.values(rules)) if (action === "deny" || action === "ask") return "ask";
|
|
93489
|
+
const allTools = lookupOwn({
|
|
93490
|
+
record: config.permission,
|
|
93491
|
+
key: "*"
|
|
93492
|
+
});
|
|
93493
|
+
return allTools !== void 0 && lookupOwn({
|
|
93494
|
+
record: allTools,
|
|
93495
|
+
key: "*"
|
|
93496
|
+
}) === "allow" ? "always-approve" : "ask";
|
|
93098
93497
|
}
|
|
93099
93498
|
// src/features/permissions/hermesagent-permissions.ts
|
|
93100
93499
|
/** Collect the glob patterns in a canonical category that carry a given action. */
|
|
@@ -94397,13 +94796,71 @@ function canonicalToKimiCodeRules({ config, logger }) {
|
|
|
94397
94796
|
});
|
|
94398
94797
|
}
|
|
94399
94798
|
}
|
|
94400
|
-
|
|
94799
|
+
const rules = [...overrideRules, ...sortKimiCodeRulesFailClosed(canonicalRules)];
|
|
94800
|
+
warnAboutIgnoredKimiCodeRuleScopes({
|
|
94801
|
+
rules: overrideRules,
|
|
94802
|
+
logger
|
|
94803
|
+
});
|
|
94804
|
+
warnAboutShadowedKimiCodeRules({
|
|
94805
|
+
rules,
|
|
94806
|
+
logger
|
|
94807
|
+
});
|
|
94808
|
+
return rules;
|
|
94401
94809
|
}
|
|
94402
|
-
|
|
94810
|
+
/**
|
|
94811
|
+
* Scopes Kimi silently ignores on a rule in the user `config.toml`.
|
|
94812
|
+
*
|
|
94813
|
+
* @see https://moonshotai.github.io/kimi-code/en/configuration/config-files.html#permission
|
|
94814
|
+
*/
|
|
94815
|
+
const KIMI_CODE_IGNORED_USER_RULE_SCOPES = /* @__PURE__ */ new Set(["turn-override", "session-runtime"]);
|
|
94816
|
+
function warnAboutIgnoredKimiCodeRuleScopes({ rules, logger }) {
|
|
94817
|
+
for (const rule of rules) if (rule.scope !== void 0 && KIMI_CODE_IGNORED_USER_RULE_SCOPES.has(rule.scope)) logger?.warn(`Kimi Code permissions: the ${rule.decision} rule for "${rule.pattern}" has scope "${rule.scope}", which Kimi ignores in ${KIMI_CODE_CONFIG_SHARED_FILE_KEY}. Use "user" or "project" for it to take effect.`);
|
|
94818
|
+
}
|
|
94819
|
+
/** Split a Kimi rule pattern (`Tool` or `Tool(arg)`) into its tool and argument. */
|
|
94820
|
+
function splitKimiCodePattern(pattern) {
|
|
94403
94821
|
const opening = pattern.indexOf("(");
|
|
94404
94822
|
const hasArguments = opening >= 0 && pattern.endsWith(")");
|
|
94405
|
-
|
|
94406
|
-
|
|
94823
|
+
return {
|
|
94824
|
+
tool: hasArguments ? pattern.slice(0, opening) : pattern,
|
|
94825
|
+
argument: hasArguments ? pattern.slice(opening + 1, -1) : "",
|
|
94826
|
+
hasArguments
|
|
94827
|
+
};
|
|
94828
|
+
}
|
|
94829
|
+
/**
|
|
94830
|
+
* Whether `stricter` certainly matches every call `rule` matches: the same
|
|
94831
|
+
* pattern, or the bare name of the same tool (which matches every call of
|
|
94832
|
+
* it). Wildcard overlaps are not detected, so this never reports a false
|
|
94833
|
+
* shadow but can miss one.
|
|
94834
|
+
*/
|
|
94835
|
+
function kimiCodeRuleCovers({ stricter, rule }) {
|
|
94836
|
+
return stricter.pattern === rule.pattern || stricter.pattern === splitKimiCodePattern(rule.pattern).tool;
|
|
94837
|
+
}
|
|
94838
|
+
/**
|
|
94839
|
+
* Kimi does not let the first matching rule win: a matching `deny` beats a
|
|
94840
|
+
* matching `ask`, which beats a matching `allow` (Kimi Code 2.6.0 docs). An
|
|
94841
|
+
* `allow` or `ask` meant to carve an exception out of a broader, stricter
|
|
94842
|
+
* rule therefore never takes effect, whether it comes from `kimi-code.rules`
|
|
94843
|
+
* or from a canonical category, so say so instead of letting the authored
|
|
94844
|
+
* order suggest otherwise. A rule whose own scope Kimi ignores already got
|
|
94845
|
+
* its warning and is skipped here.
|
|
94846
|
+
*
|
|
94847
|
+
* @see https://moonshotai.github.io/kimi-code/en/configuration/config-files.html#permission
|
|
94848
|
+
*/
|
|
94849
|
+
function warnAboutShadowedKimiCodeRules({ rules, logger }) {
|
|
94850
|
+
for (const rule of rules) {
|
|
94851
|
+
if (rule.decision === "deny" || KIMI_CODE_IGNORED_USER_RULE_SCOPES.has(rule.scope ?? "")) continue;
|
|
94852
|
+
const shadowing = rules.find((other) => isStricterAction({
|
|
94853
|
+
action: other.decision,
|
|
94854
|
+
existing: rule.decision
|
|
94855
|
+
}) && !KIMI_CODE_IGNORED_USER_RULE_SCOPES.has(other.scope ?? "") && kimiCodeRuleCovers({
|
|
94856
|
+
stricter: other,
|
|
94857
|
+
rule
|
|
94858
|
+
}));
|
|
94859
|
+
if (shadowing) logger?.warn(`Kimi Code permissions: the ${rule.decision} rule for "${rule.pattern}" never takes effect: the matching ${shadowing.decision} rule "${shadowing.pattern}" outranks it, because Kimi ranks matching rules deny > ask > allow regardless of their order.`);
|
|
94860
|
+
}
|
|
94861
|
+
}
|
|
94862
|
+
function getKimiCodePatternSpecificity(pattern) {
|
|
94863
|
+
const { tool, argument, hasArguments } = splitKimiCodePattern(pattern);
|
|
94407
94864
|
return {
|
|
94408
94865
|
tool,
|
|
94409
94866
|
toolLiteralLength: tool.replaceAll("*", "").replaceAll("?", "").length,
|
|
@@ -100469,6 +100926,14 @@ const TAKT_SECURITY_POLICIES = {
|
|
|
100469
100926
|
const TAKT_SECURITY_POLICY_KEYS = Object.keys(TAKT_SECURITY_POLICIES);
|
|
100470
100927
|
const TAKT_DEFAULT_PROVIDER = "claude-sdk";
|
|
100471
100928
|
const TAKT_LEGACY_DEFAULT_PROVIDER = "claude";
|
|
100929
|
+
const TAKT_CLAUDE_READ_DENY_PROVIDERS = [
|
|
100930
|
+
"claude-sdk",
|
|
100931
|
+
"claude",
|
|
100932
|
+
"claude-headless"
|
|
100933
|
+
];
|
|
100934
|
+
const TAKT_CLAUDE_PROVIDER_OPTIONS_KEY = "claude";
|
|
100935
|
+
const TAKT_CLAUDE_PERMISSIONS_KEY = "permissions";
|
|
100936
|
+
const TAKT_CLAUDE_PERMISSIONS_DENY_KEY = "deny";
|
|
100472
100937
|
/**
|
|
100473
100938
|
* Permissions adapter for Takt (`.takt/config.yaml`).
|
|
100474
100939
|
*
|
|
@@ -100507,6 +100972,12 @@ const TAKT_LEGACY_DEFAULT_PROVIDER = "claude";
|
|
|
100507
100972
|
* (a top-level per-provider sandbox/network table). Both are authored on
|
|
100508
100973
|
* generate and re-extracted on import.
|
|
100509
100974
|
*
|
|
100975
|
+
* Canonical `read` deny rules are also kept per path where the active provider
|
|
100976
|
+
* is Claude-family (Takt 0.76.0+): they are written as `Read(<pattern>)`
|
|
100977
|
+
* entries into `provider_options.claude.permissions.deny`, in addition to the
|
|
100978
|
+
* `readonly` mode they already derive. The list is only ever added to, so a
|
|
100979
|
+
* deny never turns into a broader allow.
|
|
100980
|
+
*
|
|
100510
100981
|
* Takt 0.56.0 moved provider configuration into a separate `runtime.yaml`
|
|
100511
100982
|
* (`.takt/runtime.yaml`, `~/.takt/runtime.yaml`). Once its `provider:` section
|
|
100512
100983
|
* carries an assignment ("runtime mode" — the state a freshly installed Takt is
|
|
@@ -100571,7 +101042,8 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100571
101042
|
outputRoot,
|
|
100572
101043
|
logger
|
|
100573
101044
|
});
|
|
100574
|
-
const
|
|
101045
|
+
const globalLayer = await readGlobalTaktLayer({
|
|
101046
|
+
global,
|
|
100575
101047
|
projectFilePath: filePath,
|
|
100576
101048
|
logger
|
|
100577
101049
|
});
|
|
@@ -100579,7 +101051,7 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100579
101051
|
const provider = resolveActiveProvider({
|
|
100580
101052
|
config,
|
|
100581
101053
|
runtime: runtime.active ? runtime.config : void 0,
|
|
100582
|
-
inheritedProvider
|
|
101054
|
+
inheritedProvider: globalLayer.provider
|
|
100583
101055
|
});
|
|
100584
101056
|
const mode = deriveTaktPermissionMode(rulesyncJson);
|
|
100585
101057
|
const override = isPlainObject(rulesyncJson.takt) ? rulesyncJson.takt : void 0;
|
|
@@ -100587,9 +101059,20 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100587
101059
|
const authoredProviderOptions = isPlainObject(override?.[TAKT_PROVIDER_OPTIONS_KEY]) ? override[TAKT_PROVIDER_OPTIONS_KEY] : void 0;
|
|
100588
101060
|
const runtimeModeRefusesProviderOptions = authoredProviderOptions !== void 0 && runtime.active;
|
|
100589
101061
|
if (runtimeModeRefusesProviderOptions) logger?.warn(`Takt permissions: not writing "${TAKT_PROVIDER_OPTIONS_KEY}" to ${filePath} because ${runtime.filePaths.join(" + ")} puts Takt in runtime provider mode (Takt 0.56.0+), where any legacy provider setting in config.yaml makes Takt fail with "Mixed provider configuration detected". Move those options to \`provider.profiles.<profile>.options\` in runtime.yaml, and remove them from the \`takt\` block of the rulesync source. A "${TAKT_PROVIDER_OPTIONS_KEY}" already in ${filePath} is left untouched — rulesync does not own that key.`);
|
|
100590
|
-
const overrideProviderOptions =
|
|
100591
|
-
providerOptions:
|
|
100592
|
-
|
|
101062
|
+
const overrideProviderOptions = addClaudeReadDenyRules({
|
|
101063
|
+
providerOptions: runtimeModeRefusesProviderOptions ? void 0 : dropUntrustedProviderOptions({
|
|
101064
|
+
providerOptions: authoredProviderOptions,
|
|
101065
|
+
global,
|
|
101066
|
+
filePath,
|
|
101067
|
+
logger
|
|
101068
|
+
}),
|
|
101069
|
+
readDenyRules: collectReadDenyRules(rulesyncJson),
|
|
101070
|
+
existingProviderOptions: config[TAKT_PROVIDER_OPTIONS_KEY],
|
|
101071
|
+
globalProviderOptions: globalLayer.providerOptions,
|
|
101072
|
+
globalFilePath: globalLayer.filePath,
|
|
101073
|
+
provider,
|
|
101074
|
+
runtimeActive: runtime.active,
|
|
101075
|
+
runtimeFilePaths: runtime.filePaths,
|
|
100593
101076
|
filePath,
|
|
100594
101077
|
logger
|
|
100595
101078
|
});
|
|
@@ -100702,11 +101185,34 @@ function readProviderName(config) {
|
|
|
100702
101185
|
return typeof provider === "string" && provider.trim() !== "" ? provider : void 0;
|
|
100703
101186
|
}
|
|
100704
101187
|
/**
|
|
100705
|
-
*
|
|
100706
|
-
*
|
|
100707
|
-
*
|
|
101188
|
+
* What a project-scope generate inherits from the global `~/.takt/config.yaml`:
|
|
101189
|
+
* its provider and its `provider_options`. Nothing at global scope, where that
|
|
101190
|
+
* file is the one being generated.
|
|
101191
|
+
*/
|
|
101192
|
+
async function readGlobalTaktLayer({ global, projectFilePath, logger }) {
|
|
101193
|
+
const globalConfig = global ? void 0 : await readGlobalTaktConfig({
|
|
101194
|
+
projectFilePath,
|
|
101195
|
+
logger
|
|
101196
|
+
});
|
|
101197
|
+
if (globalConfig === void 0) return {
|
|
101198
|
+
provider: void 0,
|
|
101199
|
+
providerOptions: void 0,
|
|
101200
|
+
filePath: void 0
|
|
101201
|
+
};
|
|
101202
|
+
return {
|
|
101203
|
+
provider: readProviderName(globalConfig.config),
|
|
101204
|
+
providerOptions: globalConfig.config[TAKT_PROVIDER_OPTIONS_KEY],
|
|
101205
|
+
filePath: globalConfig.filePath
|
|
101206
|
+
};
|
|
101207
|
+
}
|
|
101208
|
+
/**
|
|
101209
|
+
* The global `~/.takt/config.yaml`, read for a project-scope generate: its
|
|
101210
|
+
* top-level `provider:` is inherited by a project config that names none, and
|
|
101211
|
+
* its `provider_options.claude.permissions.deny` is the list a project list
|
|
101212
|
+
* would replace. An unresolvable home directory or a missing or unparsable file
|
|
101213
|
+
* all mean "nothing inherited".
|
|
100708
101214
|
*/
|
|
100709
|
-
async function
|
|
101215
|
+
async function readGlobalTaktConfig({ projectFilePath, logger }) {
|
|
100710
101216
|
let globalPath;
|
|
100711
101217
|
try {
|
|
100712
101218
|
globalPath = (0, node_path.join)(getHomeDirectory(), TAKT_DIR, TAKT_CONFIG_FILE_NAME);
|
|
@@ -100717,12 +101223,15 @@ async function readGlobalTaktProvider({ projectFilePath, logger }) {
|
|
|
100717
101223
|
try {
|
|
100718
101224
|
const content = await readFileContentOrNull(globalPath);
|
|
100719
101225
|
if (content === null) return;
|
|
100720
|
-
return
|
|
100721
|
-
format: "yaml",
|
|
100722
|
-
fileContent: content,
|
|
101226
|
+
return {
|
|
100723
101227
|
filePath: globalPath,
|
|
100724
|
-
|
|
100725
|
-
|
|
101228
|
+
config: parseSharedConfig({
|
|
101229
|
+
format: "yaml",
|
|
101230
|
+
fileContent: content,
|
|
101231
|
+
filePath: globalPath,
|
|
101232
|
+
invalidRootPolicy: "error"
|
|
101233
|
+
})
|
|
101234
|
+
};
|
|
100726
101235
|
} catch (error) {
|
|
100727
101236
|
logger?.warn(`Takt permissions: could not read the provider from ${globalPath} (${formatError(error)}); falling back to the project config alone.`);
|
|
100728
101237
|
return;
|
|
@@ -101085,6 +101594,70 @@ function taktModeToRulesyncConfig(mode) {
|
|
|
101085
101594
|
default: return { permission: { bash: { ["*"]: "deny" } } };
|
|
101086
101595
|
}
|
|
101087
101596
|
}
|
|
101597
|
+
/**
|
|
101598
|
+
* The canonical `read` deny rules as Claude Code `Read(...)` entries, in the
|
|
101599
|
+
* form the Claude Code permissions and ignore adapters write them: the pattern
|
|
101600
|
+
* verbatim, and a bare `Read` for the catch-all.
|
|
101601
|
+
*/
|
|
101602
|
+
function collectReadDenyRules(config) {
|
|
101603
|
+
const rules = config.permission.read ?? {};
|
|
101604
|
+
return Object.entries(rules).filter(([, action]) => action === "deny").map(([pattern]) => pattern === "*" ? "Read" : buildReadDenyEntry(pattern));
|
|
101605
|
+
}
|
|
101606
|
+
/**
|
|
101607
|
+
* Add the canonical `read` deny rules to `provider_options.claude.permissions.deny`
|
|
101608
|
+
* (Takt 0.76.0+), which Takt passes to `claude-sdk` / `claude-headless` as
|
|
101609
|
+
* Claude Code `permissions.deny` rules.
|
|
101610
|
+
*
|
|
101611
|
+
* Takt replaces a `deny` list wholesale rather than concatenating it, so the
|
|
101612
|
+
* rules are merged into the list that would otherwise be in force: the one the
|
|
101613
|
+
* `takt` block states (which replaces a hand-written config.yaml list, as any
|
|
101614
|
+
* authored `provider_options` leaf does), else the one already in config.yaml.
|
|
101615
|
+
* Without an authored list nothing is removed from config.yaml's — a rule
|
|
101616
|
+
* written by hand, or by an earlier generate, is kept.
|
|
101617
|
+
*
|
|
101618
|
+
* At project scope the written list also replaces a global `~/.takt/config.yaml`
|
|
101619
|
+
* deny list for this project. That list usually holds personal paths, so it is
|
|
101620
|
+
* not copied into the (committed) project file; a warning names it instead.
|
|
101621
|
+
*
|
|
101622
|
+
* Skipped when the active provider is not Claude-family (no other provider
|
|
101623
|
+
* reads the list) and, with a warning, in runtime mode, where `provider_options`
|
|
101624
|
+
* in config.yaml stops Takt with "Mixed provider configuration detected".
|
|
101625
|
+
* https://github.com/nrslib/takt/blob/main/docs/configuration.md#claude-read-deny-rules
|
|
101626
|
+
*/
|
|
101627
|
+
function addClaudeReadDenyRules({ providerOptions, readDenyRules, existingProviderOptions, globalProviderOptions, globalFilePath, provider, runtimeActive, runtimeFilePaths, filePath, logger }) {
|
|
101628
|
+
if (readDenyRules.length === 0 || !TAKT_CLAUDE_READ_DENY_PROVIDERS.includes(provider)) return providerOptions;
|
|
101629
|
+
if (runtimeActive) {
|
|
101630
|
+
logger?.warn(`Takt permissions: not writing the read deny rules (${readDenyRules.join(", ")}) to "${TAKT_PROVIDER_OPTIONS_KEY}.${TAKT_CLAUDE_PROVIDER_OPTIONS_KEY}.${TAKT_CLAUDE_PERMISSIONS_KEY}.${TAKT_CLAUDE_PERMISSIONS_DENY_KEY}" in ${filePath} because ${runtimeFilePaths.join(" + ")} puts Takt in runtime provider mode. They still make the mode readonly; to have Claude enforce them per path, add them under \`${TAKT_CLAUDE_PERMISSIONS_KEY}.${TAKT_CLAUDE_PERMISSIONS_DENY_KEY}\` in the options of a Claude profile in runtime.yaml.`);
|
|
101631
|
+
return providerOptions;
|
|
101632
|
+
}
|
|
101633
|
+
const authoredClaude = providerOptions?.[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY];
|
|
101634
|
+
const authoredDeny = readClaudeDenyList(authoredClaude);
|
|
101635
|
+
const existingDeny = isPlainObject(existingProviderOptions) ? readClaudeDenyList(existingProviderOptions[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]) : void 0;
|
|
101636
|
+
const deny = [.../* @__PURE__ */ new Set([...authoredDeny ?? existingDeny ?? [], ...readDenyRules])];
|
|
101637
|
+
const shadowedGlobalDeny = ((isPlainObject(globalProviderOptions) ? readClaudeDenyList(globalProviderOptions[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]) : void 0) ?? []).filter((rule) => !deny.includes(rule));
|
|
101638
|
+
if (shadowedGlobalDeny.length > 0) logger?.warn(`Takt permissions: the read deny rules written to "${TAKT_PROVIDER_OPTIONS_KEY}.${TAKT_CLAUDE_PROVIDER_OPTIONS_KEY}.${TAKT_CLAUDE_PERMISSIONS_KEY}.${TAKT_CLAUDE_PERMISSIONS_DENY_KEY}" in ${filePath} replace the list in ${globalFilePath ?? "the global config.yaml"} for this project, because Takt does not concatenate deny lists across layers. Claude will no longer apply ${shadowedGlobalDeny.join(", ")} here unless you add them to the project list (the \`takt.provider_options.claude.permissions.deny\` block of the rulesync source) or to the canonical \`read\` rules.`);
|
|
101639
|
+
const claude = isPlainObject(authoredClaude) ? authoredClaude : {};
|
|
101640
|
+
const permissions = isPlainObject(claude[TAKT_CLAUDE_PERMISSIONS_KEY]) ? claude[TAKT_CLAUDE_PERMISSIONS_KEY] : {};
|
|
101641
|
+
return {
|
|
101642
|
+
...providerOptions,
|
|
101643
|
+
[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]: {
|
|
101644
|
+
...claude,
|
|
101645
|
+
[TAKT_CLAUDE_PERMISSIONS_KEY]: {
|
|
101646
|
+
...permissions,
|
|
101647
|
+
[TAKT_CLAUDE_PERMISSIONS_DENY_KEY]: deny
|
|
101648
|
+
}
|
|
101649
|
+
}
|
|
101650
|
+
};
|
|
101651
|
+
}
|
|
101652
|
+
/** The string entries of `<claude options>.permissions.deny`, when it is a list. */
|
|
101653
|
+
function readClaudeDenyList(claudeOptions) {
|
|
101654
|
+
if (!isPlainObject(claudeOptions)) return;
|
|
101655
|
+
const permissions = claudeOptions[TAKT_CLAUDE_PERMISSIONS_KEY];
|
|
101656
|
+
if (!isPlainObject(permissions)) return;
|
|
101657
|
+
const deny = permissions[TAKT_CLAUDE_PERMISSIONS_DENY_KEY];
|
|
101658
|
+
if (!Array.isArray(deny)) return;
|
|
101659
|
+
return deny.filter((entry) => typeof entry === "string" && entry !== "");
|
|
101660
|
+
}
|
|
101088
101661
|
const TAKT_BASE_URL_PROVIDERS = [
|
|
101089
101662
|
"codex",
|
|
101090
101663
|
"claude",
|
|
@@ -104109,6 +104682,32 @@ function buildZedToolPermissions({ permission, logger }) {
|
|
|
104109
104682
|
inertMcpCategories
|
|
104110
104683
|
};
|
|
104111
104684
|
}
|
|
104685
|
+
/**
|
|
104686
|
+
* Zed's file-edit tools whose `confirm` default does not prompt for files inside
|
|
104687
|
+
* the project.
|
|
104688
|
+
*/
|
|
104689
|
+
const ZED_IN_PROJECT_EDIT_TOOLS = ["edit_file", "write_file"];
|
|
104690
|
+
/**
|
|
104691
|
+
* Zed's `edit_file` and `write_file` skip the permission prompt for files inside
|
|
104692
|
+
* the project when the settings decision is `confirm`: only Zed settings
|
|
104693
|
+
* folders, `.agents/skills/` and paths a symlink places outside the project
|
|
104694
|
+
* still prompt (`authorize_file_edit` in `crates/agent/src/tools/tool_permissions.rs`,
|
|
104695
|
+
* documented under "File Edits Inside the Project" since zed-industries/zed#67037).
|
|
104696
|
+
* A canonical catch-all `ask` on `edit`/`write` — or an all-tools `*` ask those
|
|
104697
|
+
* tools fall back to — therefore lets the agent edit in-project files without
|
|
104698
|
+
* asking, so say so at generate time rather than implying a prompt.
|
|
104699
|
+
*
|
|
104700
|
+
* The check runs on the merged `tools` result: a tool whose entry is a
|
|
104701
|
+
* preserved, hand-written one (not managed by rulesync) is skipped, since its
|
|
104702
|
+
* decision is the user's own. Only the literal `.*` ask pattern counts as
|
|
104703
|
+
* "prompt for every file" and silences the warning; any narrower pattern still
|
|
104704
|
+
* leaves other in-project files unprompted, so the warning stays.
|
|
104705
|
+
*/
|
|
104706
|
+
function warnInProjectEditConfirm({ managedDefault, managedTools, preservedToolNames, logger }) {
|
|
104707
|
+
const confirmTools = ZED_IN_PROJECT_EDIT_TOOLS.filter((tool) => !preservedToolNames.has(tool) && (managedTools[tool]?.default ?? managedDefault) === "confirm" && !managedTools[tool]?.always_confirm?.some((entry) => entry.pattern === ".*"));
|
|
104708
|
+
if (confirmTools.length === 0) return;
|
|
104709
|
+
logger?.warn(`Zed permissions: the catch-all "ask" for ${confirmTools.map((tool) => `"${tool}"`).join(" and ")} becomes Zed's "confirm" default, which does not prompt for edits to files inside the project (only Zed settings folders, ".agents/skills/" and files outside the project still prompt). To be asked before in-project edits, add the "ask" pattern ".*" to the category (only that exact pattern silences this warning; an "always_confirm" match outranks "always_allow" patterns). Zed honors such patterns for in-project files from v1.30 on. Canonical patterns are shared by every target: in glob-matching targets (such as Claude Code's "Edit(.*)") ".*" matches dotfiles only, so there it adds an extra "ask" for those files and loosens nothing.`);
|
|
104710
|
+
}
|
|
104112
104711
|
function asRecord(value) {
|
|
104113
104712
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
|
|
104114
104713
|
return Object.fromEntries(Object.entries(value));
|
|
@@ -104254,6 +104853,12 @@ var ZedPermissions = class ZedPermissions extends ToolPermissions {
|
|
|
104254
104853
|
if ("*" in config.permission) managedToolNames.add("*");
|
|
104255
104854
|
for (const toolName of Object.keys(existingTools)) if (toolName.startsWith("mcp__")) managedToolNames.add(toolName);
|
|
104256
104855
|
const preservedTools = Object.fromEntries(Object.entries(existingTools).filter(([toolName]) => !managedToolNames.has(toolName)));
|
|
104856
|
+
warnInProjectEditConfirm({
|
|
104857
|
+
managedDefault,
|
|
104858
|
+
managedTools,
|
|
104859
|
+
preservedToolNames: new Set(Object.keys(preservedTools)),
|
|
104860
|
+
logger
|
|
104861
|
+
});
|
|
104257
104862
|
return new ZedPermissions({
|
|
104258
104863
|
outputRoot,
|
|
104259
104864
|
relativeDirPath: paths.relativeDirPath,
|