@noetic-tools/acp 1.4.0 → 2.0.0-next.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/client.js +1 -0
- package/dist/permission-channel.d.ts +2 -2
- package/dist/permission-channel.js +23 -12
- package/dist/permissions.d.ts +6 -0
- package/dist/permissions.js +7 -0
- package/dist/serve-permissions.d.ts +8 -2
- package/dist/serve-permissions.js +26 -5
- package/dist/serve-types.d.ts +6 -5
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -74,8 +74,8 @@ export declare const acpPermissionDecisions: ExternalChannel<AcpPermissionReply>
|
|
|
74
74
|
export interface AskUserForPermissionOptions {
|
|
75
75
|
/**
|
|
76
76
|
* How long to wait for an answer, in milliseconds. On expiry the handler
|
|
77
|
-
* resolves with {@link onTimeout}
|
|
78
|
-
*
|
|
77
|
+
* resolves with {@link onTimeout}. With none, the request waits until it is
|
|
78
|
+
* answered or the turn is cancelled.
|
|
79
79
|
*/
|
|
80
80
|
timeout?: number;
|
|
81
81
|
/**
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* topic (broadcast, each waiter filters for its own `requestId`) — per-request
|
|
22
22
|
* channels would leak one channel state per prompt for the harness lifetime.
|
|
23
23
|
*/
|
|
24
|
+
import { isNoeticError } from '@noetic-tools/types';
|
|
24
25
|
import { z } from 'zod';
|
|
25
26
|
//#region Scope
|
|
26
27
|
/**
|
|
@@ -91,6 +92,13 @@ export const acpPermissionDecisions = {
|
|
|
91
92
|
mode: 'topic',
|
|
92
93
|
external: true,
|
|
93
94
|
};
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region Helpers
|
|
97
|
+
/** The longest wait one timer takes, about 24.8 days. A wait with no deadline parks again after it. */
|
|
98
|
+
const MAX_WAIT_MS = 2 ** 31 - 1;
|
|
99
|
+
function isChannelTimeout(error) {
|
|
100
|
+
return isNoeticError(error) && error.noeticError.kind === 'channel_timeout';
|
|
101
|
+
}
|
|
94
102
|
/**
|
|
95
103
|
* Build an {@link AcpPermissionHandler} that asks a human over the channel pair
|
|
96
104
|
* above. Pass it as a step's `onPermissionRequest`; it runs after the step's
|
|
@@ -98,21 +106,22 @@ export const acpPermissionDecisions = {
|
|
|
98
106
|
* @public
|
|
99
107
|
*/
|
|
100
108
|
export function askUserForPermission(opts = {}) {
|
|
101
|
-
const timeout = opts
|
|
109
|
+
const { timeout } = opts;
|
|
102
110
|
const onTimeout = opts.onTimeout ?? {
|
|
103
111
|
decision: 'deny',
|
|
104
112
|
reason: 'no answer from the user before the permission request timed out',
|
|
105
113
|
};
|
|
106
114
|
return async (request, ctx, info) => {
|
|
107
115
|
const requestId = crypto.randomUUID();
|
|
108
|
-
const deadline = Date.now() + timeout;
|
|
116
|
+
const deadline = timeout === undefined ? undefined : Date.now() + timeout;
|
|
117
|
+
const park = () => ctx.recv(acpPermissionDecisions, {
|
|
118
|
+
timeout: deadline === undefined ? MAX_WAIT_MS : Math.max(1, deadline - Date.now()),
|
|
119
|
+
});
|
|
109
120
|
// Park on the decision topic BEFORE publishing the request. Topic delivery
|
|
110
121
|
// reaches only subscribers that are parked at send time, so a reviewer who
|
|
111
122
|
// answers immediately would otherwise answer into the void and the agent
|
|
112
123
|
// would wait out the whole timeout.
|
|
113
|
-
let waiting =
|
|
114
|
-
timeout,
|
|
115
|
-
});
|
|
124
|
+
let waiting = park();
|
|
116
125
|
await ctx.send(acpPermissionRequests, {
|
|
117
126
|
requestId,
|
|
118
127
|
agentId: info.agentId,
|
|
@@ -135,13 +144,18 @@ export function askUserForPermission(opts = {}) {
|
|
|
135
144
|
//
|
|
136
145
|
// Re-parking between messages leaves a microtask-sized window in which a
|
|
137
146
|
// decision could be missed — only reachable when two prompts are answered
|
|
138
|
-
// in the same tick
|
|
147
|
+
// in the same tick.
|
|
139
148
|
while (true) {
|
|
140
149
|
let reply;
|
|
141
150
|
try {
|
|
142
151
|
reply = await waiting;
|
|
143
152
|
}
|
|
144
|
-
catch {
|
|
153
|
+
catch (error) {
|
|
154
|
+
// No deadline was set, so the end of one timer is not the end of the wait.
|
|
155
|
+
if (deadline === undefined && isChannelTimeout(error)) {
|
|
156
|
+
waiting = park();
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
145
159
|
return onTimeout;
|
|
146
160
|
}
|
|
147
161
|
if (reply.requestId === requestId) {
|
|
@@ -151,13 +165,10 @@ export function askUserForPermission(opts = {}) {
|
|
|
151
165
|
reason: reply.reason,
|
|
152
166
|
};
|
|
153
167
|
}
|
|
154
|
-
|
|
155
|
-
if (remaining <= 0) {
|
|
168
|
+
if (deadline !== undefined && deadline - Date.now() <= 0) {
|
|
156
169
|
return onTimeout;
|
|
157
170
|
}
|
|
158
|
-
waiting =
|
|
159
|
-
timeout: remaining,
|
|
160
|
-
});
|
|
171
|
+
waiting = park();
|
|
161
172
|
}
|
|
162
173
|
};
|
|
163
174
|
}
|
package/dist/permissions.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export interface AcpPermissionResolverOptions {
|
|
|
21
21
|
policy?: AcpPermissionPolicy;
|
|
22
22
|
steer?: AcpPermissionSteerer;
|
|
23
23
|
handler?: AcpBoundPermissionHandler;
|
|
24
|
+
/**
|
|
25
|
+
* The harness's approval seam, asked last: when nothing above decided and the
|
|
26
|
+
* policy names no `default`. It holds the request for a person rather than
|
|
27
|
+
* denying it (spec 08 § Held tool calls).
|
|
28
|
+
*/
|
|
29
|
+
approve?: AcpPermissionSteerer;
|
|
24
30
|
}
|
|
25
31
|
/** The concrete ACP outcome payload sent back to the agent. */
|
|
26
32
|
export type AcpRequestPermissionOutcome = {
|
package/dist/permissions.js
CHANGED
|
@@ -142,6 +142,13 @@ export async function resolvePermission(request, opts) {
|
|
|
142
142
|
if (opts.handler) {
|
|
143
143
|
return await opts.handler(request);
|
|
144
144
|
}
|
|
145
|
+
// A policy that names its default has decided. Otherwise a person does.
|
|
146
|
+
if (opts.policy?.default === undefined && opts.approve) {
|
|
147
|
+
const approved = await opts.approve(request);
|
|
148
|
+
if (approved) {
|
|
149
|
+
return approved;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
145
152
|
return {
|
|
146
153
|
decision: opts.policy?.default ?? 'deny',
|
|
147
154
|
reason: 'no permission rule, steering decision, or handler matched',
|
|
@@ -21,6 +21,10 @@ export declare function evaluateServePolicy(params: {
|
|
|
21
21
|
toolName: string;
|
|
22
22
|
kind?: AcpToolKind;
|
|
23
23
|
}): AcpServePermissionDecision;
|
|
24
|
+
/** A reply, and whether it is the broker's own because nobody answered in time. */
|
|
25
|
+
interface AskOutcome extends AcpServePermissionReply {
|
|
26
|
+
timedOut?: boolean;
|
|
27
|
+
}
|
|
24
28
|
/**
|
|
25
29
|
* Holds `ask` parks and routes each to its answerer. The layer registers the
|
|
26
30
|
* park *before* invoking `forward`, so an answer racing back in the same tick
|
|
@@ -31,9 +35,10 @@ export declare class ServePermissionBroker {
|
|
|
31
35
|
private readonly forward;
|
|
32
36
|
private readonly pending;
|
|
33
37
|
constructor(forward: (prompt: AcpServePermissionPrompt) => Promise<AcpServePermissionReply>);
|
|
34
|
-
|
|
38
|
+
/** Ask the client. With no `timeoutMs` the ask waits for an answer or a session cancel. */
|
|
39
|
+
ask(prompt: AcpServePermissionPrompt, timeoutMs?: number): Promise<AskOutcome>;
|
|
35
40
|
/** Resolve one park; later answers to the same request are dropped. */
|
|
36
|
-
answer(requestId: string, reply:
|
|
41
|
+
answer(requestId: string, reply: AskOutcome): void;
|
|
37
42
|
/** Unwind every park belonging to a session — the `session/cancel` path. */
|
|
38
43
|
cancelSession(sessionId: string): void;
|
|
39
44
|
}
|
|
@@ -53,3 +58,4 @@ export declare function createServePermissionLayer(params: {
|
|
|
53
58
|
broker: ServePermissionBroker;
|
|
54
59
|
presentation: ServeToolPresentation;
|
|
55
60
|
}): ContextLayer;
|
|
61
|
+
export {};
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { frameworkCast } from '@noetic-tools/types';
|
|
13
13
|
//#region Policy evaluation
|
|
14
|
-
|
|
14
|
+
/** The longest delay a timer takes: about 24.8 days. */
|
|
15
|
+
const MAX_HOOK_TIMEOUT_MS = 2 ** 31 - 1;
|
|
15
16
|
/**
|
|
16
17
|
* First decisive rule wins, checked `deny` → `ask` → `allow`; the policy
|
|
17
18
|
* `default` (or `allow`) applies when nothing matches.
|
|
@@ -47,6 +48,7 @@ export class ServePermissionBroker {
|
|
|
47
48
|
constructor(forward) {
|
|
48
49
|
this.forward = forward;
|
|
49
50
|
}
|
|
51
|
+
/** Ask the client. With no `timeoutMs` the ask waits for an answer or a session cancel. */
|
|
50
52
|
async ask(prompt, timeoutMs) {
|
|
51
53
|
let timer;
|
|
52
54
|
const parked = new Promise((resolve) => {
|
|
@@ -54,10 +56,14 @@ export class ServePermissionBroker {
|
|
|
54
56
|
sessionId: prompt.sessionId,
|
|
55
57
|
resolve,
|
|
56
58
|
});
|
|
59
|
+
if (timeoutMs === undefined) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
57
62
|
timer = setTimeout(() => {
|
|
58
63
|
this.answer(prompt.requestId, {
|
|
59
64
|
decision: 'deny',
|
|
60
65
|
reason: 'permission request timed out',
|
|
66
|
+
timedOut: true,
|
|
61
67
|
});
|
|
62
68
|
}, timeoutMs);
|
|
63
69
|
});
|
|
@@ -110,7 +116,7 @@ export class ServePermissionBroker {
|
|
|
110
116
|
*/
|
|
111
117
|
export function createServePermissionLayer(params) {
|
|
112
118
|
const { sessionId, policy, broker, presentation } = params;
|
|
113
|
-
const askTimeoutMs = policy
|
|
119
|
+
const { askTimeoutMs } = policy;
|
|
114
120
|
const beforeToolCall = async (hookParams) => {
|
|
115
121
|
const { toolName, toolArgs, callId } = hookParams;
|
|
116
122
|
const kind = presentation.kindOf(toolName);
|
|
@@ -143,6 +149,20 @@ export function createServePermissionLayer(params) {
|
|
|
143
149
|
kind,
|
|
144
150
|
args: toolArgs,
|
|
145
151
|
}, askTimeoutMs);
|
|
152
|
+
// Nobody at the editor answered. Rather than refuse, hand the call to the
|
|
153
|
+
// harness's approval seam, where a person can still answer it (spec 08 § Held
|
|
154
|
+
// tool calls). The editor's turn is waiting on it, so the turn stays live.
|
|
155
|
+
const approve = hookParams.ctx?.approve;
|
|
156
|
+
if (reply.timedOut && approve && callId !== undefined) {
|
|
157
|
+
return {
|
|
158
|
+
decision: await approve({
|
|
159
|
+
toolName,
|
|
160
|
+
toolArgs,
|
|
161
|
+
callId,
|
|
162
|
+
park: false,
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
146
166
|
if (reply.decision === 'allow') {
|
|
147
167
|
return {
|
|
148
168
|
decision: {
|
|
@@ -167,9 +187,10 @@ export function createServePermissionLayer(params) {
|
|
|
167
187
|
beforeToolCall,
|
|
168
188
|
},
|
|
169
189
|
timeouts: {
|
|
170
|
-
// The broker owns the
|
|
171
|
-
//
|
|
172
|
-
|
|
190
|
+
// The broker owns the editor's deadline (askTimeoutMs, none unless set). After it
|
|
191
|
+
// a call may be held for a person through the harness, for as long as that takes, so the
|
|
192
|
+
// lifecycle timeout is the longest a timer allows and only backstops a wedge.
|
|
193
|
+
beforeToolCall: MAX_HOOK_TIMEOUT_MS,
|
|
173
194
|
},
|
|
174
195
|
// A gate fails CLOSED: if the hook ever throws or blows the backstop
|
|
175
196
|
// timeout, the lifecycle denies the call rather than abstaining into the
|
package/dist/serve-types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `@noetic-tools/chat-sdk` uses — so this package keeps depending only on
|
|
6
6
|
* `@noetic-tools/types`.
|
|
7
7
|
*/
|
|
8
|
-
import type { AcpMcpServer, AcpToolKind,
|
|
8
|
+
import type { AcpMcpServer, AcpToolKind, ExecuteArgument, ExecuteOptions, FsAdapter, Item, SessionScope, ShellAdapter, StreamEvent, StreamingItem, ToolAcpDeclaration } from '@noetic-tools/types';
|
|
9
9
|
import type * as acp from '@zed-industries/agent-client-protocol';
|
|
10
10
|
/**
|
|
11
11
|
* The slice of `AgentHarnessContract` the ACP server drives. Any harness (or
|
|
@@ -13,7 +13,7 @@ import type * as acp from '@zed-industries/agent-client-protocol';
|
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
export interface AcpServeHarness {
|
|
16
|
-
execute(input:
|
|
16
|
+
execute(input: ExecuteArgument, options?: ExecuteOptions): Promise<void>;
|
|
17
17
|
getFullStream(scope?: SessionScope): AsyncIterable<StreamEvent>;
|
|
18
18
|
getItemStream(scope?: SessionScope): AsyncIterable<StreamingItem>;
|
|
19
19
|
seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
|
|
@@ -77,9 +77,10 @@ export interface AcpServePermissionPolicy {
|
|
|
77
77
|
default?: AcpServePermissionDecision;
|
|
78
78
|
rules?: ReadonlyArray<AcpServePermissionRule>;
|
|
79
79
|
/**
|
|
80
|
-
* How long an `ask` waits for the client's answer, in milliseconds.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
80
|
+
* How long an `ask` waits for the client's answer, in milliseconds. With
|
|
81
|
+
* none, the ask waits until the client answers or the turn is cancelled. On
|
|
82
|
+
* expiry the call goes to the harness's approval seam, and is denied when
|
|
83
|
+
* there is none: waiting must not become approval.
|
|
83
84
|
*/
|
|
84
85
|
askTimeoutMs?: number;
|
|
85
86
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/acp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Both directions of the Agent Client Protocol for Noetic. Drives any ACP-speaking coding agent (Claude Code, Codex, Gemini CLI, …) as a step, and serves a Noetic harness as an ACP agent for editors like Zed (toAcpAgent / serveAcp).",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@modelcontextprotocol/node": "2.1.2",
|
|
66
66
|
"@modelcontextprotocol/server": "2.4.0",
|
|
67
|
-
"@noetic-tools/types": "^3.
|
|
67
|
+
"@noetic-tools/types": "^3.19.0-next.1",
|
|
68
68
|
"@zed-industries/agent-client-protocol": "^0.4.5",
|
|
69
69
|
"ws": "8.22.1",
|
|
70
70
|
"zod": "^4.0.0"
|