@koalaauto/agentchannel 3.44.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.
- package/dist/src/adapters/claude.d.ts +11 -0
- package/dist/src/adapters/claude.js +67 -3
- package/dist/src/adapters/paths.d.ts +6 -0
- package/dist/src/adapters/paths.js +12 -0
- package/dist/src/client.d.ts +4 -2
- package/dist/src/client.js +1 -1
- package/dist/src/doctor.js +10 -3
- package/dist/src/runner/runner.d.ts +2 -2
- package/dist/src/runner/runner.js +2 -2
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -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/client.d.ts
CHANGED
|
@@ -47,8 +47,10 @@ export interface Agent {
|
|
|
47
47
|
net_allow?: string[];
|
|
48
48
|
/** The repo names its runner can work in, as the runner reported them (empty: never reported). */
|
|
49
49
|
repos?: string[];
|
|
50
|
-
/** GitHub repositories ("owner/name", "owner/*")
|
|
50
|
+
/** GitHub repositories ("owner/name", "owner/*") an admin picked for the agent's runs; empty: none picked. */
|
|
51
51
|
github_repos?: string[];
|
|
52
|
+
/** What its runs may read on GitHub: github_repos, else the repositories its runner works in (one owner); empty: nothing. */
|
|
53
|
+
github_scope?: string[];
|
|
52
54
|
}
|
|
53
55
|
/** A read-only GitHub token the hub issued for one run, valid an hour. `repos`: the repository names it covers, or ["*"]. */
|
|
54
56
|
export interface GithubToken {
|
|
@@ -432,7 +434,7 @@ export declare class Client {
|
|
|
432
434
|
/** Download one attachment into `dir`; returns the local path. */
|
|
433
435
|
download(a: Attachment, dir: string): Promise<string>;
|
|
434
436
|
me(): Promise<Agent>;
|
|
435
|
-
/** A read-only GitHub token for one run (
|
|
437
|
+
/** A read-only GitHub token for one run (the agent's github_scope); `runId` names a live run (the runner's key needs it). */
|
|
436
438
|
githubToken(runId: string): Promise<GithubToken>;
|
|
437
439
|
/** A one-hour token that pushes to one repository, for delivering a task's branch (the runner's key, the task's run). */
|
|
438
440
|
pushToken(taskId: string, runId: string, github: string): Promise<GithubToken>;
|
package/dist/src/client.js
CHANGED
|
@@ -265,7 +265,7 @@ export class Client {
|
|
|
265
265
|
a.owner_name = r.owner_name;
|
|
266
266
|
return a;
|
|
267
267
|
}
|
|
268
|
-
/** A read-only GitHub token for one run (
|
|
268
|
+
/** A read-only GitHub token for one run (the agent's github_scope); `runId` names a live run (the runner's key needs it). */
|
|
269
269
|
async githubToken(runId) {
|
|
270
270
|
return this.ach('POST', '/github/token', { run_id: runId });
|
|
271
271
|
}
|
package/dist/src/doctor.js
CHANGED
|
@@ -108,6 +108,7 @@ export async function runDoctor(o) {
|
|
|
108
108
|
let runtime;
|
|
109
109
|
let agentName;
|
|
110
110
|
let githubRepos = [];
|
|
111
|
+
let githubScope = null;
|
|
111
112
|
if (cfg.hub) {
|
|
112
113
|
const fetchFn = o.fetch ?? ((u, i) => fetch(u, i));
|
|
113
114
|
let host = cfg.hub;
|
|
@@ -170,6 +171,7 @@ export async function runDoctor(o) {
|
|
|
170
171
|
runtime = typeof me.runtime === 'string' ? me.runtime : undefined;
|
|
171
172
|
agentName = me.name;
|
|
172
173
|
githubRepos = Array.isArray(me.github_repos) ? me.github_repos : [];
|
|
174
|
+
githubScope = Array.isArray(me.github_scope) ? me.github_scope : null;
|
|
173
175
|
add('hub login', 'ok', `agent ${me.name}${me.owner_name ? ` (owner ${me.owner_name})` : ''}, runtime ${me.runtime ?? '?'}`, 'key');
|
|
174
176
|
}
|
|
175
177
|
catch (e) {
|
|
@@ -189,10 +191,15 @@ export async function runDoctor(o) {
|
|
|
189
191
|
hubLatest = c.latest_client;
|
|
190
192
|
if (c && Number.isInteger(c.min_client_proto))
|
|
191
193
|
hubMinProto = c.min_client_proto;
|
|
192
|
-
// a run's GitHub token comes from the hub's GitHub App
|
|
194
|
+
// a run's GitHub token comes from the hub's GitHub App, for the agent's scope: the repositories an admin picked, else the
|
|
195
|
+
// ones this runner works in (an older hub without github_scope: the picked ones, else every repository the App sees)
|
|
193
196
|
if (c && typeof c.github_app === 'boolean') {
|
|
194
|
-
if (c.github_app)
|
|
195
|
-
add('github', '
|
|
197
|
+
if (c.github_app && githubScope && !githubScope.length)
|
|
198
|
+
add('github', 'warn', 'no GitHub repository: this runner works in no GitHub checkout and no admin picked any', 'key', 'start the runner in a checkout, or ask your admin to pick repositories for this agent');
|
|
199
|
+
else if (c.github_app) {
|
|
200
|
+
const s = githubScope ?? githubRepos;
|
|
201
|
+
add('github', 'ok', s.length ? `a read-only token for ${s.join(', ')}, issued for each run` : 'a read-only token for every repository the hub\'s GitHub App sees, issued for each run', 'key');
|
|
202
|
+
}
|
|
196
203
|
else if (githubRepos.length)
|
|
197
204
|
add('github', 'warn', `${githubRepos.join(', ')} are listed for this agent, but the hub has no GitHub App`, 'key', 'ask your admin to set ACH_GITHUB_APP_ID and ACH_GITHUB_APP_KEY on the hub');
|
|
198
205
|
}
|
|
@@ -328,8 +328,8 @@ export declare class Runner {
|
|
|
328
328
|
/** The task's attachments, downloaded into filesDir (best effort: a failed download is listed without a path). */
|
|
329
329
|
private fetchFiles;
|
|
330
330
|
/**
|
|
331
|
-
* The GitHub token of a run: read-only, issued by the hub from its GitHub App for this one run and valid an hour (
|
|
332
|
-
*
|
|
331
|
+
* The GitHub token of a run: read-only, issued by the hub from its GitHub App for this one run and valid an hour (the
|
|
332
|
+
* repositories an admin picked for this agent, else the ones this runner works in). A hub that cannot issue one does not fail the run: the
|
|
333
333
|
* agent finds `gh` without a login, and the runner's log for the task says why. After a failure the hub is not asked again
|
|
334
334
|
* for a minute (ten when it has no GitHub App).
|
|
335
335
|
*/
|
|
@@ -1527,8 +1527,8 @@ export class Runner {
|
|
|
1527
1527
|
return out;
|
|
1528
1528
|
}
|
|
1529
1529
|
/**
|
|
1530
|
-
* The GitHub token of a run: read-only, issued by the hub from its GitHub App for this one run and valid an hour (
|
|
1531
|
-
*
|
|
1530
|
+
* The GitHub token of a run: read-only, issued by the hub from its GitHub App for this one run and valid an hour (the
|
|
1531
|
+
* repositories an admin picked for this agent, else the ones this runner works in). A hub that cannot issue one does not fail the run: the
|
|
1532
1532
|
* agent finds `gh` without a login, and the runner's log for the task says why. After a failure the hub is not asked again
|
|
1533
1533
|
* for a minute (ten when it has no GitHub App).
|
|
1534
1534
|
*/
|
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.
|
|
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",
|