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
|
@@ -5866,16 +5866,17 @@ const CONTINUE_TO_CANONICAL_EVENT_NAMES = invertRecord(CANONICAL_TO_CONTINUE_EVE
|
|
|
5866
5866
|
* observers, `gateway_platform_event` and `transform_api_error_classification`.
|
|
5867
5867
|
* Shell hooks are gated on the same set.
|
|
5868
5868
|
*
|
|
5869
|
-
* Verified against the tag `v0.
|
|
5869
|
+
* Verified against the tag `v0.23.2`: `VALID_HOOKS` holds 48 entries, grown
|
|
5870
5870
|
* from 23 at `v2026.8.3` (v0.20.0) and 37 at `v2026.8.16` (v0.20.2) — v0.21
|
|
5871
5871
|
* added `agent_loop_stopped` and `on_room_member_activity`, v0.21.5 added
|
|
5872
5872
|
* `pre_auxiliary_call` and `post_auxiliary_call`, v0.21.6 added
|
|
5873
5873
|
* `post_gateway_admission`, `on_human_input_request` and
|
|
5874
|
-
* `on_human_input_resolved`,
|
|
5875
|
-
* `post_compaction
|
|
5874
|
+
* `on_human_input_resolved`, v0.22.3 added `on_session_delete` and
|
|
5875
|
+
* `post_compaction`, and v0.23.1 added `on_session_open` and
|
|
5876
|
+
* `post_curator_run`. This list holds 47 of them — see
|
|
5876
5877
|
* {@link HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS} for the exclusion.
|
|
5877
5878
|
*
|
|
5878
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5879
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/hermes_cli/plugins.py
|
|
5879
5880
|
*/
|
|
5880
5881
|
const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
5881
5882
|
"pre_tool_call",
|
|
@@ -5900,6 +5901,7 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5900
5901
|
"on_session_finalize",
|
|
5901
5902
|
"on_session_reset",
|
|
5902
5903
|
"on_session_delete",
|
|
5904
|
+
"on_session_open",
|
|
5903
5905
|
"on_skill_lifecycle",
|
|
5904
5906
|
"subagent_start",
|
|
5905
5907
|
"subagent_stop",
|
|
@@ -5922,7 +5924,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5922
5924
|
"on_kanban_dispatch_tick",
|
|
5923
5925
|
"gateway_platform_event",
|
|
5924
5926
|
"pre_command",
|
|
5925
|
-
"post_compaction"
|
|
5927
|
+
"post_compaction",
|
|
5928
|
+
"post_curator_run"
|
|
5926
5929
|
];
|
|
5927
5930
|
/**
|
|
5928
5931
|
* `VALID_HOOKS` entries a SHELL hook may not register for. `VALID_HOOKS` doubles
|
|
@@ -5934,8 +5937,8 @@ const HERMESAGENT_NATIVE_HOOK_EVENTS = [
|
|
|
5934
5937
|
* rulesync only ever writes shell hooks, so these are excluded from
|
|
5935
5938
|
* {@link HERMESAGENT_NATIVE_HOOK_EVENTS} and warned about with their own message.
|
|
5936
5939
|
*
|
|
5937
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5938
|
-
* @see https://github.com/NousResearch/hermes-agent/blob/v0.
|
|
5940
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/hermes_cli/plugins.py — `SHELL_UNSUPPORTED_HOOKS`
|
|
5941
|
+
* @see https://github.com/NousResearch/hermes-agent/blob/v0.23.2/agent/shell_hooks.py — `_parse_hooks_block`
|
|
5939
5942
|
*/
|
|
5940
5943
|
const HERMESAGENT_SHELL_UNSUPPORTED_HOOK_EVENTS = ["transform_api_error_classification"];
|
|
5941
5944
|
/**
|
|
@@ -5955,8 +5958,8 @@ const CANONICAL_TO_HERMESAGENT_EVENT_NAMES = {
|
|
|
5955
5958
|
/**
|
|
5956
5959
|
* Hook events supported by Hermes Agent's native Shell Hooks system.
|
|
5957
5960
|
*
|
|
5958
|
-
* Hermes validates hook events against a fixed `VALID_HOOKS` set —
|
|
5959
|
-
* of v0.
|
|
5961
|
+
* Hermes validates hook events against a fixed `VALID_HOOKS` set — 48 entries as
|
|
5962
|
+
* of v0.23.2 (tag `v0.23.2`); see {@link HERMESAGENT_NATIVE_HOOK_EVENTS} for the
|
|
5960
5963
|
* full list. Only the events with a clean 1:1 canonical equivalent are mapped
|
|
5961
5964
|
* here. All other native events round-trip through `hermesagent.hooks`.
|
|
5962
5965
|
* @see https://github.com/NousResearch/hermes-agent/blob/main/website/docs/user-guide/features/hooks.md
|
|
@@ -6749,6 +6752,7 @@ const CANONICAL_TO_KIRO_IDE_EVENT_NAMES = {
|
|
|
6749
6752
|
beforeSubmitPrompt: "UserPromptSubmit",
|
|
6750
6753
|
preToolUse: "PreToolUse",
|
|
6751
6754
|
postToolUse: "PostToolUse",
|
|
6755
|
+
permissionRequest: "PermissionRequest",
|
|
6752
6756
|
stop: "Stop"
|
|
6753
6757
|
};
|
|
6754
6758
|
/**
|
|
@@ -6757,7 +6761,9 @@ const CANONICAL_TO_KIRO_IDE_EVENT_NAMES = {
|
|
|
6757
6761
|
*
|
|
6758
6762
|
* Kiro exposes PascalCase triggers. rulesync maps the canonical lifecycle
|
|
6759
6763
|
* events that have a clean 1:1 equivalent: `SessionStart`, `Stop`,
|
|
6760
|
-
* `UserPromptSubmit`, `PreToolUse`,
|
|
6764
|
+
* `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, and `PermissionRequest`
|
|
6765
|
+
* (Kiro IDE 1.4.236+ and CLI V3 3.4.0+; it takes a Pre Tool Use–style tool
|
|
6766
|
+
* matcher). Kiro also documents
|
|
6761
6767
|
* file-event (`PostFileCreate`/`PostFileSave`/`PostFileDelete`) and spec-task
|
|
6762
6768
|
* (`PreTaskExec`/`PostTaskExec`) triggers that have no canonical equivalent;
|
|
6763
6769
|
* those can still be emitted verbatim via the shared `kiro` override block
|
|
@@ -8186,6 +8192,15 @@ const CopilotSandboxUserConfiguredPathsSchema = z.strictObject({
|
|
|
8186
8192
|
deniedPaths: z.optional(z.array(z.string()))
|
|
8187
8193
|
});
|
|
8188
8194
|
/**
|
|
8195
|
+
* `chat.agent.sandbox.credentials.envVars` (VS Code 1.146+): environment
|
|
8196
|
+
* variable names (never their secret values) mapped to the HTTPS hosts the
|
|
8197
|
+
* Agent Host sandbox may inject each value into. Inside the sandbox the
|
|
8198
|
+
* variable is masked.
|
|
8199
|
+
*
|
|
8200
|
+
* @see https://code.visualstudio.com/docs/agents/run/agent-sandboxing
|
|
8201
|
+
*/
|
|
8202
|
+
const CopilotSandboxCredentialEnvVarsSchema = z.record(z.string(), z.strictObject({ injectHosts: z.array(z.string()) }));
|
|
8203
|
+
/**
|
|
8189
8204
|
* The Agent Host sandbox settings VS Code 1.141 settled on, as a nested object
|
|
8190
8205
|
* whose path mirrors the dotted setting key under `chat.agent.sandbox.` — e.g.
|
|
8191
8206
|
* `network.allowNetwork` writes `chat.agent.sandbox.network.allowNetwork`.
|
|
@@ -8207,7 +8222,8 @@ const CopilotSandboxSchema = z.strictObject({
|
|
|
8207
8222
|
lspServers: z.optional(z.boolean()),
|
|
8208
8223
|
credentials: z.optional(z.strictObject({
|
|
8209
8224
|
authenticategit: z.optional(z.boolean()),
|
|
8210
|
-
authenticategh: z.optional(z.boolean())
|
|
8225
|
+
authenticategh: z.optional(z.boolean()),
|
|
8226
|
+
envVars: z.optional(CopilotSandboxCredentialEnvVarsSchema)
|
|
8211
8227
|
})),
|
|
8212
8228
|
fileSystem: z.optional(z.strictObject({
|
|
8213
8229
|
allowDevToolAccess: z.optional(z.boolean()),
|
|
@@ -9526,15 +9542,20 @@ const CodexcliPermissionsOverrideSchema = z.looseObject({
|
|
|
9526
9542
|
/**
|
|
9527
9543
|
* The `[auto_review]` table of `config.toml`, which configures the reviewer
|
|
9528
9544
|
* that `approvals_reviewer = "auto_review"` (Rulesync's default) selects:
|
|
9529
|
-
* `policy` / `extra_policy` (text inserted into the reviewer prompt
|
|
9545
|
+
* `policy` / `extra_policy` (text inserted into the reviewer prompt;
|
|
9546
|
+
* `extra_policy` only up to Codex 0.168.0),
|
|
9530
9547
|
* `timeout_ms` (the review budget, Codex 0.165.0+; `0` waits without a
|
|
9531
9548
|
* deadline), `circuit_break_action` (`default` | `strict`) and
|
|
9532
9549
|
* `conversation_history_max_output_tokens` (a positive token cap). Codex
|
|
9533
9550
|
* rejects the whole config file when one of these has the wrong type or is
|
|
9534
9551
|
* out of range (`timeout_ms` is a `u32`, the token cap a `NonZeroUsize`), so
|
|
9535
9552
|
* they are checked here; every other key passes through verbatim.
|
|
9553
|
+
* `extra_policy` and `experimental_policy_template` were removed in Codex
|
|
9554
|
+
* 0.169.0 (openai/codex PR #60646): newer Codex ignores them and warns at
|
|
9555
|
+
* startup (only `--strict-config` rejects them), so they are still accepted
|
|
9556
|
+
* and written for older Codex, and generate warns when they are authored.
|
|
9536
9557
|
*
|
|
9537
|
-
* @see https://github.com/openai/codex/blob/rust-v0.
|
|
9558
|
+
* @see https://github.com/openai/codex/blob/rust-v0.169.0/codex-rs/config/src/config_toml.rs (`AutoReviewToml`)
|
|
9538
9559
|
*/
|
|
9539
9560
|
auto_review: z.optional(z.looseObject({
|
|
9540
9561
|
policy: z.optional(z.string()),
|
|
@@ -14001,6 +14022,7 @@ const SHARED_CONFIG_OWNERSHIP = {
|
|
|
14001
14022
|
"chat.agent.sandbox.lspServers",
|
|
14002
14023
|
"chat.agent.sandbox.credentials.authenticategit",
|
|
14003
14024
|
"chat.agent.sandbox.credentials.authenticategh",
|
|
14025
|
+
"chat.agent.sandbox.credentials.envVars",
|
|
14004
14026
|
"chat.agent.sandbox.fileSystem.allowDevToolAccess",
|
|
14005
14027
|
"chat.agent.sandbox.fileSystem.userConfiguredPaths",
|
|
14006
14028
|
"zoo-code.allowedCommands",
|
|
@@ -51919,9 +51941,14 @@ const GooseCheckFrontmatterSchema = z.extend(AmpCheckFrontmatterSchema, {
|
|
|
51919
51941
|
"turn-limit": z.optional(z.int().check(z.nonnegative()))
|
|
51920
51942
|
});
|
|
51921
51943
|
/**
|
|
51922
|
-
* Represents a Goose review check
|
|
51944
|
+
* Represents a Goose review check, written to the user-wide
|
|
51923
51945
|
* `~/.config/goose/checks/` (global scope only).
|
|
51924
51946
|
*
|
|
51947
|
+
* Goose v1.60.0 removed the `goose review` subcommand that ran these checks
|
|
51948
|
+
* (aaif-goose/goose#13469). Goose still discovers them, but only lists them as
|
|
51949
|
+
* agent sources (`properties.kind = "check"`), so `model` and `turn-limit`
|
|
51950
|
+
* have no runtime effect there.
|
|
51951
|
+
*
|
|
51925
51952
|
* Goose discovers repository checks in `.agents/checks/*.md`, the same
|
|
51926
51953
|
* cross-tool directory the `amp` checks target already writes (Goose's
|
|
51927
51954
|
* `tools` and `severity-default` fields exist for parity with Amp's), so the
|
|
@@ -56524,7 +56551,11 @@ const CLAUDE_SPEC = {
|
|
|
56524
56551
|
tool: "onFailure",
|
|
56525
56552
|
trueValue: "block",
|
|
56526
56553
|
falseValue: "continue",
|
|
56527
|
-
hookTypes: /* @__PURE__ */ new Set([
|
|
56554
|
+
hookTypes: /* @__PURE__ */ new Set([
|
|
56555
|
+
"command",
|
|
56556
|
+
"http",
|
|
56557
|
+
"mcp_tool"
|
|
56558
|
+
]),
|
|
56528
56559
|
ignoredEvents: /* @__PURE__ */ new Set([
|
|
56529
56560
|
"stop",
|
|
56530
56561
|
"subagentStop",
|
|
@@ -59836,7 +59867,7 @@ function canonicalToHermesHooks({ config, toolOverrideHooks, logger }) {
|
|
|
59836
59867
|
for (const [nativeEvent, definitions] of Object.entries(toolOverrideHooks ?? {})) {
|
|
59837
59868
|
if (HERMESAGENT_CANONICAL_EVENTS.has(nativeEvent)) continue;
|
|
59838
59869
|
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.`);
|
|
59839
|
-
else if (!HERMESAGENT_NATIVE_EVENTS.has(nativeEvent)) logger?.warn(`Hermes hook event "${nativeEvent}" is not documented by Hermes Agent v0.
|
|
59870
|
+
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.`);
|
|
59840
59871
|
setHermesHookEntries({
|
|
59841
59872
|
result,
|
|
59842
59873
|
event: nativeEvent,
|
|
@@ -60312,7 +60343,8 @@ const BLOCKING_HOOKS = new Set(Object.keys(NAMED_HOOK_MATCHER_SUBJECTS).filter((
|
|
|
60312
60343
|
* 5 minutes). Ordinary commands write to the host's stdout and stderr, as Bun
|
|
60313
60344
|
* Shell echoed them; a `preToolUse` command's are read, 1 MiB each kept (more
|
|
60314
60345
|
* stdout denies; on the Bun Shell fallback the whole output is buffered before
|
|
60315
|
-
* that check)
|
|
60346
|
+
* that check), and a `sessionStart` command's stdout is read the same way while
|
|
60347
|
+
* its stderr goes to the host's (after the command, on Bun Shell). Output
|
|
60316
60348
|
* pipes a background process keeps open are read for 1 s after the command
|
|
60317
60349
|
* exits; what arrived by then is kept, and the reads are then cancelled, as
|
|
60318
60350
|
* they are at a timeout. The OpenCode 1.x-style `event` hooks (`inProcess`)
|
|
@@ -60460,15 +60492,18 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60460
60492
|
" const timeout = () => new Promise((resolve) => (timer = setTimeout(resolve, seconds * 1000, null)));",
|
|
60461
60493
|
" if (inProcess || !(await __rulesyncCanExec)) {",
|
|
60462
60494
|
` const run = Bun.$\`echo \${input} | \${{ raw: command }}\`.cwd(${cwdExpression}).nothrow();`,
|
|
60463
|
-
"
|
|
60464
|
-
"
|
|
60495
|
+
" // A sessionStart command's stderr reaches the host when it ends, even after its timeout.",
|
|
60496
|
+
" const finished = echo === true ? run : run.quiet().then((done) => (echo && process.stderr.write(done.stderr), done));",
|
|
60497
|
+
" const result = await Promise.race([finished, timeout()]).finally(() => clearTimeout(timer));",
|
|
60498
|
+
" if (!result || echo === true) return result && { exitCode: result.exitCode };",
|
|
60465
60499
|
" const { exitCode, stdout, stderr } = result;",
|
|
60466
60500
|
" return { exitCode, stdout: stdout.toString(), stderr: stderr.toString(), overflow: stdout.length > 1048576 };",
|
|
60467
60501
|
" }",
|
|
60468
|
-
" // An ordinary command writes to the host's stdout and stderr; a preToolUse one is read
|
|
60469
|
-
"
|
|
60470
|
-
` const proc = ${spawn("\"export BUN_BE_BUN=\\n\" + command", "new TextEncoder().encode(input + \"\\n\")", "
|
|
60471
|
-
" const
|
|
60502
|
+
" // An ordinary command writes to the host's stdout and stderr; a preToolUse one is read, and",
|
|
60503
|
+
" // a sessionStart one (`echo: \"stderr\"`) has its stdout read.",
|
|
60504
|
+
` const proc = ${spawn("\"export BUN_BE_BUN=\\n\" + command", "new TextEncoder().encode(input + \"\\n\")", "echo === true ? \"inherit\" : \"pipe\"", "echo ? \"inherit\" : \"pipe\"")};`,
|
|
60505
|
+
" const stdout = echo === true ? undefined : __rulesyncRead(proc.stdout);",
|
|
60506
|
+
" const stderr = echo ? undefined : __rulesyncRead(proc.stderr);",
|
|
60472
60507
|
" const exitCode = await Promise.race([proc.exited, timeout()]).finally(() => clearTimeout(timer));",
|
|
60473
60508
|
" if (exitCode === null) {",
|
|
60474
60509
|
" stdout?.stop(), stderr?.stop();",
|
|
@@ -60476,15 +60511,15 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60476
60511
|
" else __rulesyncKillTree(proc);",
|
|
60477
60512
|
" return null;",
|
|
60478
60513
|
" }",
|
|
60479
|
-
" if (echo) return { exitCode };",
|
|
60480
|
-
" await Promise.race([Promise.all([stdout.done, stderr
|
|
60481
|
-
" stdout.stop(), stderr
|
|
60482
|
-
" return { exitCode, stdout: stdout.text(), stderr: stderr
|
|
60514
|
+
" if (echo === true) return { exitCode };",
|
|
60515
|
+
" await Promise.race([Promise.all([stdout.done, stderr?.done]), Bun.sleep(1000)]);",
|
|
60516
|
+
" stdout.stop(), stderr?.stop();",
|
|
60517
|
+
" return { exitCode, stdout: stdout.text(), stderr: stderr?.text() ?? \"\", overflow: stdout.overflow() };",
|
|
60483
60518
|
"};",
|
|
60484
|
-
"const __rulesyncRunHook = async ({ label, command, input, blocking, seconds, inProcess = false }) => {",
|
|
60519
|
+
"const __rulesyncRunHook = async ({ label, command, input, blocking, seconds, inProcess = false, context = false }) => {",
|
|
60485
60520
|
" let result;",
|
|
60486
60521
|
" try {",
|
|
60487
|
-
" result = await __rulesyncRunCommand({ command, input, seconds, inProcess, echo: true });",
|
|
60522
|
+
" result = await __rulesyncRunCommand({ command, input, seconds, inProcess, echo: context ? \"stderr\" : true });",
|
|
60488
60523
|
" } catch (error) {",
|
|
60489
60524
|
" if (blocking) throw error;",
|
|
60490
60525
|
" console.error(\"[rulesync-hooks] \" + label + \" hook failed:\", error);",
|
|
@@ -60495,7 +60530,7 @@ function buildRunHelperLinesFor(cwdExpression) {
|
|
|
60495
60530
|
" if (blocking) throw new Error(message);",
|
|
60496
60531
|
" return console.error(message);",
|
|
60497
60532
|
" }",
|
|
60498
|
-
" if (result.exitCode === 0) return;",
|
|
60533
|
+
" if (result.exitCode === 0) return result;",
|
|
60499
60534
|
" const message = \"[rulesync-hooks] \" + label + \" hook exited with code \" + result.exitCode;",
|
|
60500
60535
|
" if (blocking) throw new Error(message);",
|
|
60501
60536
|
" console.error(message);",
|
|
@@ -60563,6 +60598,85 @@ const PRE_TOOL_USE_RESULT_HELPER_LINES = [
|
|
|
60563
60598
|
" );",
|
|
60564
60599
|
"};"
|
|
60565
60600
|
];
|
|
60601
|
+
/**
|
|
60602
|
+
* Helpers the generated plugin defines when a `sessionStart` handler is
|
|
60603
|
+
* present, so the command's stdout reaches the model as Claude Code's
|
|
60604
|
+
* `SessionStart` stdout does:
|
|
60605
|
+
* - `__rulesyncSessionStart(sessionID, run)` runs a session's `sessionStart`
|
|
60606
|
+
* commands (`run` pushes each command's result) and keeps the pending context
|
|
60607
|
+
* for that session. It always settles, since every command is bounded by its
|
|
60608
|
+
* timeout.
|
|
60609
|
+
* - `__rulesyncSessionContext(sessionID)` waits for that context, which the
|
|
60610
|
+
* host's system-prompt hook then adds to each model request of the session.
|
|
60611
|
+
*
|
|
60612
|
+
* A command's context is its stdout on exit code 0, or the
|
|
60613
|
+
* `hookSpecificOutput.additionalContext` string of a JSON object it prints,
|
|
60614
|
+
* trimmed and capped at Claude Code's 10,000 characters; more than 1 MiB of
|
|
60615
|
+
* stdout is logged and ignored. Only sessions whose context is not empty are
|
|
60616
|
+
* kept, the 100 whose context was used or became ready most recently, and a
|
|
60617
|
+
* deleted session is dropped.
|
|
60618
|
+
*/
|
|
60619
|
+
const SESSION_CONTEXT_HELPER_LINES = [
|
|
60620
|
+
"const __rulesyncSessionContexts = new Map();",
|
|
60621
|
+
"const __rulesyncKept = new WeakSet();",
|
|
60622
|
+
"const __rulesyncContextOf = (result) => {",
|
|
60623
|
+
" if (typeof result?.stdout !== \"string\") return \"\";",
|
|
60624
|
+
" if (result.overflow) {",
|
|
60625
|
+
" console.error(\"[rulesync-hooks] sessionStart hook wrote more than 1 MiB to stdout; it is ignored\");",
|
|
60626
|
+
" return \"\";",
|
|
60627
|
+
" }",
|
|
60628
|
+
" let text = result.stdout;",
|
|
60629
|
+
" try {",
|
|
60630
|
+
" const parsed = JSON.parse(text);",
|
|
60631
|
+
" // Like Claude Code, only a JSON object counts as JSON output; anything else is plain text.",
|
|
60632
|
+
" if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) text = parsed.hookSpecificOutput?.additionalContext;",
|
|
60633
|
+
" } catch {}",
|
|
60634
|
+
" return typeof text === \"string\" ? text.trim().slice(0, 10000) : \"\";",
|
|
60635
|
+
"};",
|
|
60636
|
+
"const __rulesyncSessionStart = (sessionID, run) => {",
|
|
60637
|
+
" const results = [];",
|
|
60638
|
+
" const pending = run(results)",
|
|
60639
|
+
" .catch(() => {})",
|
|
60640
|
+
" .then(() => results.map(__rulesyncContextOf).filter(Boolean).join(\"\\n\\n\"));",
|
|
60641
|
+
" if (typeof sessionID === \"string\") {",
|
|
60642
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60643
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60644
|
+
" // Only a non-empty context is kept, and only it counts towards the 100: a running",
|
|
60645
|
+
" // or empty one never evicts another session's context.",
|
|
60646
|
+
" pending.then((context) => {",
|
|
60647
|
+
" if (__rulesyncSessionContexts.get(sessionID) !== pending) return;",
|
|
60648
|
+
" if (!context) return void __rulesyncSessionContexts.delete(sessionID);",
|
|
60649
|
+
" __rulesyncKept.add(pending);",
|
|
60650
|
+
" // Evict in completion order: a context counts as used once it is ready.",
|
|
60651
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60652
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60653
|
+
" const kept = [...__rulesyncSessionContexts].filter(([, entry]) => __rulesyncKept.has(entry));",
|
|
60654
|
+
" if (kept.length > 100) __rulesyncSessionContexts.delete(kept[0][0]);",
|
|
60655
|
+
" });",
|
|
60656
|
+
" }",
|
|
60657
|
+
" return pending;",
|
|
60658
|
+
"};",
|
|
60659
|
+
"const __rulesyncSessionContext = async (sessionID) => {",
|
|
60660
|
+
" const pending = __rulesyncSessionContexts.get(sessionID);",
|
|
60661
|
+
" if (!pending) return \"\";",
|
|
60662
|
+
" __rulesyncSessionContexts.delete(sessionID);",
|
|
60663
|
+
" __rulesyncSessionContexts.set(sessionID, pending);",
|
|
60664
|
+
" return pending;",
|
|
60665
|
+
"};"
|
|
60666
|
+
];
|
|
60667
|
+
/**
|
|
60668
|
+
* The statements of a `sessionStart` group, run through `__rulesyncSessionStart`.
|
|
60669
|
+
* `__rulesyncSessionStart` registers the session's pending context before its
|
|
60670
|
+
* first `await`, so `"void"` (used by the serial V2 event loop) registers it
|
|
60671
|
+
* as soon as the event is read without waiting for the commands.
|
|
60672
|
+
*/
|
|
60673
|
+
function wrapSessionStartLines(sessionIdExpression, statements, operator = "await") {
|
|
60674
|
+
return [
|
|
60675
|
+
`${operator} __rulesyncSessionStart(${sessionIdExpression}, async (__rulesyncResults) => {`,
|
|
60676
|
+
...statements.map((line) => ` ${line}`),
|
|
60677
|
+
"});"
|
|
60678
|
+
];
|
|
60679
|
+
}
|
|
60566
60680
|
function escapeForTemplateLiteral(command) {
|
|
60567
60681
|
return command.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
60568
60682
|
}
|
|
@@ -60623,6 +60737,14 @@ function warnIgnoredFailClosed({ config, supportedEvents, toolConfigKey, logger
|
|
|
60623
60737
|
}
|
|
60624
60738
|
}
|
|
60625
60739
|
}
|
|
60740
|
+
/** Whether any handler is a `sessionStart` one, whose stdout becomes session context. */
|
|
60741
|
+
function usesSessionContext(handlers) {
|
|
60742
|
+
return handlers.some((handler) => handler.context);
|
|
60743
|
+
}
|
|
60744
|
+
/** The handler fields a canonical event's `sessionStart`-ness adds. */
|
|
60745
|
+
function sessionContextExtrasFor(canonicalEvent) {
|
|
60746
|
+
return canonicalEvent === "sessionStart" ? { context: true } : {};
|
|
60747
|
+
}
|
|
60626
60748
|
/** The per-canonical-event gates and payload every handler of it carries. */
|
|
60627
60749
|
function handlerExtrasFor(canonicalEvent) {
|
|
60628
60750
|
const shellGate = SHELL_EVENT_TOOL_GATES[canonicalEvent];
|
|
@@ -60632,7 +60754,8 @@ function handlerExtrasFor(canonicalEvent) {
|
|
|
60632
60754
|
event: canonicalEvent,
|
|
60633
60755
|
...shellGate ? { toolGate: shellGate.tool } : {},
|
|
60634
60756
|
...propertyGate ? { propertyGate } : {},
|
|
60635
|
-
...payload ? { payload } : {}
|
|
60757
|
+
...payload ? { payload } : {},
|
|
60758
|
+
...sessionContextExtrasFor(canonicalEvent)
|
|
60636
60759
|
};
|
|
60637
60760
|
}
|
|
60638
60761
|
/**
|
|
@@ -60674,22 +60797,22 @@ function buildGenericEventBodyLines(genericEventHandlers) {
|
|
|
60674
60797
|
const bodyLines = [];
|
|
60675
60798
|
if (Object.keys(genericEventHandlers).length === 0) return bodyLines;
|
|
60676
60799
|
bodyLines.push(" event: async ({ event }) => {");
|
|
60800
|
+
if (Object.values(genericEventHandlers).some(usesSessionContext)) bodyLines.push(` if (event.type === "session.deleted") __rulesyncSessionContexts.delete(${V1_SESSION_ID_EXPRESSION});`);
|
|
60677
60801
|
let isFirst = true;
|
|
60678
60802
|
for (const [eventName, handlers] of Object.entries(genericEventHandlers)) {
|
|
60679
60803
|
bodyLines.push(` ${isFirst ? "if" : "else if"} (event.type === "${eventName}") {`);
|
|
60680
60804
|
isFirst = false;
|
|
60681
|
-
|
|
60805
|
+
const statements = buildPayloadClosureLines({
|
|
60682
60806
|
handlers,
|
|
60683
60807
|
cwdExpression: V1_CWD_EXPRESSION
|
|
60684
|
-
})
|
|
60808
|
+
});
|
|
60685
60809
|
for (const handler of handlers) {
|
|
60686
60810
|
const runStatement = buildRunStatement(handler);
|
|
60687
|
-
if (handler.propertyGate) {
|
|
60688
|
-
|
|
60689
|
-
bodyLines.push(` ${runStatement}`);
|
|
60690
|
-
bodyLines.push(" }");
|
|
60691
|
-
} else bodyLines.push(` ${runStatement}`);
|
|
60811
|
+
if (handler.propertyGate) statements.push(`if (${handler.propertyGate}) {`, ` ${runStatement}`, "}");
|
|
60812
|
+
else statements.push(runStatement);
|
|
60692
60813
|
}
|
|
60814
|
+
const lines = usesSessionContext(handlers) ? wrapSessionStartLines(V1_SESSION_ID_EXPRESSION, statements) : statements;
|
|
60815
|
+
bodyLines.push(...lines.map((line) => ` ${line}`));
|
|
60693
60816
|
bodyLines.push(" }");
|
|
60694
60817
|
}
|
|
60695
60818
|
bodyLines.push(" },");
|
|
@@ -60700,6 +60823,19 @@ function stdinPayloadVariable(stdinEvent) {
|
|
|
60700
60823
|
}
|
|
60701
60824
|
/** The `cwd` a V1 payload reports: the session directory, else the process's. */
|
|
60702
60825
|
const V1_CWD_EXPRESSION = "directory ?? process.cwd()";
|
|
60826
|
+
/** The session a V1 `session.created` / `session.deleted` event is about. */
|
|
60827
|
+
const V1_SESSION_ID_EXPRESSION = "event.properties?.info?.id";
|
|
60828
|
+
/**
|
|
60829
|
+
* The V1 named hook that adds a session's `sessionStart` context to the system
|
|
60830
|
+
* prompt of each of its model requests. OpenCode 1.x, Kilo and MiMo Code all
|
|
60831
|
+
* call it with the request's `sessionID`.
|
|
60832
|
+
*/
|
|
60833
|
+
const V1_SYSTEM_TRANSFORM_LINES = [
|
|
60834
|
+
" \"experimental.chat.system.transform\": async (input, output) => {",
|
|
60835
|
+
" const context = await __rulesyncSessionContext(input?.sessionID);",
|
|
60836
|
+
" if (context && Array.isArray(output?.system)) output.system.push(context);",
|
|
60837
|
+
" },"
|
|
60838
|
+
];
|
|
60703
60839
|
/** Lazily serialized closures for the payloads the handlers use (internal tables only). */
|
|
60704
60840
|
function buildPayloadClosureLines({ handlers, cwdExpression }) {
|
|
60705
60841
|
const payloads = /* @__PURE__ */ new Map();
|
|
@@ -60727,20 +60863,27 @@ function buildRunStatement(handler) {
|
|
|
60727
60863
|
const failClosed = handler.failClosed === void 0 ? "" : `, ${handler.failClosed}`;
|
|
60728
60864
|
return `${PRE_TOOL_USE_RESULT_HELPER}(await __rulesyncRunCommand({ command: ${command}, input: ${input}, seconds: ${handler.timeout} })${failClosed});`;
|
|
60729
60865
|
}
|
|
60730
|
-
|
|
60866
|
+
const run = `await __rulesyncRunHook({ ${[
|
|
60731
60867
|
`label: ${JSON.stringify(handler.event)}`,
|
|
60732
60868
|
`command: ${command}`,
|
|
60733
60869
|
`input: ${input}`,
|
|
60734
60870
|
`blocking: ${handler.blocking}`,
|
|
60735
60871
|
`seconds: ${handler.timeout}`,
|
|
60736
|
-
...handler.inProcess ? ["inProcess: true"] : []
|
|
60737
|
-
|
|
60872
|
+
...handler.inProcess ? ["inProcess: true"] : [],
|
|
60873
|
+
...handler.context ? ["context: true"] : []
|
|
60874
|
+
].join(", ")} })`;
|
|
60875
|
+
return handler.context ? `__rulesyncResults.push(${run});` : `${run};`;
|
|
60738
60876
|
}
|
|
60739
60877
|
/** The helpers a plugin body defines before its handlers, run in `cwdExpression`. */
|
|
60740
60878
|
function buildRunHelperLines({ handlers, cwdExpression }) {
|
|
60741
60879
|
if (handlers.length === 0) return [];
|
|
60742
60880
|
const usesPreToolUse = handlers.some((handler) => handler.payload?.name === "PreToolUse");
|
|
60743
|
-
|
|
60881
|
+
const usesContext = usesSessionContext(handlers);
|
|
60882
|
+
return [
|
|
60883
|
+
...buildRunHelperLinesFor(cwdExpression),
|
|
60884
|
+
...usesPreToolUse ? ["", ...PRE_TOOL_USE_RESULT_HELPER_LINES] : [],
|
|
60885
|
+
...usesContext ? ["", ...SESSION_CONTEXT_HELPER_LINES] : []
|
|
60886
|
+
];
|
|
60744
60887
|
}
|
|
60745
60888
|
/** Emit the named (`tool.execute.*`) handler blocks. */
|
|
60746
60889
|
function buildNamedEventBodyLines(namedEventHandlers) {
|
|
@@ -60814,7 +60957,12 @@ function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey,
|
|
|
60814
60957
|
namedEventHandlers,
|
|
60815
60958
|
genericEventHandlers
|
|
60816
60959
|
});
|
|
60817
|
-
const
|
|
60960
|
+
const usesContext = Object.values(genericEventHandlers).some(usesSessionContext);
|
|
60961
|
+
const bodyLines = [
|
|
60962
|
+
...buildGenericEventBodyLines(genericEventHandlers),
|
|
60963
|
+
...buildNamedEventBodyLines(namedEventHandlers),
|
|
60964
|
+
...usesContext ? V1_SYSTEM_TRANSFORM_LINES : []
|
|
60965
|
+
];
|
|
60818
60966
|
return wrapInExportShape({
|
|
60819
60967
|
preambleLines: buildRunHelperLines({
|
|
60820
60968
|
handlers: [...Object.values(namedEventHandlers), ...Object.values(genericEventHandlers)].flat(),
|
|
@@ -61127,6 +61275,37 @@ const KiroIdeHooksFileSchema = z.looseObject({
|
|
|
61127
61275
|
hooks: z.optional(z.array(KiroIdeHookEntrySchema))
|
|
61128
61276
|
});
|
|
61129
61277
|
/**
|
|
61278
|
+
* Triggers on which Kiro runs only `command` actions.
|
|
61279
|
+
* @see https://kiro.dev/docs/hooks/types/#permission-request
|
|
61280
|
+
*/
|
|
61281
|
+
const KIRO_COMMAND_ONLY_TRIGGERS = /* @__PURE__ */ new Set(["PermissionRequest"]);
|
|
61282
|
+
/**
|
|
61283
|
+
* Whether an imported entry is an `agent` action on a command-only trigger
|
|
61284
|
+
* (Kiro also accepts the camelCase `permissionRequest` spelling). Kiro never
|
|
61285
|
+
* runs such a hook, so importing it would hand other targets an LLM
|
|
61286
|
+
* permission hook the user never had in effect.
|
|
61287
|
+
*/
|
|
61288
|
+
function isAgentActionOnCommandOnlyTrigger(entry) {
|
|
61289
|
+
if (entry.action?.type !== "agent" || entry.trigger === void 0) return false;
|
|
61290
|
+
const trigger = lookupOwn({
|
|
61291
|
+
record: CANONICAL_TO_KIRO_IDE_EVENT_NAMES,
|
|
61292
|
+
key: entry.trigger
|
|
61293
|
+
}) ?? entry.trigger;
|
|
61294
|
+
return KIRO_COMMAND_ONLY_TRIGGERS.has(trigger);
|
|
61295
|
+
}
|
|
61296
|
+
/**
|
|
61297
|
+
* Drop `prompt` definitions on a {@link KIRO_COMMAND_ONLY_TRIGGERS} trigger with
|
|
61298
|
+
* a warning, rather than writing an `agent` action Kiro never runs.
|
|
61299
|
+
*/
|
|
61300
|
+
function dropPromptHooksOnCommandOnlyTrigger(trigger, definitions, logger) {
|
|
61301
|
+
if (!KIRO_COMMAND_ONLY_TRIGGERS.has(trigger)) return definitions;
|
|
61302
|
+
return definitions.filter((def) => {
|
|
61303
|
+
if (def.type !== "prompt") return true;
|
|
61304
|
+
logger?.warn(`Skipped a prompt hook on Kiro's "${trigger}" trigger: Kiro runs only command actions on it.`);
|
|
61305
|
+
return false;
|
|
61306
|
+
});
|
|
61307
|
+
}
|
|
61308
|
+
/**
|
|
61130
61309
|
* Build the Kiro IDE hook entries for a single canonical event's definitions.
|
|
61131
61310
|
*
|
|
61132
61311
|
* `command`-type definitions become `{ type: "command", command }` actions and
|
|
@@ -61181,7 +61360,7 @@ const KIRO_HOOKS_OVERRIDE_KEY = "kiro";
|
|
|
61181
61360
|
* that is actually read.
|
|
61182
61361
|
*/
|
|
61183
61362
|
const KIRO_HOOKS_IGNORED_OVERRIDE_KEYS = ["kiro-ide", "kiro-cli"];
|
|
61184
|
-
function canonicalToKiroIdeHooks(config) {
|
|
61363
|
+
function canonicalToKiroIdeHooks(config, logger) {
|
|
61185
61364
|
const kiroIdeSupported = new Set(KIRO_IDE_HOOK_EVENTS);
|
|
61186
61365
|
const sharedHooks = {};
|
|
61187
61366
|
for (const [event, defs] of Object.entries(config.hooks)) if (kiroIdeSupported.has(event)) sharedHooks[event] = defs;
|
|
@@ -61198,7 +61377,7 @@ function canonicalToKiroIdeHooks(config) {
|
|
|
61198
61377
|
record: KIRO_LEGACY_TO_KIRO_IDE_TRIGGER_NAMES,
|
|
61199
61378
|
key: eventName
|
|
61200
61379
|
}) ?? eventName;
|
|
61201
|
-
entries.push(...buildKiroIdeEntriesForEvent(trigger, definitions));
|
|
61380
|
+
entries.push(...buildKiroIdeEntriesForEvent(trigger, dropPromptHooksOnCommandOnlyTrigger(trigger, definitions, logger)));
|
|
61202
61381
|
}
|
|
61203
61382
|
return entries;
|
|
61204
61383
|
}
|
|
@@ -61210,25 +61389,35 @@ function copyOptionalHookFields({ entry, def }) {
|
|
|
61210
61389
|
if (entry.enabled === false) def.enabled = false;
|
|
61211
61390
|
if (entry.confirm !== void 0 && entry.confirm !== null) def.confirm = omitPrototypePollutionKeysDeep(entry.confirm);
|
|
61212
61391
|
}
|
|
61213
|
-
|
|
61392
|
+
/**
|
|
61393
|
+
* The canonical `type` plus `command` / `prompt` of an imported Kiro action, or
|
|
61394
|
+
* `undefined` when the action carries nothing to run.
|
|
61395
|
+
*/
|
|
61396
|
+
function toCanonicalAction(action) {
|
|
61397
|
+
if (action.type === "command") return action.command ? {
|
|
61398
|
+
type: "command",
|
|
61399
|
+
command: action.command
|
|
61400
|
+
} : void 0;
|
|
61401
|
+
return action.prompt ? {
|
|
61402
|
+
type: "prompt",
|
|
61403
|
+
prompt: action.prompt
|
|
61404
|
+
} : void 0;
|
|
61405
|
+
}
|
|
61406
|
+
function kiroIdeHooksToCanonical(entries, logger) {
|
|
61214
61407
|
const canonical = {};
|
|
61215
61408
|
for (const entry of entries) {
|
|
61216
61409
|
if (entry.trigger === void 0 || entry.action === void 0) continue;
|
|
61410
|
+
if (isAgentActionOnCommandOnlyTrigger(entry)) {
|
|
61411
|
+
logger?.warn(`Skipped an agent hook on Kiro's "${entry.trigger}" trigger: Kiro runs only command actions on it.`);
|
|
61412
|
+
continue;
|
|
61413
|
+
}
|
|
61217
61414
|
const eventName = lookupOwn({
|
|
61218
61415
|
record: KIRO_IDE_TO_CANONICAL_EVENT_NAMES,
|
|
61219
61416
|
key: entry.trigger
|
|
61220
61417
|
}) ?? entry.trigger;
|
|
61221
61418
|
if (isPrototypePollutionKey(eventName)) continue;
|
|
61222
|
-
const def =
|
|
61223
|
-
if (
|
|
61224
|
-
if (!entry.action.command) continue;
|
|
61225
|
-
def.type = "command";
|
|
61226
|
-
def.command = entry.action.command;
|
|
61227
|
-
} else {
|
|
61228
|
-
if (!entry.action.prompt) continue;
|
|
61229
|
-
def.type = "prompt";
|
|
61230
|
-
def.prompt = entry.action.prompt;
|
|
61231
|
-
}
|
|
61419
|
+
const def = toCanonicalAction(entry.action);
|
|
61420
|
+
if (def === void 0) continue;
|
|
61232
61421
|
if (entry.name !== void 0 && entry.name !== null) def.name = entry.name;
|
|
61233
61422
|
if (entry.description !== void 0 && entry.description !== null) def.description = entry.description;
|
|
61234
61423
|
if (entry.matcher !== void 0 && entry.matcher !== null && entry.matcher !== "") def.matcher = entry.matcher;
|
|
@@ -61294,7 +61483,7 @@ var KiroIdeHooks = class extends ToolHooks {
|
|
|
61294
61483
|
if (config[ignoredKey]?.hooks === void 0) continue;
|
|
61295
61484
|
logger?.warn(`The "${ignoredKey}.hooks" block in ${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.`);
|
|
61296
61485
|
}
|
|
61297
|
-
const hooks = canonicalToKiroIdeHooks(config);
|
|
61486
|
+
const hooks = canonicalToKiroIdeHooks(config, logger);
|
|
61298
61487
|
const fileContent = JSON.stringify({
|
|
61299
61488
|
version: "v1",
|
|
61300
61489
|
hooks
|
|
@@ -61311,7 +61500,7 @@ var KiroIdeHooks = class extends ToolHooks {
|
|
|
61311
61500
|
const hooks = kiroIdeHooksToCanonical(this.parseFileContentOrThrow({
|
|
61312
61501
|
displayName: "Kiro IDE",
|
|
61313
61502
|
parse: (fileContent) => KiroIdeHooksFileSchema.parse(JSON.parse(fileContent))
|
|
61314
|
-
}).hooks ?? []);
|
|
61503
|
+
}).hooks ?? [], logger);
|
|
61315
61504
|
return this.toRulesyncHooksDefault({ fileContent: JSON.stringify(buildImportedHooksConfig({
|
|
61316
61505
|
logger,
|
|
61317
61506
|
hooks,
|
|
@@ -61743,6 +61932,27 @@ const TOOL_MATCHER_HELPER_LINES = [
|
|
|
61743
61932
|
];
|
|
61744
61933
|
/** Hook points whose `matcher` is tested against the tool name. */
|
|
61745
61934
|
const OPENCODE_V2_MATCHABLE_HOOKS = /* @__PURE__ */ new Set(["tool:execute.before", "tool:execute.after"]);
|
|
61935
|
+
/** The session a V2 `session.created` / `session.deleted` event is about. */
|
|
61936
|
+
const V2_SESSION_ID_EXPRESSION = "event.data?.sessionID";
|
|
61937
|
+
/**
|
|
61938
|
+
* The `session:context` registration that adds a session's `sessionStart`
|
|
61939
|
+
* context to the system prompt of each of its agent-loop model requests. A
|
|
61940
|
+
* host that cannot register it (no `ctx.session.hook`, or no `context` hook
|
|
61941
|
+
* point) gets a logged error instead of a setup throw, so the plugin's other
|
|
61942
|
+
* hooks, `preToolUse` guards included, still load.
|
|
61943
|
+
*/
|
|
61944
|
+
const SESSION_CONTEXT_HOOK_LINES = [
|
|
61945
|
+
"try {",
|
|
61946
|
+
" __rulesyncRegistrations.push(",
|
|
61947
|
+
" await ctx.session.hook(\"context\", async (event) => {",
|
|
61948
|
+
" const context = await __rulesyncSessionContext(event?.sessionID);",
|
|
61949
|
+
" if (context && Array.isArray(event?.system)) event.system.push({ type: \"text\", text: context });",
|
|
61950
|
+
" }),",
|
|
61951
|
+
" );",
|
|
61952
|
+
"} catch (error) {",
|
|
61953
|
+
" console.error(\"[rulesync-hooks] could not register the session context hook; sessionStart output does not reach the model:\", error);",
|
|
61954
|
+
"}"
|
|
61955
|
+
];
|
|
61746
61956
|
/** Wrap a statement in the handler's gate and matcher conditions. */
|
|
61747
61957
|
function wrapInConditions(handler, statement, indent) {
|
|
61748
61958
|
const conditions = [];
|
|
@@ -61779,32 +61989,52 @@ function buildHookRegistrationLines(hookPoint, handlers) {
|
|
|
61779
61989
|
* in its own try/catch, so a throw while evaluating its gate or building its
|
|
61780
61990
|
* payload, outside `__rulesyncRunHook`, is logged the same way. The
|
|
61781
61991
|
* subscription passes `types` so the server delivers only the handled events.
|
|
61992
|
+
*
|
|
61993
|
+
* The loop itself never waits for a command, so a slow handler cannot hold back
|
|
61994
|
+
* the events after it: handlers run one after another on
|
|
61995
|
+
* `__rulesyncEventQueue`, in event order, while `sessionStart` starts right
|
|
61996
|
+
* away, outside the queue (so it can overlap other event commands), and its
|
|
61997
|
+
* session's pending context is registered before that session's first model
|
|
61998
|
+
* request asks for it. Handlers still queued at dispose are skipped.
|
|
61782
61999
|
*/
|
|
61783
|
-
function buildEventLoopLines(eventHandlers) {
|
|
62000
|
+
function buildEventLoopLines(eventHandlers, usesContext) {
|
|
61784
62001
|
const lines = [];
|
|
61785
|
-
const
|
|
62002
|
+
const eventTypes = new Set(eventHandlers.keys());
|
|
62003
|
+
if (usesContext) eventTypes.add("session.deleted");
|
|
62004
|
+
const types = [...eventTypes].map((eventType) => JSON.stringify(eventType)).join(", ");
|
|
61786
62005
|
lines.push("const __rulesyncEvents = new AbortController();");
|
|
62006
|
+
lines.push("let __rulesyncEventQueue = Promise.resolve();");
|
|
61787
62007
|
lines.push("void (async () => {");
|
|
61788
62008
|
lines.push(" for await (const event of ctx.event.subscribe({");
|
|
61789
62009
|
lines.push(` types: [${types}],`);
|
|
61790
62010
|
lines.push(" signal: __rulesyncEvents.signal,");
|
|
61791
62011
|
lines.push(" })) {");
|
|
62012
|
+
if (usesContext) lines.push(` if (event.type === "session.deleted") __rulesyncSessionContexts.delete(${V2_SESSION_ID_EXPRESSION});`);
|
|
61792
62013
|
let isFirst = true;
|
|
61793
62014
|
for (const [eventType, handlers] of eventHandlers) {
|
|
61794
62015
|
lines.push(` ${isFirst ? "if" : "} else if"} (event.type === "${eventType}") {`);
|
|
61795
62016
|
isFirst = false;
|
|
61796
|
-
|
|
62017
|
+
const statements = buildPayloadClosureLines({
|
|
61797
62018
|
handlers,
|
|
61798
62019
|
cwdExpression: "directory"
|
|
61799
|
-
})
|
|
62020
|
+
});
|
|
61800
62021
|
for (const handler of handlers) {
|
|
61801
|
-
|
|
61802
|
-
|
|
61803
|
-
|
|
62022
|
+
statements.push("try {");
|
|
62023
|
+
statements.push(...wrapInConditions(handler, buildRunStatement(handler), " "));
|
|
62024
|
+
statements.push("} catch (error) {");
|
|
61804
62025
|
const message = JSON.stringify(`[rulesync-hooks] ${handler.event} hook failed:`);
|
|
61805
|
-
|
|
61806
|
-
|
|
61807
|
-
}
|
|
62026
|
+
statements.push(` console.error(${message}, error);`);
|
|
62027
|
+
statements.push("}");
|
|
62028
|
+
}
|
|
62029
|
+
const body = usesSessionContext(handlers) ? wrapSessionStartLines(V2_SESSION_ID_EXPRESSION, statements, "void") : [
|
|
62030
|
+
"__rulesyncEventQueue = __rulesyncEventQueue",
|
|
62031
|
+
" .then(async () => {",
|
|
62032
|
+
" if (__rulesyncEvents.signal.aborted) return;",
|
|
62033
|
+
...statements.map((line) => ` ${line}`),
|
|
62034
|
+
" })",
|
|
62035
|
+
` .catch((error) => console.error(${JSON.stringify(`[rulesync-hooks] ${eventType} event hook failed:`)}, error));`
|
|
62036
|
+
];
|
|
62037
|
+
lines.push(...body.map((line) => ` ${line}`));
|
|
61808
62038
|
}
|
|
61809
62039
|
lines.push(" }");
|
|
61810
62040
|
lines.push(" }");
|
|
@@ -61835,7 +62065,8 @@ function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
|
61835
62065
|
...hookTimingOf(def),
|
|
61836
62066
|
...def.matcher ? { matcher: def.matcher } : {},
|
|
61837
62067
|
...gate ? { gate } : {},
|
|
61838
|
-
...payload ? { payload } : {}
|
|
62068
|
+
...payload ? { payload } : {},
|
|
62069
|
+
...sessionContextExtrasFor(canonicalEvent)
|
|
61839
62070
|
});
|
|
61840
62071
|
}
|
|
61841
62072
|
return handlers;
|
|
@@ -61852,16 +62083,19 @@ function buildSetupBodyLines({ hookHandlers, eventHandlers }) {
|
|
|
61852
62083
|
})
|
|
61853
62084
|
];
|
|
61854
62085
|
if ([...hookHandlers.values()].some((handlers) => handlers.some((handler) => handler.matcher !== void 0))) body.push("", ...TOOL_MATCHER_HELPER_LINES);
|
|
62086
|
+
const usesContext = [...eventHandlers.values()].some(usesSessionContext);
|
|
62087
|
+
const registers = hookHandlers.size > 0 || usesContext;
|
|
61855
62088
|
const cleanup = [];
|
|
61856
|
-
if (
|
|
62089
|
+
if (registers) {
|
|
61857
62090
|
body.push("", "const __rulesyncRegistrations = [];");
|
|
61858
62091
|
for (const [hookPoint, handlers] of hookHandlers) body.push(...buildHookRegistrationLines(hookPoint, handlers));
|
|
62092
|
+
if (usesContext) body.push(...SESSION_CONTEXT_HOOK_LINES);
|
|
61859
62093
|
}
|
|
61860
62094
|
if (eventHandlers.size > 0) {
|
|
61861
|
-
body.push("", ...buildEventLoopLines(eventHandlers));
|
|
62095
|
+
body.push("", ...buildEventLoopLines(eventHandlers, usesContext));
|
|
61862
62096
|
cleanup.push(" __rulesyncEvents.abort();");
|
|
61863
62097
|
}
|
|
61864
|
-
if (
|
|
62098
|
+
if (registers) cleanup.push(" await Promise.all(__rulesyncRegistrations.map((registration) => registration.dispose()));");
|
|
61865
62099
|
body.push("", "return async () => {", ...cleanup, "};");
|
|
61866
62100
|
return body;
|
|
61867
62101
|
}
|
|
@@ -72701,12 +72935,22 @@ const MAX_REMOVE_EMPTY_ENTRIES_DEPTH = 32;
|
|
|
72701
72935
|
*/
|
|
72702
72936
|
const GROK_DISABLED_MCP_TOOLS_KEY = "disabled_mcp_tools";
|
|
72703
72937
|
/**
|
|
72938
|
+
* Grok 1.0.88+ runs a command that prints JSON headers at every connect of an
|
|
72939
|
+
* HTTP/SSE server. In `config.toml` the key is `headers_helper`; the camelCase
|
|
72940
|
+
* `headersHelper` (rulesync's canonical spelling) is documented for
|
|
72941
|
+
* `.mcp.json` only, so it is renamed in both directions.
|
|
72942
|
+
* (Grok user guide `07-mcp-servers.md`, "Headers from a command".)
|
|
72943
|
+
*/
|
|
72944
|
+
const CANONICAL_HEADERS_HELPER_KEY = "headersHelper";
|
|
72945
|
+
const GROK_HEADERS_HELPER_KEY = "headers_helper";
|
|
72946
|
+
/**
|
|
72704
72947
|
* Grok Build stores MCP servers in `config.toml` under a `[mcp_servers.<name>]`
|
|
72705
72948
|
* table. Verified against `grok mcp add` (grok 0.2.54): a stdio server emits
|
|
72706
72949
|
* `command`, `args`, `enabled = true`, and an `[mcp_servers.<name>.env]` table;
|
|
72707
72950
|
* a remote server emits `url` and `enabled`. Unlike Codex CLI, Grok uses a
|
|
72708
|
-
* literal `env` table (not the `env_vars` passthrough list), so the
|
|
72709
|
-
*
|
|
72951
|
+
* literal `env` table (not the `env_vars` passthrough list), so the field
|
|
72952
|
+
* renames are `disabled` (rulesync) ↔ `enabled = false` (grok) and
|
|
72953
|
+
* `headersHelper` ↔ `headers_helper`. `disabledTools`
|
|
72710
72954
|
* never lands in the server table: it is lifted into the top-level
|
|
72711
72955
|
* `[disabled_mcp_tools]` table by `buildDisabledMcpTools`.
|
|
72712
72956
|
*/
|
|
@@ -72720,6 +72964,8 @@ function convertToGrokFormat(mcpServers) {
|
|
|
72720
72964
|
if (PROTOTYPE_POLLUTION_KEYS.has(key) || key === "disabledTools") continue;
|
|
72721
72965
|
if (key === "disabled") {
|
|
72722
72966
|
if (value === true) converted["enabled"] = false;
|
|
72967
|
+
} else if (key === CANONICAL_HEADERS_HELPER_KEY) {
|
|
72968
|
+
if (!Object.hasOwn(config, GROK_HEADERS_HELPER_KEY)) converted[GROK_HEADERS_HELPER_KEY] = value;
|
|
72723
72969
|
} else converted[key] = value;
|
|
72724
72970
|
}
|
|
72725
72971
|
result[name] = converted;
|
|
@@ -72735,6 +72981,9 @@ function convertFromGrokFormat(grokMcp) {
|
|
|
72735
72981
|
if (PROTOTYPE_POLLUTION_KEYS.has(key)) continue;
|
|
72736
72982
|
if (key === "enabled") {
|
|
72737
72983
|
if (value === false) converted["disabled"] = true;
|
|
72984
|
+
} else if (key === GROK_HEADERS_HELPER_KEY) converted[CANONICAL_HEADERS_HELPER_KEY] = value;
|
|
72985
|
+
else if (key === CANONICAL_HEADERS_HELPER_KEY) {
|
|
72986
|
+
if (!Object.hasOwn(config, GROK_HEADERS_HELPER_KEY)) converted[CANONICAL_HEADERS_HELPER_KEY] = value;
|
|
72738
72987
|
} else converted[key] = value;
|
|
72739
72988
|
}
|
|
72740
72989
|
result[name] = converted;
|
|
@@ -73850,6 +74099,21 @@ function fromKiroMcpServers(servers) {
|
|
|
73850
74099
|
}];
|
|
73851
74100
|
}));
|
|
73852
74101
|
}
|
|
74102
|
+
/**
|
|
74103
|
+
* Parse an existing user-level `~/.kiro/settings/mcp.json` so a global generate
|
|
74104
|
+
* can merge into it. An unparseable file is refused instead of overwritten:
|
|
74105
|
+
* it is unversioned, so replacing it would lose whatever the user had there.
|
|
74106
|
+
*/
|
|
74107
|
+
function parseExistingKiroMcpConfig(fileContent, configPath) {
|
|
74108
|
+
let parsed;
|
|
74109
|
+
try {
|
|
74110
|
+
parsed = JSON.parse(fileContent);
|
|
74111
|
+
} catch (error) {
|
|
74112
|
+
throw new Error(`Failed to parse Kiro MCP config at ${configPath}: ${formatError(error)}`, { cause: error });
|
|
74113
|
+
}
|
|
74114
|
+
if (!isPlainObject(parsed)) throw new Error(`Failed to parse Kiro MCP config at ${configPath}: expected a JSON object`);
|
|
74115
|
+
return parsed;
|
|
74116
|
+
}
|
|
73853
74117
|
var KiroMcp = class KiroMcp extends ToolMcp {
|
|
73854
74118
|
json;
|
|
73855
74119
|
constructor(params) {
|
|
@@ -73859,13 +74123,26 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73859
74123
|
getJson() {
|
|
73860
74124
|
return this.json;
|
|
73861
74125
|
}
|
|
74126
|
+
/**
|
|
74127
|
+
* The user-level `~/.kiro/settings/mcp.json` also holds settings rulesync
|
|
74128
|
+
* does not manage (such as the top-level `identityProvider` block for
|
|
74129
|
+
* organization sign-in, which Kiro reads only from this file), so it is never
|
|
74130
|
+
* deleted in global mode. The project file is rulesync-managed and may be.
|
|
74131
|
+
* The sweep has no in-place retraction, so a global `--delete` run without a
|
|
74132
|
+
* source leaves the generated `mcpServers` behind; an empty source
|
|
74133
|
+
* (`{ "mcpServers": {} }`) retracts them through the normal merge.
|
|
74134
|
+
* @see https://kiro.dev/docs/mcp/configuration/
|
|
74135
|
+
*/
|
|
74136
|
+
isDeletable() {
|
|
74137
|
+
return !this.global;
|
|
74138
|
+
}
|
|
73862
74139
|
static getSettablePaths() {
|
|
73863
74140
|
return {
|
|
73864
74141
|
relativeDirPath: KIRO_SETTINGS_DIR_PATH,
|
|
73865
74142
|
relativeFilePath: KIRO_MCP_FILE_NAME
|
|
73866
74143
|
};
|
|
73867
74144
|
}
|
|
73868
|
-
static async fromFile({ outputRoot = process.cwd(), validate = true }) {
|
|
74145
|
+
static async fromFile({ outputRoot = process.cwd(), validate = true, global = false }) {
|
|
73869
74146
|
const paths = this.getSettablePaths();
|
|
73870
74147
|
const fileContent = await readFileContentOrNull(join(outputRoot, paths.relativeDirPath, paths.relativeFilePath)) ?? "{\"mcpServers\":{}}";
|
|
73871
74148
|
return new KiroMcp({
|
|
@@ -73873,18 +74150,34 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73873
74150
|
relativeDirPath: paths.relativeDirPath,
|
|
73874
74151
|
relativeFilePath: paths.relativeFilePath,
|
|
73875
74152
|
fileContent,
|
|
73876
|
-
validate
|
|
74153
|
+
validate,
|
|
74154
|
+
global
|
|
73877
74155
|
});
|
|
73878
74156
|
}
|
|
73879
|
-
|
|
74157
|
+
/**
|
|
74158
|
+
* In global mode the generated `mcpServers` are merged into the existing
|
|
74159
|
+
* user-level file, keeping every other top-level key (for example
|
|
74160
|
+
* `identityProvider`). The project file is written from scratch.
|
|
74161
|
+
*/
|
|
74162
|
+
static async fromRulesyncMcp({ outputRoot = process.cwd(), rulesyncMcp, validate = true, global = false }) {
|
|
73880
74163
|
const paths = this.getSettablePaths();
|
|
73881
|
-
const
|
|
74164
|
+
const mcpServers = toKiroMcpServers(rulesyncMcp.getMcpServers());
|
|
74165
|
+
let existing = {};
|
|
74166
|
+
if (global) {
|
|
74167
|
+
const configPath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
74168
|
+
const existingContent = await readFileContentOrNull(configPath);
|
|
74169
|
+
if (existingContent !== null) existing = parseExistingKiroMcpConfig(existingContent, configPath);
|
|
74170
|
+
}
|
|
73882
74171
|
return new KiroMcp({
|
|
73883
74172
|
outputRoot,
|
|
73884
74173
|
relativeDirPath: paths.relativeDirPath,
|
|
73885
74174
|
relativeFilePath: paths.relativeFilePath,
|
|
73886
|
-
fileContent
|
|
73887
|
-
|
|
74175
|
+
fileContent: JSON.stringify({
|
|
74176
|
+
...existing,
|
|
74177
|
+
mcpServers
|
|
74178
|
+
}, null, 2),
|
|
74179
|
+
validate,
|
|
74180
|
+
global
|
|
73888
74181
|
});
|
|
73889
74182
|
}
|
|
73890
74183
|
toRulesyncMcp() {
|
|
@@ -73892,13 +74185,14 @@ var KiroMcp = class KiroMcp extends ToolMcp {
|
|
|
73892
74185
|
const translated = isMcpServers(mcpServers) ? fromKiroMcpServers(mcpServers) : {};
|
|
73893
74186
|
return this.toRulesyncMcpDefault({ fileContent: JSON.stringify({ mcpServers: translated }, null, 2) });
|
|
73894
74187
|
}
|
|
73895
|
-
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath }) {
|
|
74188
|
+
static forDeletion({ outputRoot = process.cwd(), relativeDirPath, relativeFilePath, global = false }) {
|
|
73896
74189
|
return new KiroMcp({
|
|
73897
74190
|
outputRoot,
|
|
73898
74191
|
relativeDirPath,
|
|
73899
74192
|
relativeFilePath,
|
|
73900
74193
|
fileContent: "{}",
|
|
73901
|
-
validate: false
|
|
74194
|
+
validate: false,
|
|
74195
|
+
global
|
|
73902
74196
|
});
|
|
73903
74197
|
}
|
|
73904
74198
|
};
|
|
@@ -84348,6 +84642,29 @@ const CLAUDECODE_WIDENING_DEFAULT_MODES = {
|
|
|
84348
84642
|
*/
|
|
84349
84643
|
const CLAUDECODE_PROJECT_SCOPE_IGNORED_DEFAULT_MODES = /* @__PURE__ */ new Set(["auto", "bypassPermissions"]);
|
|
84350
84644
|
/**
|
|
84645
|
+
* The `permissions` fields Claude Code reads only from user or managed settings
|
|
84646
|
+
* (and `--settings`), never from a repository's `.claude/settings.json`, so
|
|
84647
|
+
* they are dropped at project scope and written only under `--global`.
|
|
84648
|
+
* `denyInsteadOfPrompting` (v2.1.319+) only restricts, but committing it to a
|
|
84649
|
+
* project file would promise unattended denials that never happen.
|
|
84650
|
+
*
|
|
84651
|
+
* @see https://code.claude.com/docs/en/settings-reference#permissions-denyinsteadofprompting
|
|
84652
|
+
*/
|
|
84653
|
+
const CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS = /* @__PURE__ */ new Set(["denyInsteadOfPrompting"]);
|
|
84654
|
+
/**
|
|
84655
|
+
* Drop the project-scope `permissions` fields in
|
|
84656
|
+
* {@link CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS}, warning once per field
|
|
84657
|
+
* in the same voice as the user-scope-only top-level keys.
|
|
84658
|
+
*/
|
|
84659
|
+
function stripUserScopeOnlyPermissionsFields({ fields, global, relativeFilePath, logger }) {
|
|
84660
|
+
if (global) return;
|
|
84661
|
+
for (const key of CLAUDECODE_USER_SCOPE_ONLY_PERMISSIONS_FIELDS) {
|
|
84662
|
+
if (!Object.hasOwn(fields, key)) continue;
|
|
84663
|
+
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}.`);
|
|
84664
|
+
delete fields[key];
|
|
84665
|
+
}
|
|
84666
|
+
}
|
|
84667
|
+
/**
|
|
84351
84668
|
* Drop a project-scope `permissions.defaultMode` Claude Code ignores there (see
|
|
84352
84669
|
* {@link CLAUDECODE_PROJECT_SCOPE_IGNORED_DEFAULT_MODES}), warning in the same
|
|
84353
84670
|
* voice as the other values the project-scoped file cannot honor.
|
|
@@ -84441,7 +84758,7 @@ const CLAUDECODE_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
84441
84758
|
},
|
|
84442
84759
|
{
|
|
84443
84760
|
path: ["enabled"],
|
|
84444
|
-
reason: "turns the sandbox on, and sandboxed Bash commands then run without a permission prompt
|
|
84761
|
+
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)",
|
|
84445
84762
|
widens: isNotFalse
|
|
84446
84763
|
},
|
|
84447
84764
|
{
|
|
@@ -84744,6 +85061,7 @@ const CLAUDECODE_UNHONORED_KEY_SOURCES = {
|
|
|
84744
85061
|
disableCommandPluginSources: "managed settings",
|
|
84745
85062
|
disableDesktopLocalSessions: "managed settings",
|
|
84746
85063
|
disableMobileSimulatorTools: "managed settings",
|
|
85064
|
+
disableRemotePreviewScripts: "managed settings",
|
|
84747
85065
|
disableSideloadFlags: "managed settings",
|
|
84748
85066
|
externalEditorContext: "~/.claude.json",
|
|
84749
85067
|
forceRemoteSettingsRefresh: "managed settings",
|
|
@@ -85237,6 +85555,12 @@ var ClaudecodePermissions = class ClaudecodePermissions extends ToolPermissions
|
|
|
85237
85555
|
relativeFilePath: paths.relativeFilePath,
|
|
85238
85556
|
logger
|
|
85239
85557
|
});
|
|
85558
|
+
stripUserScopeOnlyPermissionsFields({
|
|
85559
|
+
fields: nonListFields,
|
|
85560
|
+
global,
|
|
85561
|
+
relativeFilePath: paths.relativeFilePath,
|
|
85562
|
+
logger
|
|
85563
|
+
});
|
|
85240
85564
|
trustAffecting.push(...collectWideningPermissionFields({ fields: nonListFields }));
|
|
85241
85565
|
settings.permissions = {
|
|
85242
85566
|
...settings.permissions,
|
|
@@ -87214,6 +87538,7 @@ const CODEX_DEFAULT_APPROVAL_POLICY = "on-request";
|
|
|
87214
87538
|
const CODEX_DEFAULT_APPROVALS_REVIEWER = "auto_review";
|
|
87215
87539
|
const CODEX_RETIRED_APPROVAL_POLICY = "untrusted";
|
|
87216
87540
|
const CODEX_DEPRECATED_APPROVAL_POLICY = "on-failure";
|
|
87541
|
+
const CODEX_REMOVED_AUTO_REVIEW_KEYS = ["extra_policy", "experimental_policy_template"];
|
|
87217
87542
|
const CODEX_GLOB_SCAN_MAX_DEPTH = 8;
|
|
87218
87543
|
const CODEX_MINIMAL_KEY = ":minimal";
|
|
87219
87544
|
const CODEX_GIT_WRITE_RULES = { ".git/**": "write" };
|
|
@@ -87815,6 +88140,10 @@ function computeCodexcliOverridePatch({ existing, override, logger }) {
|
|
|
87815
88140
|
value,
|
|
87816
88141
|
logger
|
|
87817
88142
|
})) continue;
|
|
88143
|
+
if (key === "auto_review" && isRecord(value)) warnAboutRemovedAutoReviewKeys({
|
|
88144
|
+
value,
|
|
88145
|
+
logger
|
|
88146
|
+
});
|
|
87818
88147
|
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.`);
|
|
87819
88148
|
const existingValue = existing[key];
|
|
87820
88149
|
patch[key] = isRecord(existingValue) && isRecord(value) ? {
|
|
@@ -87854,6 +88183,12 @@ function isWritableApprovalPolicy({ value, logger }) {
|
|
|
87854
88183
|
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.`);
|
|
87855
88184
|
return true;
|
|
87856
88185
|
}
|
|
88186
|
+
function warnAboutRemovedAutoReviewKeys({ value, logger }) {
|
|
88187
|
+
for (const key of CODEX_REMOVED_AUTO_REVIEW_KEYS) {
|
|
88188
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
88189
|
+
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.`);
|
|
88190
|
+
}
|
|
88191
|
+
}
|
|
87857
88192
|
function extractCodexcliOverride(table) {
|
|
87858
88193
|
const override = {};
|
|
87859
88194
|
for (const key of CODEXCLI_OVERRIDE_KEYS) if (table[key] !== void 0) override[key] = table[key];
|
|
@@ -89228,6 +89563,17 @@ const AUTO_APPROVE_KEYS = {
|
|
|
89228
89563
|
webfetch: "chat.tools.urls.autoApprove"
|
|
89229
89564
|
};
|
|
89230
89565
|
/**
|
|
89566
|
+
* VS Code registers `chat.tools.edits.autoApprove` with
|
|
89567
|
+
* `ConfigurationScope.APPLICATION` (user settings only) and ignores the value
|
|
89568
|
+
* in a workspace `.vscode/settings.json`, so canonical `edit` rules written
|
|
89569
|
+
* there have no effect. The terminal and URL maps are honored in the workspace
|
|
89570
|
+
* only by the Local harness, which VS Code removes in February 2027.
|
|
89571
|
+
*
|
|
89572
|
+
* @see https://github.com/microsoft/vscode/blob/1.147.0/src/vs/workbench/contrib/chat/browser/chat.shared.contribution.ts
|
|
89573
|
+
* @see https://code.visualstudio.com/docs/agents/run/approvals
|
|
89574
|
+
*/
|
|
89575
|
+
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.";
|
|
89576
|
+
/**
|
|
89231
89577
|
* The workspace setting holding the starting permission level of new Local
|
|
89232
89578
|
* (`local` harness) chat sessions, authored through the
|
|
89233
89579
|
* `copilot.defaultPermissionMode` override. VS Code 1.144 narrowed it to Local
|
|
@@ -89385,6 +89731,10 @@ const SANDBOX_LEAVES = [
|
|
|
89385
89731
|
path: ["credentials", "authenticategh"],
|
|
89386
89732
|
schema: z.boolean()
|
|
89387
89733
|
},
|
|
89734
|
+
{
|
|
89735
|
+
path: ["credentials", "envVars"],
|
|
89736
|
+
schema: CopilotSandboxCredentialEnvVarsSchema
|
|
89737
|
+
},
|
|
89388
89738
|
{
|
|
89389
89739
|
path: ["fileSystem", "allowDevToolAccess"],
|
|
89390
89740
|
schema: z.boolean()
|
|
@@ -89444,6 +89794,11 @@ const COPILOT_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
89444
89794
|
reason: "hands your GitHub CLI authentication to sandboxed commands",
|
|
89445
89795
|
widens: isNotFalse
|
|
89446
89796
|
},
|
|
89797
|
+
{
|
|
89798
|
+
path: ["credentials", "envVars"],
|
|
89799
|
+
reason: "lets the sandbox send the named environment variables' values to the listed hosts",
|
|
89800
|
+
widens: isNonEmptyMap
|
|
89801
|
+
},
|
|
89447
89802
|
{
|
|
89448
89803
|
path: ["fileSystem", "allowDevToolAccess"],
|
|
89449
89804
|
reason: "grants sandboxed commands developer-tool directories, which can hold credentials such as registry tokens",
|
|
@@ -89469,6 +89824,27 @@ const COPILOT_TRUST_AFFECTING_SANDBOX_PATHS = [
|
|
|
89469
89824
|
}
|
|
89470
89825
|
];
|
|
89471
89826
|
const COPILOT_TOOL_LABEL = "GitHub Copilot";
|
|
89827
|
+
/** The trust-warning label of the `credentials.envVars` leaf. */
|
|
89828
|
+
const ENV_VARS_LABEL = "sandbox.credentials.envVars";
|
|
89829
|
+
/**
|
|
89830
|
+
* Every `VAR -> host, host` pair of a `credentials.envVars` map, so a
|
|
89831
|
+
* developer generating from a cloned repository can spot an unexpected host
|
|
89832
|
+
* without opening the file. Names and hosts are JSON-quoted so control
|
|
89833
|
+
* characters in authored values cannot forge log lines.
|
|
89834
|
+
*/
|
|
89835
|
+
function describeEnvVars(envVars) {
|
|
89836
|
+
return Object.entries(envVars).map(([name, { injectHosts }]) => `${JSON.stringify(name)} -> ${injectHosts.length > 0 ? injectHosts.map((host) => JSON.stringify(host)).join(", ") : "(no hosts)"}`).join("; ");
|
|
89837
|
+
}
|
|
89838
|
+
/**
|
|
89839
|
+
* A separate, stronger warning for `injectHosts` entries containing `*`: the
|
|
89840
|
+
* sandbox may then send the credential to any host the pattern matches.
|
|
89841
|
+
*/
|
|
89842
|
+
function warnOnWildcardInjectHosts({ envVars, relativeFilePath, logger }) {
|
|
89843
|
+
if (envVars === void 0) return;
|
|
89844
|
+
const wildcards = Object.entries(envVars).flatMap(([name, { injectHosts }]) => injectHosts.filter((host) => host.includes("*")).map((host) => `${JSON.stringify(name)} -> ${JSON.stringify(host)}`));
|
|
89845
|
+
if (wildcards.length === 0) return;
|
|
89846
|
+
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.`);
|
|
89847
|
+
}
|
|
89472
89848
|
function sandboxKey(path) {
|
|
89473
89849
|
return `${SANDBOX_KEY_PREFIX}${path.join(".")}`;
|
|
89474
89850
|
}
|
|
@@ -89661,14 +90037,16 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
89661
90037
|
const patch = {};
|
|
89662
90038
|
for (const [category, settingKey] of Object.entries(AUTO_APPROVE_KEYS)) {
|
|
89663
90039
|
if (!Object.hasOwn(config.permission, category)) continue;
|
|
90040
|
+
const rules = category === "bash" ? bashRulesHonoringAllTools(config.permission) : honorCopilotAllToolsRestrictions({
|
|
90041
|
+
permission: config.permission,
|
|
90042
|
+
category,
|
|
90043
|
+
logger
|
|
90044
|
+
});
|
|
89664
90045
|
patch[settingKey] = buildAutoApproveValue({
|
|
89665
90046
|
category,
|
|
89666
|
-
rules
|
|
89667
|
-
permission: config.permission,
|
|
89668
|
-
category,
|
|
89669
|
-
logger
|
|
89670
|
-
})
|
|
90047
|
+
rules
|
|
89671
90048
|
});
|
|
90049
|
+
if (category === "edit" && Object.keys(rules).length > 0) logger?.warn(EDITS_KEY_IGNORED_WARNING);
|
|
89672
90050
|
}
|
|
89673
90051
|
const existingSettings = () => parseSharedConfig({
|
|
89674
90052
|
format: "jsonc",
|
|
@@ -89689,13 +90067,23 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
89689
90067
|
sandbox,
|
|
89690
90068
|
existingSettings: existingSettings()
|
|
89691
90069
|
}));
|
|
90070
|
+
const relativeFilePath = join(paths.relativeDirPath, paths.relativeFilePath);
|
|
90071
|
+
const envVars = sandbox.credentials?.envVars;
|
|
89692
90072
|
warnOnTrustAffectingEntries({
|
|
89693
90073
|
toolLabel: COPILOT_TOOL_LABEL,
|
|
89694
90074
|
entries: collectTrustAffectingSandboxPaths({
|
|
89695
90075
|
sandbox,
|
|
89696
90076
|
paths: COPILOT_TRUST_AFFECTING_SANDBOX_PATHS
|
|
89697
|
-
})
|
|
89698
|
-
|
|
90077
|
+
}).map((entry) => entry.label === ENV_VARS_LABEL && envVars !== void 0 ? {
|
|
90078
|
+
...entry,
|
|
90079
|
+
reason: `${entry.reason}: ${describeEnvVars(envVars)}`
|
|
90080
|
+
} : entry),
|
|
90081
|
+
relativeFilePath,
|
|
90082
|
+
logger
|
|
90083
|
+
});
|
|
90084
|
+
warnOnWildcardInjectHosts({
|
|
90085
|
+
envVars,
|
|
90086
|
+
relativeFilePath,
|
|
89699
90087
|
logger
|
|
89700
90088
|
});
|
|
89701
90089
|
}
|
|
@@ -92583,7 +92971,7 @@ function convertGoosePermissionConfigToRulesync(userPermission) {
|
|
|
92583
92971
|
const GROKCLI_UI_KEY = "ui";
|
|
92584
92972
|
const GROKCLI_PERMISSION_MODE_KEY = "permission_mode";
|
|
92585
92973
|
const GROKCLI_PERMISSION_KEY = "permission";
|
|
92586
|
-
const
|
|
92974
|
+
const GROKCLI_DERIVED_PERMISSION_MODES = /* @__PURE__ */ new Set(["ask", "always-approve"]);
|
|
92587
92975
|
const CATEGORY_TO_GROK_TOOL = {
|
|
92588
92976
|
bash: "Bash",
|
|
92589
92977
|
read: "Read",
|
|
@@ -92810,12 +93198,15 @@ function parseGrokRule(rule) {
|
|
|
92810
93198
|
* compact arrays, so a user-authored `rules` array is preserved verbatim
|
|
92811
93199
|
* but not reconciled against them.
|
|
92812
93200
|
*
|
|
92813
|
-
* The coarse `[ui] permission_mode` toggle is
|
|
92814
|
-
* compatibility with older Grok versions
|
|
92815
|
-
*
|
|
93201
|
+
* The coarse `[ui] permission_mode` toggle is kept in sync for backward
|
|
93202
|
+
* compatibility with older Grok versions, but only when the config already
|
|
93203
|
+
* sets it to `ask` or `always-approve`: `always-approve` only when the config
|
|
93204
|
+
* has the all-tools catch-all allow (`"*": { "*": "allow" }`) and no
|
|
93205
|
+
* `deny`/`ask` rule, otherwise `ask` (conservative — it is never `always-approve`
|
|
92816
93206
|
* while any `deny`/`ask` rule exists, so it never contradicts the fine-grained
|
|
92817
|
-
* arrays).
|
|
92818
|
-
* (see
|
|
93207
|
+
* arrays). A missing key is not added, so Grok's own default mode applies. It
|
|
93208
|
+
* is a user-level UI setting, so it is only touched in global scope (see
|
|
93209
|
+
* below).
|
|
92819
93210
|
*
|
|
92820
93211
|
* Both scopes are supported: the adapter syncs the project-level
|
|
92821
93212
|
* `./.grok/config.toml` (default) and the user-level `~/.grok/config.toml`
|
|
@@ -92876,7 +93267,7 @@ var GrokcliPermissions = class GrokcliPermissions extends ToolPermissions {
|
|
|
92876
93267
|
ask: buckets.ask
|
|
92877
93268
|
};
|
|
92878
93269
|
const existingUi = toRecord(parsed[GROKCLI_UI_KEY]);
|
|
92879
|
-
const uiPatch = global && existingUi[GROKCLI_PERMISSION_MODE_KEY]
|
|
93270
|
+
const uiPatch = global && GROKCLI_DERIVED_PERMISSION_MODES.has(existingUi[GROKCLI_PERMISSION_MODE_KEY]) ? { [GROKCLI_UI_KEY]: {
|
|
92880
93271
|
...existingUi,
|
|
92881
93272
|
[GROKCLI_PERMISSION_MODE_KEY]: deriveGrokPermissionMode(config)
|
|
92882
93273
|
} } : {};
|
|
@@ -93057,22 +93448,30 @@ function parseGrokPermissionArrays(permission) {
|
|
|
93057
93448
|
/**
|
|
93058
93449
|
* Legacy coarse fallback: map `[ui] permission_mode` to a canonical action.
|
|
93059
93450
|
* `always-approve` ⇒ `allow`; anything else (including a missing mode) ⇒ `ask`.
|
|
93451
|
+
* A missing mode now means Grok's own default (`auto` in the TUI since 1.0.80),
|
|
93452
|
+
* which has no canonical counterpart, so the narrower `ask` reading is kept.
|
|
93060
93453
|
*/
|
|
93061
93454
|
function legacyModeAction(parsed) {
|
|
93062
93455
|
return toRecord(parsed[GROKCLI_UI_KEY])[GROKCLI_PERMISSION_MODE_KEY] === "always-approve" ? "allow" : "ask";
|
|
93063
93456
|
}
|
|
93064
93457
|
/**
|
|
93065
93458
|
* Collapse a rulesync permissions config into Grok's single coarse mode.
|
|
93066
|
-
*
|
|
93067
|
-
*
|
|
93459
|
+
* `always-approve` lets every tool run without a prompt, so it is derived only
|
|
93460
|
+
* from a true catch-all allow — the all-tools rule `"*": { "*": "allow" }` —
|
|
93461
|
+
* with no `deny`/`ask` rule anywhere. Narrow allows (e.g. `bash: { "git *":
|
|
93462
|
+
* "allow" }`, or even `bash: { "*": "allow" }`) never widen into it; they and
|
|
93463
|
+
* an empty config map to `ask`.
|
|
93068
93464
|
*/
|
|
93069
93465
|
function deriveGrokPermissionMode(config) {
|
|
93070
|
-
|
|
93071
|
-
|
|
93072
|
-
|
|
93073
|
-
|
|
93074
|
-
}
|
|
93075
|
-
return
|
|
93466
|
+
for (const rules of Object.values(config.permission)) for (const action of Object.values(rules)) if (action === "deny" || action === "ask") return "ask";
|
|
93467
|
+
const allTools = lookupOwn({
|
|
93468
|
+
record: config.permission,
|
|
93469
|
+
key: "*"
|
|
93470
|
+
});
|
|
93471
|
+
return allTools !== void 0 && lookupOwn({
|
|
93472
|
+
record: allTools,
|
|
93473
|
+
key: "*"
|
|
93474
|
+
}) === "allow" ? "always-approve" : "ask";
|
|
93076
93475
|
}
|
|
93077
93476
|
// src/features/permissions/hermesagent-permissions.ts
|
|
93078
93477
|
/** Collect the glob patterns in a canonical category that carry a given action. */
|
|
@@ -94375,13 +94774,71 @@ function canonicalToKimiCodeRules({ config, logger }) {
|
|
|
94375
94774
|
});
|
|
94376
94775
|
}
|
|
94377
94776
|
}
|
|
94378
|
-
|
|
94777
|
+
const rules = [...overrideRules, ...sortKimiCodeRulesFailClosed(canonicalRules)];
|
|
94778
|
+
warnAboutIgnoredKimiCodeRuleScopes({
|
|
94779
|
+
rules: overrideRules,
|
|
94780
|
+
logger
|
|
94781
|
+
});
|
|
94782
|
+
warnAboutShadowedKimiCodeRules({
|
|
94783
|
+
rules,
|
|
94784
|
+
logger
|
|
94785
|
+
});
|
|
94786
|
+
return rules;
|
|
94379
94787
|
}
|
|
94380
|
-
|
|
94788
|
+
/**
|
|
94789
|
+
* Scopes Kimi silently ignores on a rule in the user `config.toml`.
|
|
94790
|
+
*
|
|
94791
|
+
* @see https://moonshotai.github.io/kimi-code/en/configuration/config-files.html#permission
|
|
94792
|
+
*/
|
|
94793
|
+
const KIMI_CODE_IGNORED_USER_RULE_SCOPES = /* @__PURE__ */ new Set(["turn-override", "session-runtime"]);
|
|
94794
|
+
function warnAboutIgnoredKimiCodeRuleScopes({ rules, logger }) {
|
|
94795
|
+
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.`);
|
|
94796
|
+
}
|
|
94797
|
+
/** Split a Kimi rule pattern (`Tool` or `Tool(arg)`) into its tool and argument. */
|
|
94798
|
+
function splitKimiCodePattern(pattern) {
|
|
94381
94799
|
const opening = pattern.indexOf("(");
|
|
94382
94800
|
const hasArguments = opening >= 0 && pattern.endsWith(")");
|
|
94383
|
-
|
|
94384
|
-
|
|
94801
|
+
return {
|
|
94802
|
+
tool: hasArguments ? pattern.slice(0, opening) : pattern,
|
|
94803
|
+
argument: hasArguments ? pattern.slice(opening + 1, -1) : "",
|
|
94804
|
+
hasArguments
|
|
94805
|
+
};
|
|
94806
|
+
}
|
|
94807
|
+
/**
|
|
94808
|
+
* Whether `stricter` certainly matches every call `rule` matches: the same
|
|
94809
|
+
* pattern, or the bare name of the same tool (which matches every call of
|
|
94810
|
+
* it). Wildcard overlaps are not detected, so this never reports a false
|
|
94811
|
+
* shadow but can miss one.
|
|
94812
|
+
*/
|
|
94813
|
+
function kimiCodeRuleCovers({ stricter, rule }) {
|
|
94814
|
+
return stricter.pattern === rule.pattern || stricter.pattern === splitKimiCodePattern(rule.pattern).tool;
|
|
94815
|
+
}
|
|
94816
|
+
/**
|
|
94817
|
+
* Kimi does not let the first matching rule win: a matching `deny` beats a
|
|
94818
|
+
* matching `ask`, which beats a matching `allow` (Kimi Code 2.6.0 docs). An
|
|
94819
|
+
* `allow` or `ask` meant to carve an exception out of a broader, stricter
|
|
94820
|
+
* rule therefore never takes effect, whether it comes from `kimi-code.rules`
|
|
94821
|
+
* or from a canonical category, so say so instead of letting the authored
|
|
94822
|
+
* order suggest otherwise. A rule whose own scope Kimi ignores already got
|
|
94823
|
+
* its warning and is skipped here.
|
|
94824
|
+
*
|
|
94825
|
+
* @see https://moonshotai.github.io/kimi-code/en/configuration/config-files.html#permission
|
|
94826
|
+
*/
|
|
94827
|
+
function warnAboutShadowedKimiCodeRules({ rules, logger }) {
|
|
94828
|
+
for (const rule of rules) {
|
|
94829
|
+
if (rule.decision === "deny" || KIMI_CODE_IGNORED_USER_RULE_SCOPES.has(rule.scope ?? "")) continue;
|
|
94830
|
+
const shadowing = rules.find((other) => isStricterAction({
|
|
94831
|
+
action: other.decision,
|
|
94832
|
+
existing: rule.decision
|
|
94833
|
+
}) && !KIMI_CODE_IGNORED_USER_RULE_SCOPES.has(other.scope ?? "") && kimiCodeRuleCovers({
|
|
94834
|
+
stricter: other,
|
|
94835
|
+
rule
|
|
94836
|
+
}));
|
|
94837
|
+
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.`);
|
|
94838
|
+
}
|
|
94839
|
+
}
|
|
94840
|
+
function getKimiCodePatternSpecificity(pattern) {
|
|
94841
|
+
const { tool, argument, hasArguments } = splitKimiCodePattern(pattern);
|
|
94385
94842
|
return {
|
|
94386
94843
|
tool,
|
|
94387
94844
|
toolLiteralLength: tool.replaceAll("*", "").replaceAll("?", "").length,
|
|
@@ -100447,6 +100904,14 @@ const TAKT_SECURITY_POLICIES = {
|
|
|
100447
100904
|
const TAKT_SECURITY_POLICY_KEYS = Object.keys(TAKT_SECURITY_POLICIES);
|
|
100448
100905
|
const TAKT_DEFAULT_PROVIDER = "claude-sdk";
|
|
100449
100906
|
const TAKT_LEGACY_DEFAULT_PROVIDER = "claude";
|
|
100907
|
+
const TAKT_CLAUDE_READ_DENY_PROVIDERS = [
|
|
100908
|
+
"claude-sdk",
|
|
100909
|
+
"claude",
|
|
100910
|
+
"claude-headless"
|
|
100911
|
+
];
|
|
100912
|
+
const TAKT_CLAUDE_PROVIDER_OPTIONS_KEY = "claude";
|
|
100913
|
+
const TAKT_CLAUDE_PERMISSIONS_KEY = "permissions";
|
|
100914
|
+
const TAKT_CLAUDE_PERMISSIONS_DENY_KEY = "deny";
|
|
100450
100915
|
/**
|
|
100451
100916
|
* Permissions adapter for Takt (`.takt/config.yaml`).
|
|
100452
100917
|
*
|
|
@@ -100485,6 +100950,12 @@ const TAKT_LEGACY_DEFAULT_PROVIDER = "claude";
|
|
|
100485
100950
|
* (a top-level per-provider sandbox/network table). Both are authored on
|
|
100486
100951
|
* generate and re-extracted on import.
|
|
100487
100952
|
*
|
|
100953
|
+
* Canonical `read` deny rules are also kept per path where the active provider
|
|
100954
|
+
* is Claude-family (Takt 0.76.0+): they are written as `Read(<pattern>)`
|
|
100955
|
+
* entries into `provider_options.claude.permissions.deny`, in addition to the
|
|
100956
|
+
* `readonly` mode they already derive. The list is only ever added to, so a
|
|
100957
|
+
* deny never turns into a broader allow.
|
|
100958
|
+
*
|
|
100488
100959
|
* Takt 0.56.0 moved provider configuration into a separate `runtime.yaml`
|
|
100489
100960
|
* (`.takt/runtime.yaml`, `~/.takt/runtime.yaml`). Once its `provider:` section
|
|
100490
100961
|
* carries an assignment ("runtime mode" — the state a freshly installed Takt is
|
|
@@ -100549,7 +101020,8 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100549
101020
|
outputRoot,
|
|
100550
101021
|
logger
|
|
100551
101022
|
});
|
|
100552
|
-
const
|
|
101023
|
+
const globalLayer = await readGlobalTaktLayer({
|
|
101024
|
+
global,
|
|
100553
101025
|
projectFilePath: filePath,
|
|
100554
101026
|
logger
|
|
100555
101027
|
});
|
|
@@ -100557,7 +101029,7 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100557
101029
|
const provider = resolveActiveProvider({
|
|
100558
101030
|
config,
|
|
100559
101031
|
runtime: runtime.active ? runtime.config : void 0,
|
|
100560
|
-
inheritedProvider
|
|
101032
|
+
inheritedProvider: globalLayer.provider
|
|
100561
101033
|
});
|
|
100562
101034
|
const mode = deriveTaktPermissionMode(rulesyncJson);
|
|
100563
101035
|
const override = isPlainObject(rulesyncJson.takt) ? rulesyncJson.takt : void 0;
|
|
@@ -100565,9 +101037,20 @@ var TaktPermissions = class TaktPermissions extends ToolPermissions {
|
|
|
100565
101037
|
const authoredProviderOptions = isPlainObject(override?.[TAKT_PROVIDER_OPTIONS_KEY]) ? override[TAKT_PROVIDER_OPTIONS_KEY] : void 0;
|
|
100566
101038
|
const runtimeModeRefusesProviderOptions = authoredProviderOptions !== void 0 && runtime.active;
|
|
100567
101039
|
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.`);
|
|
100568
|
-
const overrideProviderOptions =
|
|
100569
|
-
providerOptions:
|
|
100570
|
-
|
|
101040
|
+
const overrideProviderOptions = addClaudeReadDenyRules({
|
|
101041
|
+
providerOptions: runtimeModeRefusesProviderOptions ? void 0 : dropUntrustedProviderOptions({
|
|
101042
|
+
providerOptions: authoredProviderOptions,
|
|
101043
|
+
global,
|
|
101044
|
+
filePath,
|
|
101045
|
+
logger
|
|
101046
|
+
}),
|
|
101047
|
+
readDenyRules: collectReadDenyRules(rulesyncJson),
|
|
101048
|
+
existingProviderOptions: config[TAKT_PROVIDER_OPTIONS_KEY],
|
|
101049
|
+
globalProviderOptions: globalLayer.providerOptions,
|
|
101050
|
+
globalFilePath: globalLayer.filePath,
|
|
101051
|
+
provider,
|
|
101052
|
+
runtimeActive: runtime.active,
|
|
101053
|
+
runtimeFilePaths: runtime.filePaths,
|
|
100571
101054
|
filePath,
|
|
100572
101055
|
logger
|
|
100573
101056
|
});
|
|
@@ -100680,11 +101163,34 @@ function readProviderName(config) {
|
|
|
100680
101163
|
return typeof provider === "string" && provider.trim() !== "" ? provider : void 0;
|
|
100681
101164
|
}
|
|
100682
101165
|
/**
|
|
100683
|
-
*
|
|
100684
|
-
*
|
|
100685
|
-
*
|
|
101166
|
+
* What a project-scope generate inherits from the global `~/.takt/config.yaml`:
|
|
101167
|
+
* its provider and its `provider_options`. Nothing at global scope, where that
|
|
101168
|
+
* file is the one being generated.
|
|
101169
|
+
*/
|
|
101170
|
+
async function readGlobalTaktLayer({ global, projectFilePath, logger }) {
|
|
101171
|
+
const globalConfig = global ? void 0 : await readGlobalTaktConfig({
|
|
101172
|
+
projectFilePath,
|
|
101173
|
+
logger
|
|
101174
|
+
});
|
|
101175
|
+
if (globalConfig === void 0) return {
|
|
101176
|
+
provider: void 0,
|
|
101177
|
+
providerOptions: void 0,
|
|
101178
|
+
filePath: void 0
|
|
101179
|
+
};
|
|
101180
|
+
return {
|
|
101181
|
+
provider: readProviderName(globalConfig.config),
|
|
101182
|
+
providerOptions: globalConfig.config[TAKT_PROVIDER_OPTIONS_KEY],
|
|
101183
|
+
filePath: globalConfig.filePath
|
|
101184
|
+
};
|
|
101185
|
+
}
|
|
101186
|
+
/**
|
|
101187
|
+
* The global `~/.takt/config.yaml`, read for a project-scope generate: its
|
|
101188
|
+
* top-level `provider:` is inherited by a project config that names none, and
|
|
101189
|
+
* its `provider_options.claude.permissions.deny` is the list a project list
|
|
101190
|
+
* would replace. An unresolvable home directory or a missing or unparsable file
|
|
101191
|
+
* all mean "nothing inherited".
|
|
100686
101192
|
*/
|
|
100687
|
-
async function
|
|
101193
|
+
async function readGlobalTaktConfig({ projectFilePath, logger }) {
|
|
100688
101194
|
let globalPath;
|
|
100689
101195
|
try {
|
|
100690
101196
|
globalPath = join(getHomeDirectory(), TAKT_DIR, TAKT_CONFIG_FILE_NAME);
|
|
@@ -100695,12 +101201,15 @@ async function readGlobalTaktProvider({ projectFilePath, logger }) {
|
|
|
100695
101201
|
try {
|
|
100696
101202
|
const content = await readFileContentOrNull(globalPath);
|
|
100697
101203
|
if (content === null) return;
|
|
100698
|
-
return
|
|
100699
|
-
format: "yaml",
|
|
100700
|
-
fileContent: content,
|
|
101204
|
+
return {
|
|
100701
101205
|
filePath: globalPath,
|
|
100702
|
-
|
|
100703
|
-
|
|
101206
|
+
config: parseSharedConfig({
|
|
101207
|
+
format: "yaml",
|
|
101208
|
+
fileContent: content,
|
|
101209
|
+
filePath: globalPath,
|
|
101210
|
+
invalidRootPolicy: "error"
|
|
101211
|
+
})
|
|
101212
|
+
};
|
|
100704
101213
|
} catch (error) {
|
|
100705
101214
|
logger?.warn(`Takt permissions: could not read the provider from ${globalPath} (${formatError(error)}); falling back to the project config alone.`);
|
|
100706
101215
|
return;
|
|
@@ -101063,6 +101572,70 @@ function taktModeToRulesyncConfig(mode) {
|
|
|
101063
101572
|
default: return { permission: { bash: { ["*"]: "deny" } } };
|
|
101064
101573
|
}
|
|
101065
101574
|
}
|
|
101575
|
+
/**
|
|
101576
|
+
* The canonical `read` deny rules as Claude Code `Read(...)` entries, in the
|
|
101577
|
+
* form the Claude Code permissions and ignore adapters write them: the pattern
|
|
101578
|
+
* verbatim, and a bare `Read` for the catch-all.
|
|
101579
|
+
*/
|
|
101580
|
+
function collectReadDenyRules(config) {
|
|
101581
|
+
const rules = config.permission.read ?? {};
|
|
101582
|
+
return Object.entries(rules).filter(([, action]) => action === "deny").map(([pattern]) => pattern === "*" ? "Read" : buildReadDenyEntry(pattern));
|
|
101583
|
+
}
|
|
101584
|
+
/**
|
|
101585
|
+
* Add the canonical `read` deny rules to `provider_options.claude.permissions.deny`
|
|
101586
|
+
* (Takt 0.76.0+), which Takt passes to `claude-sdk` / `claude-headless` as
|
|
101587
|
+
* Claude Code `permissions.deny` rules.
|
|
101588
|
+
*
|
|
101589
|
+
* Takt replaces a `deny` list wholesale rather than concatenating it, so the
|
|
101590
|
+
* rules are merged into the list that would otherwise be in force: the one the
|
|
101591
|
+
* `takt` block states (which replaces a hand-written config.yaml list, as any
|
|
101592
|
+
* authored `provider_options` leaf does), else the one already in config.yaml.
|
|
101593
|
+
* Without an authored list nothing is removed from config.yaml's — a rule
|
|
101594
|
+
* written by hand, or by an earlier generate, is kept.
|
|
101595
|
+
*
|
|
101596
|
+
* At project scope the written list also replaces a global `~/.takt/config.yaml`
|
|
101597
|
+
* deny list for this project. That list usually holds personal paths, so it is
|
|
101598
|
+
* not copied into the (committed) project file; a warning names it instead.
|
|
101599
|
+
*
|
|
101600
|
+
* Skipped when the active provider is not Claude-family (no other provider
|
|
101601
|
+
* reads the list) and, with a warning, in runtime mode, where `provider_options`
|
|
101602
|
+
* in config.yaml stops Takt with "Mixed provider configuration detected".
|
|
101603
|
+
* https://github.com/nrslib/takt/blob/main/docs/configuration.md#claude-read-deny-rules
|
|
101604
|
+
*/
|
|
101605
|
+
function addClaudeReadDenyRules({ providerOptions, readDenyRules, existingProviderOptions, globalProviderOptions, globalFilePath, provider, runtimeActive, runtimeFilePaths, filePath, logger }) {
|
|
101606
|
+
if (readDenyRules.length === 0 || !TAKT_CLAUDE_READ_DENY_PROVIDERS.includes(provider)) return providerOptions;
|
|
101607
|
+
if (runtimeActive) {
|
|
101608
|
+
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.`);
|
|
101609
|
+
return providerOptions;
|
|
101610
|
+
}
|
|
101611
|
+
const authoredClaude = providerOptions?.[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY];
|
|
101612
|
+
const authoredDeny = readClaudeDenyList(authoredClaude);
|
|
101613
|
+
const existingDeny = isPlainObject(existingProviderOptions) ? readClaudeDenyList(existingProviderOptions[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]) : void 0;
|
|
101614
|
+
const deny = [.../* @__PURE__ */ new Set([...authoredDeny ?? existingDeny ?? [], ...readDenyRules])];
|
|
101615
|
+
const shadowedGlobalDeny = ((isPlainObject(globalProviderOptions) ? readClaudeDenyList(globalProviderOptions[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]) : void 0) ?? []).filter((rule) => !deny.includes(rule));
|
|
101616
|
+
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.`);
|
|
101617
|
+
const claude = isPlainObject(authoredClaude) ? authoredClaude : {};
|
|
101618
|
+
const permissions = isPlainObject(claude[TAKT_CLAUDE_PERMISSIONS_KEY]) ? claude[TAKT_CLAUDE_PERMISSIONS_KEY] : {};
|
|
101619
|
+
return {
|
|
101620
|
+
...providerOptions,
|
|
101621
|
+
[TAKT_CLAUDE_PROVIDER_OPTIONS_KEY]: {
|
|
101622
|
+
...claude,
|
|
101623
|
+
[TAKT_CLAUDE_PERMISSIONS_KEY]: {
|
|
101624
|
+
...permissions,
|
|
101625
|
+
[TAKT_CLAUDE_PERMISSIONS_DENY_KEY]: deny
|
|
101626
|
+
}
|
|
101627
|
+
}
|
|
101628
|
+
};
|
|
101629
|
+
}
|
|
101630
|
+
/** The string entries of `<claude options>.permissions.deny`, when it is a list. */
|
|
101631
|
+
function readClaudeDenyList(claudeOptions) {
|
|
101632
|
+
if (!isPlainObject(claudeOptions)) return;
|
|
101633
|
+
const permissions = claudeOptions[TAKT_CLAUDE_PERMISSIONS_KEY];
|
|
101634
|
+
if (!isPlainObject(permissions)) return;
|
|
101635
|
+
const deny = permissions[TAKT_CLAUDE_PERMISSIONS_DENY_KEY];
|
|
101636
|
+
if (!Array.isArray(deny)) return;
|
|
101637
|
+
return deny.filter((entry) => typeof entry === "string" && entry !== "");
|
|
101638
|
+
}
|
|
101066
101639
|
const TAKT_BASE_URL_PROVIDERS = [
|
|
101067
101640
|
"codex",
|
|
101068
101641
|
"claude",
|
|
@@ -104087,6 +104660,32 @@ function buildZedToolPermissions({ permission, logger }) {
|
|
|
104087
104660
|
inertMcpCategories
|
|
104088
104661
|
};
|
|
104089
104662
|
}
|
|
104663
|
+
/**
|
|
104664
|
+
* Zed's file-edit tools whose `confirm` default does not prompt for files inside
|
|
104665
|
+
* the project.
|
|
104666
|
+
*/
|
|
104667
|
+
const ZED_IN_PROJECT_EDIT_TOOLS = ["edit_file", "write_file"];
|
|
104668
|
+
/**
|
|
104669
|
+
* Zed's `edit_file` and `write_file` skip the permission prompt for files inside
|
|
104670
|
+
* the project when the settings decision is `confirm`: only Zed settings
|
|
104671
|
+
* folders, `.agents/skills/` and paths a symlink places outside the project
|
|
104672
|
+
* still prompt (`authorize_file_edit` in `crates/agent/src/tools/tool_permissions.rs`,
|
|
104673
|
+
* documented under "File Edits Inside the Project" since zed-industries/zed#67037).
|
|
104674
|
+
* A canonical catch-all `ask` on `edit`/`write` — or an all-tools `*` ask those
|
|
104675
|
+
* tools fall back to — therefore lets the agent edit in-project files without
|
|
104676
|
+
* asking, so say so at generate time rather than implying a prompt.
|
|
104677
|
+
*
|
|
104678
|
+
* The check runs on the merged `tools` result: a tool whose entry is a
|
|
104679
|
+
* preserved, hand-written one (not managed by rulesync) is skipped, since its
|
|
104680
|
+
* decision is the user's own. Only the literal `.*` ask pattern counts as
|
|
104681
|
+
* "prompt for every file" and silences the warning; any narrower pattern still
|
|
104682
|
+
* leaves other in-project files unprompted, so the warning stays.
|
|
104683
|
+
*/
|
|
104684
|
+
function warnInProjectEditConfirm({ managedDefault, managedTools, preservedToolNames, logger }) {
|
|
104685
|
+
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 === ".*"));
|
|
104686
|
+
if (confirmTools.length === 0) return;
|
|
104687
|
+
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.`);
|
|
104688
|
+
}
|
|
104090
104689
|
function asRecord(value) {
|
|
104091
104690
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
|
|
104092
104691
|
return Object.fromEntries(Object.entries(value));
|
|
@@ -104232,6 +104831,12 @@ var ZedPermissions = class ZedPermissions extends ToolPermissions {
|
|
|
104232
104831
|
if ("*" in config.permission) managedToolNames.add("*");
|
|
104233
104832
|
for (const toolName of Object.keys(existingTools)) if (toolName.startsWith("mcp__")) managedToolNames.add(toolName);
|
|
104234
104833
|
const preservedTools = Object.fromEntries(Object.entries(existingTools).filter(([toolName]) => !managedToolNames.has(toolName)));
|
|
104834
|
+
warnInProjectEditConfirm({
|
|
104835
|
+
managedDefault,
|
|
104836
|
+
managedTools,
|
|
104837
|
+
preservedToolNames: new Set(Object.keys(preservedTools)),
|
|
104838
|
+
logger
|
|
104839
|
+
});
|
|
104235
104840
|
return new ZedPermissions({
|
|
104236
104841
|
outputRoot,
|
|
104237
104842
|
relativeDirPath: paths.relativeDirPath,
|
|
@@ -107389,4 +107994,4 @@ const CHECKS_IMPORT_STRATEGY = {
|
|
|
107389
107994
|
};
|
|
107390
107995
|
export { RulesyncRule as $, RULESYNC_RULES_RELATIVE_DIR_PATH as $n, getFileSizeAndExecutableBit as $t, CODEBUDDY_LOCAL_RULE_FILE_NAME as A, ToolTargetSchema as An, fallbackLogger as At, CLAUDECODE_LOCAL_RULE_FILE_NAME as B, RULESYNC_CONFIG_RELATIVE_FILE_PATH as Bn, assertDirectoryIfExists as Bt, LETTACODE_DIR as C, toPosixPath as Cn, SourceEntrySchema as Ct, COMMANDCODE_DIR as D, ALL_TOOL_TARGETS as Dn, ConsoleLogger as Dt, FACTORYDROID_SETTINGS_LOCAL_FILE_NAME as E, mapWithConcurrency as En, findControlCharacter as Et, sweepRefusalReason as F, FEATURE_SOURCE_TREE_ENTRIES as Fn, CLIError as Ft, toInstructionBudgetFile as G, RULESYNC_IGNORE_RELATIVE_FILE_PATH as Gn, assertWritablePathInsideRoot as Gt, CLAUDECODE_SETTINGS_LOCAL_FILE_NAME as H, RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH as Hn, assertNoSymlinkBelowRoot as Ht, CODEXCLI_BASH_RULES_FILE_NAME as I, MAX_FILE_SIZE as In, ErrorCodes as It, getLocalSkillDirNames as J, RULESYNC_MCP_SCHEMA_URL as Jn, directoryExists as Jt, classifyRemoteName as K, RULESYNC_LOCAL_CONFIG_RELATIVE_FILE_PATH as Kn, checkPathTraversal as Kt, CODEXCLI_DIR as L, RULESYNC_AIIGNORE_RELATIVE_FILE_PATH as Ln, parseJsonc as Lt, AUGMENTCODE_SETTINGS_LOCAL_FILE_NAME as M, ALL_FEATURES_WITH_WILDCARD as Mn, withFallbackLoggerTarget as Mt, caseFoldIdentity as N, DEPRECATED_FEATURE_REPLACEMENTS as Nn, resetRunWarningState as Nt, COMMANDCODE_SETTINGS_LOCAL_FILE_NAME as O, ALL_TOOL_TARGETS_WITH_WILDCARD as On, JsonLogger as Ot, groupSpellingsByCaseFoldedIdentity as P, CURATED_RULES_FEATURE_SUBDIR as Pn, withWarnOnceScope as Pt, RulesyncSkillFrontmatterSchema as Q, RULESYNC_RELATIVE_DIR_PATH as Qn, findFilesByGlobs as Qt, CLAUDECODE_AGENT_MEMORY_LOCAL_DIR_NAME as R, RULESYNC_CHECKS_RELATIVE_DIR_PATH as Rn, PathOutsideRootError as Rt, QWENCODE_LOCAL_RULE_FILE_NAME as S, splitPathSegments as Sn, GITIGNORE_DESTINATION_KEY as St, FACTORYDROID_DIR as T, writeFileContent as Tn, getSourceTransport as Tt, CLAUDECODE_SKILLS_DIR_PATH as U, RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH as Un, assertPathResolvesInsideRoot as Ut, CLAUDECODE_MEMORIES_DIR_NAME as V, RULESYNC_CONFIG_SCHEMA_URL as Vn, assertLandingOutsideVcsMetadata as Vt, findProjectInstructionBudgetFindings as W, RULESYNC_HOOKS_RELATIVE_FILE_PATH as Wn, assertTreeContainsNoSymlinks as Wt, RulesyncSubagentFrontmatterSchema as X, RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH as Xn, fileExists as Xt, RulesyncSubagent as Y, RULESYNC_NPM_SOURCES_LOCK_RELATIVE_FILE_PATH as Yn, ensureDir as Yt, RulesyncSkill as Z, RULESYNC_PERMISSIONS_SCHEMA_URL as Zn, fileExistsStrict as Zt, SkillsProcessor as _, removeFileWithoutFollowingSymlinks as _n, mergeInputRootConfigs as _t, convertFromTool as a, listDirectoryEntryNames as an, formatMegabytes as ar, getRulesyncSourceCandidates as at, REASONIX_LOCAL_RULE_FILE_NAME as b, resolvedRelativePath as bn, CONFLICTING_TARGET_PAIRS as bt, ELLIPSIS_WIDTH as c, normalizePosixDirPath as cn, hasEnclosingMarkOutsideKeycap as cr, RulesyncCommandFrontmatterSchema as ct, McpProcessor as d, readFileContent as dn, stripControlCharactersKeepingLineFeeds as dr, stringifyFrontmatter as dt, getHomeDirectory as en, RULESYNC_SKILLS_RELATIVE_DIR_PATH as er, RulesyncRuleFrontmatterSchema as et, IgnoreProcessor as f, readFileContentOrNull as fn, stripControlCharactersKeepingLineFeedsAndTabs as fr, loadYaml as ft, SubagentsProcessor as g, removeFileStrict as gn, ConfigResolver as gt, RulesProcessor as h, removeFile as hn, SKILL_FILE_NAME as ht, inspectInputRoots as i, isSymlink as in, RULESYNC_XDG_CONFIG_HOME_DEFAULT_DIR_NAME as ir, RulesyncHooks as it, AUGMENTCODE_DIR as j, ALL_FEATURES as jn, warnOnConflictingFlags as jt, CODEBUDDY_DIR as k, PACKAGING_TOOL_TARGETS as kn, WarningCollectingLogger as kt, displayWidthOf as l, pathEscapesRoot as ln, quoteForLog as lr, RulesyncCheck as lt, ChecksProcessor as m, removeDirectoryStrict as mn, SHARED_USER_MANAGED_CONFIG_PATHS as mt, formatSourceLoadFailure as n, isFileSystemError as nn, RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH as nr, RulesyncMcp as nt, getProcessorRegistryEntry as o, listFilePathsRecursively as on, formatError as or, resolveRulesyncSourceWritePath as ot, HooksProcessor as p, removeDirectory as pn, stripHiddenCharacters as pr, isRecord as pt, hasWindowsFoldableName as q, RULESYNC_MCP_RELATIVE_FILE_PATH as qn, createTempDirectory as qt, generate as r, isRootDirPath as rn, RULESYNC_USER_CONFIG_DIR_NAME as rr, RulesyncIgnore as rt, parseCommaSeparatedList as s, listSubdirectoryNames as sn, truncateText as sr, RulesyncCommand as st, importFromTool as t, isFileNotFoundError as tn, RULESYNC_SOURCES_LOCK_RELATIVE_FILE_PATH as tr, RulesyncPermissions as tt, shortenToWidth as u, posixRelativePathEscapesRoot as un, stripControlCharacters as ur, RulesyncCheckFrontmatterSchema as ut, CRUSH_LOCAL_RULE_FILE_NAME as v, removeTempDirectory as vn, parseConfigFileContent as vt, LETTACODE_SETTINGS_LOCAL_FILE_NAME as w, writeFileBuffer as wn, assertTargetsFeaturesExclusive as wt, QWENCODE_DIR as x, runWithDirectoryRollback as xn, ConfigFileSchema as xt, CommandsProcessor as y, resolvePath as yn, resolveEffectiveInputRoots as yt, CLAUDECODE_DIR as z, RULESYNC_COMMANDS_RELATIVE_DIR_PATH as zn, applyFileMode as zt };
|
|
107391
107996
|
|
|
107392
|
-
//# sourceMappingURL=import-
|
|
107997
|
+
//# sourceMappingURL=import-Ctgal4jT.js.map
|