@koalaauto/agentchannel 3.45.0 → 3.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -22,6 +22,17 @@ export declare const MENTION_GIT_TOOLS: string[];
|
|
|
22
22
|
* run (`--ext-diff`, `-c`, `--exec`), and nothing before `git` (an environment variable can name a program too).
|
|
23
23
|
*/
|
|
24
24
|
export declare function mentionGitDenied(command: string): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a command is one plain `ach <sub> ...` call of an allowed subcommand: literal words only. Claude Code's own rule
|
|
27
|
+
* (`Bash(ach reply:*)`) gives up on a long quoted argument with `;` or a line break in it and asks, which a run that cannot ask
|
|
28
|
+
* reads as a refusal (2026-11-17: two replies with evidence were lost that way). Quoted text is literal here: nothing a shell
|
|
29
|
+
* would expand (`$`, a backtick), chain, redirect or glob outside quotes, and nothing before `ach`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function plainAchCommand(command: string, subs: string[]): boolean;
|
|
32
|
+
/** The subcommands of a list like `Bash(ach reply:*)`. */
|
|
33
|
+
export declare const achSubcommands: (tools: string[]) => string[];
|
|
34
|
+
/** PreToolUse for Bash: a plain call of one of the run's `ach` commands is allowed outright (see plainAchCommand). */
|
|
35
|
+
export declare function achCommandHook(tools: string[]): HookCallbackMatcher;
|
|
25
36
|
/** PreToolUse for a mention run's Bash: the git rules above (a hook runs for pre-approved commands too). */
|
|
26
37
|
export declare function mentionGitHook(): HookCallbackMatcher;
|
|
27
38
|
/** canUseTool for workdir: path policy (reads under $HOME, writes outside cwd) plus the Bash deny list. */
|
|
@@ -2,7 +2,7 @@ import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
|
2
2
|
import { homedir, tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { CAPS_SERVER } from '../caps.js';
|
|
5
|
-
import { toolDenied } from './paths.js';
|
|
5
|
+
import { isSessionToolResult, READ_TOOLS, toolDenied, toolPaths } from './paths.js';
|
|
6
6
|
import { macTempPatterns, readable, systemPaths } from './scope.js';
|
|
7
7
|
import { spawnGroup } from './procgroup.js';
|
|
8
8
|
import { modelId } from './types.js';
|
|
@@ -66,6 +66,62 @@ export function mentionGitDenied(command) {
|
|
|
66
66
|
return `this run reads the repository's history only: no ${args.find((a) => /^--(ext-diff|exec|no-index|textconv)\b/.test(a))}`;
|
|
67
67
|
return undefined;
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether a command is one plain `ach <sub> ...` call of an allowed subcommand: literal words only. Claude Code's own rule
|
|
71
|
+
* (`Bash(ach reply:*)`) gives up on a long quoted argument with `;` or a line break in it and asks, which a run that cannot ask
|
|
72
|
+
* reads as a refusal (2026-11-17: two replies with evidence were lost that way). Quoted text is literal here: nothing a shell
|
|
73
|
+
* would expand (`$`, a backtick), chain, redirect or glob outside quotes, and nothing before `ach`.
|
|
74
|
+
*/
|
|
75
|
+
export function plainAchCommand(command, subs) {
|
|
76
|
+
const cmd = command.trim();
|
|
77
|
+
const m = /^ach\s+([a-z][a-z-]*)(\s|$)/.exec(cmd);
|
|
78
|
+
if (!m || !subs.includes(m[1]))
|
|
79
|
+
return false;
|
|
80
|
+
let q = '';
|
|
81
|
+
for (let i = 0; i < cmd.length; i++) {
|
|
82
|
+
const ch = cmd[i];
|
|
83
|
+
if (q === "'") {
|
|
84
|
+
if (ch === "'")
|
|
85
|
+
q = '';
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (q === '"') {
|
|
89
|
+
if (ch === '\\') {
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (ch === '"')
|
|
94
|
+
q = '';
|
|
95
|
+
else if (ch === '$' || ch === '`')
|
|
96
|
+
return false;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (ch === "'" || ch === '"') {
|
|
100
|
+
q = ch;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (/[;&|<>(){}$`\\\n\r*?[\]~!]/.test(ch))
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return q === '';
|
|
107
|
+
}
|
|
108
|
+
/** The subcommands of a list like `Bash(ach reply:*)`. */
|
|
109
|
+
export const achSubcommands = (tools) => tools.map((t) => /^Bash\(ach ([a-z-]+):\*\)$/.exec(t)?.[1]).filter((s) => !!s);
|
|
110
|
+
/** PreToolUse for Bash: a plain call of one of the run's `ach` commands is allowed outright (see plainAchCommand). */
|
|
111
|
+
export function achCommandHook(tools) {
|
|
112
|
+
const subs = achSubcommands(tools);
|
|
113
|
+
return {
|
|
114
|
+
hooks: [
|
|
115
|
+
async (input) => {
|
|
116
|
+
if (input.hook_event_name !== 'PreToolUse' || input.tool_name !== 'Bash')
|
|
117
|
+
return {};
|
|
118
|
+
if (!plainAchCommand(String((input.tool_input ?? {}).command ?? ''), subs))
|
|
119
|
+
return {};
|
|
120
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'allow' } };
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
69
125
|
/** PreToolUse for a mention run's Bash: the git rules above (a hook runs for pre-approved commands too). */
|
|
70
126
|
export function mentionGitHook() {
|
|
71
127
|
return {
|
|
@@ -106,7 +162,15 @@ export function pathPolicyHook(pol) {
|
|
|
106
162
|
async (input) => {
|
|
107
163
|
if (input.hook_event_name !== 'PreToolUse')
|
|
108
164
|
return {};
|
|
109
|
-
const
|
|
165
|
+
const args = (input.tool_input ?? {});
|
|
166
|
+
// what Claude Code saved for this session (a long tool result) is the run's own: readable, whatever the roots say
|
|
167
|
+
if (READ_TOOLS.has(input.tool_name)) {
|
|
168
|
+
const paths = toolPaths(input.tool_name, args);
|
|
169
|
+
if (paths.length && paths.every((p) => isSessionToolResult(pol.cwd, p, String(input.session_id ?? '')))) {
|
|
170
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'allow' } };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const why = toolDenied(pol, input.tool_name, args);
|
|
110
174
|
if (!why)
|
|
111
175
|
return {};
|
|
112
176
|
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: why } };
|
|
@@ -198,7 +262,7 @@ export function claudePermOptions(perm, o) {
|
|
|
198
262
|
// test). The PreToolUse hook checks them; the SDK's notice that canUseTool is shadowed for them is expected.
|
|
199
263
|
allowedTools: ['Read', 'Glob', 'Grep', ...achTools, ...(o.mode === 'mention' ? MENTION_GIT_TOOLS : [])],
|
|
200
264
|
sandbox,
|
|
201
|
-
hooks: { PreToolUse: [pathPolicyHook(pol), ...(o.mode === 'mention' ? [mentionGitHook()] : [])] },
|
|
265
|
+
hooks: { PreToolUse: [pathPolicyHook(pol), achCommandHook(achTools), ...(o.mode === 'mention' ? [mentionGitHook()] : [])] },
|
|
202
266
|
};
|
|
203
267
|
if (perm === 'read')
|
|
204
268
|
return { ...common, permissionMode: 'dontAsk' };
|
|
@@ -44,6 +44,12 @@ export declare const READ_TOOLS: Set<string>;
|
|
|
44
44
|
export declare const WRITE_TOOLS: Set<string>;
|
|
45
45
|
/** File paths a tool call touches (relative paths are resolved against cwd by the policy). */
|
|
46
46
|
export declare function toolPaths(toolName: string, input: Record<string, unknown>): string[];
|
|
47
|
+
/**
|
|
48
|
+
* A file Claude Code wrote for this very session: a tool result too long for the conversation is saved under
|
|
49
|
+
* `~/.claude/projects/<project>/<session>/tool-results/` and the agent is told to read it from there. Only this session's: the
|
|
50
|
+
* same folder holds the owner's other sessions.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isSessionToolResult(cwd: string, p: string, sessionId: string): boolean;
|
|
47
53
|
/** Deny reason for a tool call under the policy, or undefined to allow. */
|
|
48
54
|
export declare function toolDenied(pol: PathPolicy, toolName: string, input: Record<string, unknown>): string | undefined;
|
|
49
55
|
export declare function existing(paths: string[]): string[];
|
|
@@ -116,6 +116,18 @@ export function toolPaths(toolName, input) {
|
|
|
116
116
|
out.push('.');
|
|
117
117
|
return out;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* A file Claude Code wrote for this very session: a tool result too long for the conversation is saved under
|
|
121
|
+
* `~/.claude/projects/<project>/<session>/tool-results/` and the agent is told to read it from there. Only this session's: the
|
|
122
|
+
* same folder holds the owner's other sessions.
|
|
123
|
+
*/
|
|
124
|
+
export function isSessionToolResult(cwd, p, sessionId) {
|
|
125
|
+
if (!/^[A-Za-z0-9-]{8,64}$/.test(sessionId))
|
|
126
|
+
return false;
|
|
127
|
+
const parts = realish(resolve(cwd, p)).split(/[\\/]+/);
|
|
128
|
+
const i = parts.lastIndexOf('tool-results');
|
|
129
|
+
return i >= 4 && i < parts.length - 1 && parts[i - 1] === sessionId && parts[i - 3] === 'projects' && parts[i - 4] === '.claude' && !parts.slice(i).includes('..');
|
|
130
|
+
}
|
|
119
131
|
/** Deny reason for a tool call under the policy, or undefined to allow. */
|
|
120
132
|
export function toolDenied(pol, toolName, input) {
|
|
121
133
|
const write = WRITE_TOOLS.has(toolName);
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.45.
|
|
3
|
+
"version": "3.45.1",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|