tenjin-cli 0.1.0-alpha.20 → 0.1.0-alpha.21
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 +17 -2
- package/dist/{chunk-3BS55ANY.js → chunk-2AQO4YDI.js} +50 -4
- package/dist/{chunk-3BS55ANY.js.map → chunk-2AQO4YDI.js.map} +1 -1
- package/dist/{chunk-HH3PDYIG.js → chunk-3EUTWC2B.js} +5 -5
- package/dist/{chunk-BTX2QE2Y.js → chunk-AQRUD5GQ.js} +2 -2
- package/dist/{chunk-CXUYCDPX.js → chunk-C363JZN2.js} +4 -4
- package/dist/{chunk-PO4HAXAW.js → chunk-ETW2ASBP.js} +52 -18
- package/dist/chunk-ETW2ASBP.js.map +1 -0
- package/dist/{chunk-RPR2C2JO.js → chunk-GHTPYKDT.js} +5 -5
- package/dist/{chunk-5KD5HRAJ.js → chunk-IOB7URFH.js} +3 -2
- package/dist/chunk-IOB7URFH.js.map +1 -0
- package/dist/{chunk-5FYKPQNX.js → chunk-IOIHYOU4.js} +3 -3
- package/dist/{chunk-LN2HISWU.js → chunk-JN7TMXVF.js} +2 -2
- package/dist/{chunk-TU7XH3JJ.js → chunk-K6AXXYCG.js} +14 -2
- package/dist/chunk-K6AXXYCG.js.map +1 -0
- package/dist/{chunk-2G2WLVHB.js → chunk-LAIZ2AQA.js} +9 -4
- package/dist/chunk-LAIZ2AQA.js.map +1 -0
- package/dist/{chunk-YREKMJPP.js → chunk-N4DJEQAF.js} +65 -6
- package/dist/chunk-N4DJEQAF.js.map +1 -0
- package/dist/{chunk-NSG5TVZQ.js → chunk-OSUD6YZZ.js} +14 -10
- package/dist/chunk-OSUD6YZZ.js.map +1 -0
- package/dist/{chunk-2E6GVIRP.js → chunk-OTPEH3AH.js} +47 -9
- package/dist/chunk-OTPEH3AH.js.map +1 -0
- package/dist/{chunk-LI44XLMB.js → chunk-PJEG2JIJ.js} +5 -5
- package/dist/{chunk-4M5FBWT5.js → chunk-QF4SSCQV.js} +10 -1
- package/dist/chunk-QF4SSCQV.js.map +1 -0
- package/dist/chunk-QHILSA6G.js +82 -0
- package/dist/chunk-QHILSA6G.js.map +1 -0
- package/dist/{chunk-72UHZRG6.js → chunk-QRFONFRW.js} +2 -2
- package/dist/{chunk-P42QX3QF.js → chunk-RCJQARZF.js} +2 -2
- package/dist/{chunk-P42QX3QF.js.map → chunk-RCJQARZF.js.map} +1 -1
- package/dist/chunk-SRVDXR6B.js +337 -0
- package/dist/chunk-SRVDXR6B.js.map +1 -0
- package/dist/{chunk-7ACHDNJA.js → chunk-U2ATFMKZ.js} +13 -4
- package/dist/chunk-U2ATFMKZ.js.map +1 -0
- package/dist/{chunk-4AS52HUG.js → chunk-UY2TOI3B.js} +70 -27
- package/dist/chunk-UY2TOI3B.js.map +1 -0
- package/dist/{chunk-CCDOV45D.js → chunk-W3LVZ2EN.js} +25 -8
- package/dist/{chunk-CCDOV45D.js.map → chunk-W3LVZ2EN.js.map} +1 -1
- package/dist/{chunk-YEBNE5NW.js → chunk-YVODPFTL.js} +5 -5
- package/dist/{cli-XJQYUOHI.js → cli-7KJ4QLUU.js} +42 -29
- package/dist/{cli-XJQYUOHI.js.map → cli-7KJ4QLUU.js.map} +1 -1
- package/dist/{config-KMJLFPSI.js → config-MSN6H4MD.js} +10 -8
- package/dist/{doctor-KMN55D7U.js → doctor-ITUCKN6C.js} +25 -16
- package/dist/{doctor-KMN55D7U.js.map → doctor-ITUCKN6C.js.map} +1 -1
- package/dist/{fund-LT6ZPGEQ.js → fund-XPB4IIG5.js} +11 -11
- package/dist/{hook-command-U5XPEHAJ.js → hook-command-VVV2Q23L.js} +293 -80
- package/dist/hook-command-VVV2Q23L.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/{install-MMNXJ5LM.js → install-OSJRM2ME.js} +13 -11
- package/dist/{install-identity-B7FVIWML.js → install-identity-YIWKQOUD.js} +7 -7
- package/dist/{install-wallet-XMVUBCHS.js → install-wallet-BWJO2SUC.js} +10 -10
- package/dist/{mcp-TUPRIPSI.js → mcp-KE5YKPS2.js} +203 -29
- package/dist/{mcp-TUPRIPSI.js.map → mcp-KE5YKPS2.js.map} +1 -1
- package/dist/{paths-LRMWNTJP.js → paths-MUXHUOCM.js} +8 -2
- package/dist/{pay-XAWW3NV3.js → pay-MUV2U232.js} +18 -16
- package/dist/payments-4D27K4L2.js +48 -0
- package/dist/payments-4D27K4L2.js.map +1 -0
- package/dist/{send-HESQYRKM.js → send-BXHFKDBF.js} +10 -10
- package/dist/{status-ANZPRZJJ.js → status-3Z3YPRSE.js} +6 -6
- package/dist/{status-line-J3TUWVRQ.js → status-line-CKRMGZ3Q.js} +7 -7
- package/dist/{status-line-wiring-HSV7DXO5.js → status-line-wiring-GECLIIBT.js} +5 -5
- package/dist/tenjin-daemon.mjs +57 -6
- package/dist/{uninstall-GUU34YKP.js → uninstall-BZTVWJ7W.js} +11 -11
- package/dist/{update-KO2NZRJ5.js → update-IQQTEOI5.js} +6 -6
- package/dist/{wallet-3URC5QPK.js → wallet-UFXQ57TZ.js} +10 -10
- package/docs/agent-permissions.md +4 -2
- package/docs/safety-model.md +2 -2
- package/package.json +1 -1
- package/dist/chunk-2E6GVIRP.js.map +0 -1
- package/dist/chunk-2G2WLVHB.js.map +0 -1
- package/dist/chunk-3KKKB2AQ.js +0 -40
- package/dist/chunk-3KKKB2AQ.js.map +0 -1
- package/dist/chunk-4AS52HUG.js.map +0 -1
- package/dist/chunk-4M5FBWT5.js.map +0 -1
- package/dist/chunk-5KD5HRAJ.js.map +0 -1
- package/dist/chunk-7ACHDNJA.js.map +0 -1
- package/dist/chunk-NSG5TVZQ.js.map +0 -1
- package/dist/chunk-PO4HAXAW.js.map +0 -1
- package/dist/chunk-TU7XH3JJ.js.map +0 -1
- package/dist/chunk-YREKMJPP.js.map +0 -1
- package/dist/hook-command-U5XPEHAJ.js.map +0 -1
- /package/dist/{chunk-HH3PDYIG.js.map → chunk-3EUTWC2B.js.map} +0 -0
- /package/dist/{chunk-BTX2QE2Y.js.map → chunk-AQRUD5GQ.js.map} +0 -0
- /package/dist/{chunk-CXUYCDPX.js.map → chunk-C363JZN2.js.map} +0 -0
- /package/dist/{chunk-RPR2C2JO.js.map → chunk-GHTPYKDT.js.map} +0 -0
- /package/dist/{chunk-5FYKPQNX.js.map → chunk-IOIHYOU4.js.map} +0 -0
- /package/dist/{chunk-LN2HISWU.js.map → chunk-JN7TMXVF.js.map} +0 -0
- /package/dist/{chunk-LI44XLMB.js.map → chunk-PJEG2JIJ.js.map} +0 -0
- /package/dist/{chunk-72UHZRG6.js.map → chunk-QRFONFRW.js.map} +0 -0
- /package/dist/{chunk-YEBNE5NW.js.map → chunk-YVODPFTL.js.map} +0 -0
- /package/dist/{config-KMJLFPSI.js.map → config-MSN6H4MD.js.map} +0 -0
- /package/dist/{fund-LT6ZPGEQ.js.map → fund-XPB4IIG5.js.map} +0 -0
- /package/dist/{install-MMNXJ5LM.js.map → install-OSJRM2ME.js.map} +0 -0
- /package/dist/{install-identity-B7FVIWML.js.map → install-identity-YIWKQOUD.js.map} +0 -0
- /package/dist/{install-wallet-XMVUBCHS.js.map → install-wallet-BWJO2SUC.js.map} +0 -0
- /package/dist/{paths-LRMWNTJP.js.map → paths-MUXHUOCM.js.map} +0 -0
- /package/dist/{pay-XAWW3NV3.js.map → pay-MUV2U232.js.map} +0 -0
- /package/dist/{send-HESQYRKM.js.map → send-BXHFKDBF.js.map} +0 -0
- /package/dist/{status-ANZPRZJJ.js.map → status-3Z3YPRSE.js.map} +0 -0
- /package/dist/{status-line-J3TUWVRQ.js.map → status-line-CKRMGZ3Q.js.map} +0 -0
- /package/dist/{status-line-wiring-HSV7DXO5.js.map → status-line-wiring-GECLIIBT.js.map} +0 -0
- /package/dist/{uninstall-GUU34YKP.js.map → uninstall-BZTVWJ7W.js.map} +0 -0
- /package/dist/{update-KO2NZRJ5.js.map → update-IQQTEOI5.js.map} +0 -0
- /package/dist/{wallet-3URC5QPK.js.map → wallet-UFXQ57TZ.js.map} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
isPublicAddress
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LAIZ2AQA.js";
|
|
5
5
|
import {
|
|
6
6
|
requestToolAccess
|
|
7
7
|
} from "./chunk-S2NRVRPF.js";
|
|
8
8
|
import {
|
|
9
9
|
ROUTER_PATH,
|
|
10
10
|
requestDecision
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UY2TOI3B.js";
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
} from "./chunk-
|
|
13
|
+
rememberingBalanceReader
|
|
14
|
+
} from "./chunk-QHILSA6G.js";
|
|
15
15
|
import {
|
|
16
16
|
evaluateSpendPolicy,
|
|
17
17
|
readSpendSummary,
|
|
18
18
|
spentOf
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-U2ATFMKZ.js";
|
|
20
20
|
import {
|
|
21
21
|
REQUEST_TOOL
|
|
22
22
|
} from "./chunk-TGLKKLQG.js";
|
|
@@ -34,32 +34,37 @@ import {
|
|
|
34
34
|
noteSession,
|
|
35
35
|
pruneProgress,
|
|
36
36
|
pruneSessions,
|
|
37
|
+
redirectClaimed,
|
|
37
38
|
sessionDir,
|
|
38
39
|
wasOffered,
|
|
39
40
|
writeProgress
|
|
40
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-QF4SSCQV.js";
|
|
41
42
|
import {
|
|
42
43
|
composeUserAgent
|
|
43
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-2AQO4YDI.js";
|
|
44
45
|
import {
|
|
45
46
|
routerSettings
|
|
46
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-C363JZN2.js";
|
|
47
48
|
import "./chunk-2I4QTOLB.js";
|
|
48
49
|
import {
|
|
49
50
|
resolveContextSettings
|
|
50
|
-
} from "./chunk-
|
|
51
|
-
import
|
|
51
|
+
} from "./chunk-IOB7URFH.js";
|
|
52
|
+
import {
|
|
53
|
+
parseUsdToAtomic,
|
|
54
|
+
toMoney
|
|
55
|
+
} from "./chunk-O2JYBOUO.js";
|
|
52
56
|
import {
|
|
53
57
|
external_exports,
|
|
54
58
|
isSameDeployment,
|
|
55
59
|
loadRawConfig,
|
|
60
|
+
resolveExperimentalBazaar,
|
|
56
61
|
resolveSettings
|
|
57
|
-
} from "./chunk-
|
|
58
|
-
import "./chunk-
|
|
62
|
+
} from "./chunk-W3LVZ2EN.js";
|
|
63
|
+
import "./chunk-RCJQARZF.js";
|
|
59
64
|
import "./chunk-JLEF5WHM.js";
|
|
60
65
|
import {
|
|
61
66
|
walletPath
|
|
62
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-K6AXXYCG.js";
|
|
63
68
|
import "./chunk-ZXTAQYNA.js";
|
|
64
69
|
|
|
65
70
|
// src/router/hooks.ts
|
|
@@ -79,6 +84,14 @@ var MAX_LITERAL_URL_CHARS = 2e3;
|
|
|
79
84
|
var MAX_PENDING_CHARS = 4e3;
|
|
80
85
|
var MAX_OUTCOME_ERROR_CHARS = 1e3;
|
|
81
86
|
var MASK_MARGIN = 4096;
|
|
87
|
+
function subjectOf(pending) {
|
|
88
|
+
return "query" in pending ? pending.query : "url" in pending ? pending.url : pending.question;
|
|
89
|
+
}
|
|
90
|
+
function withSubject(pending, subject) {
|
|
91
|
+
if ("query" in pending) return { tool: pending.tool, query: subject };
|
|
92
|
+
if ("url" in pending) return { tool: pending.tool, url: subject };
|
|
93
|
+
return { tool: pending.tool, question: subject };
|
|
94
|
+
}
|
|
82
95
|
var URL_RE = /\bhttps?:\/\/[^\s<>"'`)\]]+/gi;
|
|
83
96
|
function literalUrlsIn(text) {
|
|
84
97
|
const found = /* @__PURE__ */ new Set();
|
|
@@ -112,7 +125,7 @@ function fit(packet) {
|
|
|
112
125
|
}
|
|
113
126
|
function seal(packet) {
|
|
114
127
|
const pending = packet.pendingCall;
|
|
115
|
-
const subject = pending === void 0 ? "" :
|
|
128
|
+
const subject = pending === void 0 ? "" : subjectOf(pending);
|
|
116
129
|
const sealedSubject = maskWithin(subject, MAX_PENDING_CHARS);
|
|
117
130
|
const bound = (text) => maskWithin(text, MAX_MESSAGE_CHARS).text;
|
|
118
131
|
const sealedCurrent = maskWithin(packet.current.text, MAX_MESSAGE_CHARS);
|
|
@@ -123,9 +136,7 @@ function seal(packet) {
|
|
|
123
136
|
history: packet.history.slice(-MAX_HISTORY).map((message) => ({ role: message.role, text: bound(message.text) })).filter((message) => message.text.length > 0),
|
|
124
137
|
literalUrls: packet.literalUrls.filter((url) => !isLocalTarget(url)).map(mask).filter((url) => url.length <= MAX_LITERAL_URL_CHARS),
|
|
125
138
|
historyStatus: packet.historyStatus,
|
|
126
|
-
...pending === void 0 ? {} : {
|
|
127
|
-
pendingCall: "query" in pending ? { tool: pending.tool, query: sealedSubject.text } : { tool: pending.tool, url: sealedSubject.text }
|
|
128
|
-
},
|
|
139
|
+
...pending === void 0 ? {} : { pendingCall: withSubject(pending, sealedSubject.text) },
|
|
129
140
|
...outcome === void 0 ? {} : {
|
|
130
141
|
nativeOutcome: {
|
|
131
142
|
...outcome,
|
|
@@ -173,7 +184,7 @@ async function buildPromptPacket(transcriptPath, sessionId, prompt) {
|
|
|
173
184
|
}
|
|
174
185
|
async function buildNativePacket(transcriptPath, sessionId, pending, opts = {}) {
|
|
175
186
|
const { agentId, nativeOutcome } = opts;
|
|
176
|
-
const subject =
|
|
187
|
+
const subject = subjectOf(pending);
|
|
177
188
|
const read = await readHistory(transcriptPath, { sessionId });
|
|
178
189
|
const own = agentId === void 0 ? null : await readHistory(subagentTranscriptPath(transcriptPath, sessionId, agentId), {
|
|
179
190
|
sessionId,
|
|
@@ -201,6 +212,7 @@ function subagentTranscriptPath(transcriptPath, sessionId, agentId) {
|
|
|
201
212
|
async function readHistory(path, scope) {
|
|
202
213
|
if (path === void 0 || path.length === 0) return null;
|
|
203
214
|
let raw;
|
|
215
|
+
let tail;
|
|
204
216
|
let file;
|
|
205
217
|
try {
|
|
206
218
|
file = await open(path, "r");
|
|
@@ -209,22 +221,37 @@ async function readHistory(path, scope) {
|
|
|
209
221
|
}
|
|
210
222
|
try {
|
|
211
223
|
const stat = await file.stat();
|
|
212
|
-
if (!stat.isFile()
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
216
|
-
raw =
|
|
224
|
+
if (!stat.isFile()) return null;
|
|
225
|
+
tail = stat.size > MAX_TRANSCRIPT_BYTES;
|
|
226
|
+
const read = tail ? await readTail(file, stat.size) : await readHead(file);
|
|
227
|
+
if (read === null) return null;
|
|
228
|
+
raw = read;
|
|
217
229
|
} catch {
|
|
218
230
|
return null;
|
|
219
231
|
} finally {
|
|
220
232
|
await file.close();
|
|
221
233
|
}
|
|
222
234
|
try {
|
|
223
|
-
|
|
235
|
+
const messages = parseRows(raw, scope);
|
|
236
|
+
if (tail && !messages.some((message) => message.role === "user")) return null;
|
|
237
|
+
return messages;
|
|
224
238
|
} catch {
|
|
225
239
|
return null;
|
|
226
240
|
}
|
|
227
241
|
}
|
|
242
|
+
async function readHead(file) {
|
|
243
|
+
const buffer = Buffer.alloc(MAX_TRANSCRIPT_BYTES + 1);
|
|
244
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
245
|
+
if (bytesRead > MAX_TRANSCRIPT_BYTES) return null;
|
|
246
|
+
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
247
|
+
}
|
|
248
|
+
async function readTail(file, size) {
|
|
249
|
+
const buffer = Buffer.alloc(MAX_TRANSCRIPT_BYTES + 1);
|
|
250
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, size - buffer.length);
|
|
251
|
+
const window = buffer.subarray(0, bytesRead);
|
|
252
|
+
const newline = window.indexOf(10);
|
|
253
|
+
return newline === -1 ? null : window.subarray(newline + 1).toString("utf8");
|
|
254
|
+
}
|
|
228
255
|
function parseRows(raw, scope) {
|
|
229
256
|
const { sessionId, agentId } = scope;
|
|
230
257
|
let messages = [];
|
|
@@ -260,12 +287,24 @@ function parseRows(raw, scope) {
|
|
|
260
287
|
return messages;
|
|
261
288
|
}
|
|
262
289
|
var LOCAL_COMMAND_OUTPUT = /^\s*<local-command-(?:stdout|stderr)>/;
|
|
290
|
+
var HANDBACK_PREFIXES = [
|
|
291
|
+
"<task-notification>",
|
|
292
|
+
"<agent-message",
|
|
293
|
+
"<teammate-message",
|
|
294
|
+
"<cross-session-message",
|
|
295
|
+
"Another Claude session sent a message"
|
|
296
|
+
];
|
|
297
|
+
function isHandback(text) {
|
|
298
|
+
const trimmed = text.trimStart();
|
|
299
|
+
return HANDBACK_PREFIXES.some((prefix) => trimmed.startsWith(prefix));
|
|
300
|
+
}
|
|
301
|
+
var HARNESS_ORIGINS = /* @__PURE__ */ new Set(["task-notification", "peer"]);
|
|
263
302
|
function harnessUserRow(row, text) {
|
|
264
303
|
const origin = row.origin;
|
|
265
|
-
if (origin !== null && typeof origin === "object" && origin.kind
|
|
304
|
+
if (origin !== null && typeof origin === "object" && HARNESS_ORIGINS.has(origin.kind)) {
|
|
266
305
|
return true;
|
|
267
306
|
}
|
|
268
|
-
return text
|
|
307
|
+
return isHandback(text) || LOCAL_COMMAND_OUTPUT.test(text);
|
|
269
308
|
}
|
|
270
309
|
function ownSidechainRow(row, agentId) {
|
|
271
310
|
return row.isSidechain === true && row.agentId === agentId && row.isMeta !== true;
|
|
@@ -475,6 +514,20 @@ var ShortfallEventSchema = external_exports.object({
|
|
|
475
514
|
error: external_exports.unknown().optional(),
|
|
476
515
|
is_interrupt: external_exports.boolean().optional()
|
|
477
516
|
});
|
|
517
|
+
var AskEventSchema = external_exports.object({
|
|
518
|
+
hook_event_name: external_exports.literal("PreToolUse").optional(),
|
|
519
|
+
...NativeCallFields,
|
|
520
|
+
tool_name: external_exports.literal("AskUserQuestion")
|
|
521
|
+
});
|
|
522
|
+
var AnswerEventSchema = external_exports.object({
|
|
523
|
+
hook_event_name: external_exports.literal("PostToolUse"),
|
|
524
|
+
session_id: external_exports.string().min(1).max(200),
|
|
525
|
+
transcript_path: external_exports.string().optional(),
|
|
526
|
+
tool_name: external_exports.literal("AskUserQuestion"),
|
|
527
|
+
tool_input: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
528
|
+
tool_response: external_exports.unknown().optional(),
|
|
529
|
+
cwd: external_exports.string().optional()
|
|
530
|
+
});
|
|
478
531
|
var DelegationEventSchema = external_exports.object({
|
|
479
532
|
session_id: external_exports.string().min(1).max(200),
|
|
480
533
|
transcript_path: external_exports.string().optional(),
|
|
@@ -496,6 +549,25 @@ function decodeEvent(raw) {
|
|
|
496
549
|
}
|
|
497
550
|
const native = NativeEventSchema.safeParse(raw);
|
|
498
551
|
if (native.success) return { kind: "native", ...nativeCallOf(native.data) };
|
|
552
|
+
const answer = AnswerEventSchema.safeParse(raw);
|
|
553
|
+
if (answer.success) {
|
|
554
|
+
return {
|
|
555
|
+
kind: "answer",
|
|
556
|
+
sessionId: answer.data.session_id,
|
|
557
|
+
...optional("transcriptPath", answer.data.transcript_path),
|
|
558
|
+
answers: answersOf(answer.data.tool_response, answer.data.tool_input),
|
|
559
|
+
...optional("cwd", answer.data.cwd)
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const ask = AskEventSchema.safeParse(raw);
|
|
563
|
+
if (ask.success) {
|
|
564
|
+
const question = questionOf(ask.data.tool_input);
|
|
565
|
+
return {
|
|
566
|
+
kind: "ask",
|
|
567
|
+
...callFieldsOf(ask.data),
|
|
568
|
+
pending: question === null ? null : { tool: "AskUserQuestion", question }
|
|
569
|
+
};
|
|
570
|
+
}
|
|
499
571
|
const delegation = DelegationEventSchema.safeParse(raw);
|
|
500
572
|
if (delegation.success) {
|
|
501
573
|
const input = delegation.data.tool_input;
|
|
@@ -521,17 +593,51 @@ function decodeEvent(raw) {
|
|
|
521
593
|
};
|
|
522
594
|
}
|
|
523
595
|
function nativeCallOf(event) {
|
|
596
|
+
return {
|
|
597
|
+
...callFieldsOf(event),
|
|
598
|
+
tool: event.tool_name,
|
|
599
|
+
pending: pendingCallOf(event.tool_name, event.tool_input)
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
function callFieldsOf(event) {
|
|
524
603
|
return {
|
|
525
604
|
sessionId: event.session_id,
|
|
526
605
|
...optional("transcriptPath", event.transcript_path),
|
|
527
|
-
tool: event.tool_name,
|
|
528
|
-
pending: pendingCallOf(event.tool_name, event.tool_input),
|
|
529
606
|
...optional("toolUseId", event.tool_use_id),
|
|
530
607
|
...optional("agentId", event.agent_id),
|
|
531
608
|
...optional("agentType", event.agent_type),
|
|
532
609
|
...optional("cwd", event.cwd)
|
|
533
610
|
};
|
|
534
611
|
}
|
|
612
|
+
function questionOf(input) {
|
|
613
|
+
const questions = Array.isArray(input.questions) ? input.questions : [];
|
|
614
|
+
const parts = [];
|
|
615
|
+
for (const entry of questions) {
|
|
616
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
617
|
+
const { question, options } = entry;
|
|
618
|
+
if (typeof question === "string" && question.trim().length > 0) parts.push(question.trim());
|
|
619
|
+
for (const option of Array.isArray(options) ? options : []) {
|
|
620
|
+
if (option === null || typeof option !== "object") continue;
|
|
621
|
+
const { label, description } = option;
|
|
622
|
+
if (typeof label !== "string" || label.trim().length === 0) continue;
|
|
623
|
+
parts.push(
|
|
624
|
+
typeof description === "string" && description.trim().length > 0 ? `${label.trim()}: ${description.trim()}` : label.trim()
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const joined = parts.join(" ");
|
|
629
|
+
return joined.length > 0 ? joined : null;
|
|
630
|
+
}
|
|
631
|
+
function answersOf(response, input) {
|
|
632
|
+
for (const holder of [response, input]) {
|
|
633
|
+
if (holder === null || typeof holder !== "object" || Array.isArray(holder)) continue;
|
|
634
|
+
const answers = holder.answers;
|
|
635
|
+
if (answers === null || typeof answers !== "object" || Array.isArray(answers)) continue;
|
|
636
|
+
const texts = Object.values(answers).filter((value) => typeof value === "string").map((value) => value.trim()).filter((value) => value.length > 0);
|
|
637
|
+
if (texts.length > 0) return texts.join("\n");
|
|
638
|
+
}
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
535
641
|
function searchOf(event) {
|
|
536
642
|
if (event.hook_event_name !== "PostToolUse" || event.tool_name !== "WebSearch") return null;
|
|
537
643
|
const response = event.tool_response;
|
|
@@ -545,6 +651,7 @@ function optional(key, value) {
|
|
|
545
651
|
var ACKNOWLEDGEMENTS = /* @__PURE__ */ new Set(["y", "yes", "ok", "okay", "continue", "go", "sure", "thanks"]);
|
|
546
652
|
function promptSkipReason(prompt) {
|
|
547
653
|
const trimmed = prompt.trim();
|
|
654
|
+
if (isHandback(trimmed)) return "handback";
|
|
548
655
|
if (trimmed.startsWith("/")) return "slash";
|
|
549
656
|
const normalized = trimmed.toLowerCase().replace(/[.!,]+$/, "");
|
|
550
657
|
return ACKNOWLEDGEMENTS.has(normalized) ? "acknowledgement" : null;
|
|
@@ -558,6 +665,7 @@ function attributed(hint) {
|
|
|
558
665
|
return `${HINT_SOURCE}: ${toolNamed(hint)}`;
|
|
559
666
|
}
|
|
560
667
|
var ONE_BLOCK = "If this does not cover it, make your own call again: you will not be redirected twice in a row for the same search or URL.";
|
|
668
|
+
var ONE_BLOCK_QUESTION = "If this does not cover it, ask your question again: you will not be redirected twice in a row for the same question.";
|
|
561
669
|
function shortfallOffer(tool, hint) {
|
|
562
670
|
return `${HINT_SOURCE}: your ${tool} call came back short. Optional: ${toolNamed(hint)}`;
|
|
563
671
|
}
|
|
@@ -607,7 +715,12 @@ var BALANCE_TIMEOUT_MS = 1e3;
|
|
|
607
715
|
function gateDeadline(deps) {
|
|
608
716
|
return (deps.now?.() ?? Date.now()) + (deps.timeoutMs ?? GATE_TIMEOUT_MS);
|
|
609
717
|
}
|
|
610
|
-
async function
|
|
718
|
+
async function spendShortfall(decision, deps, deadline) {
|
|
719
|
+
const price = `$${toMoney(decision.providerPriceAtomic).usd}`;
|
|
720
|
+
const approval = (detail) => ({
|
|
721
|
+
withheld: "offer needs approval",
|
|
722
|
+
note: `Note: ${price} ${detail}; request will return needs_approval with the command the user runs to approve it \u2014 ask the user first.`
|
|
723
|
+
});
|
|
611
724
|
let rpcUrl;
|
|
612
725
|
try {
|
|
613
726
|
const settings = await resolveContextSettings(hookContext(deps));
|
|
@@ -619,15 +732,22 @@ async function withheldBecause(decision, deps, deadline) {
|
|
|
619
732
|
creator: new URL(decision.endpoint).host,
|
|
620
733
|
sessionSpentAtomic: ledger === null ? 0n : spentOf(ledger)
|
|
621
734
|
});
|
|
622
|
-
if (evaluation.decision !== "allow")
|
|
735
|
+
if (evaluation.decision !== "allow") {
|
|
736
|
+
return approval(
|
|
737
|
+
evaluation.reason === "above_auto_spend" ? `is above this machine's automatic per-call limit ($${toMoney(settings.policy.maxAutoSpendAtomic.toString()).usd})` : "needs approval under this machine's spend limits"
|
|
738
|
+
);
|
|
739
|
+
}
|
|
623
740
|
rpcUrl = settings.rpcUrl;
|
|
624
741
|
} catch {
|
|
625
|
-
return "
|
|
742
|
+
return approval("needs approval under this machine's spend limits");
|
|
626
743
|
}
|
|
627
744
|
if ((deps.env ?? process.env).TENJIN_WALLET_KEY?.trim()) return null;
|
|
628
745
|
const address = await walletAddress(deps.dataDir);
|
|
629
746
|
if (address === null) return null;
|
|
630
|
-
const
|
|
747
|
+
const readBalance = rememberingBalanceReader(deps.dataDir, {
|
|
748
|
+
...deps.now !== void 0 ? { now: deps.now } : {}
|
|
749
|
+
});
|
|
750
|
+
const balance = await readBalance(address, rpcUrl, {
|
|
631
751
|
timeoutMs: Math.min(BALANCE_TIMEOUT_MS, deadline - (deps.now?.() ?? Date.now())),
|
|
632
752
|
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
633
753
|
});
|
|
@@ -638,7 +758,50 @@ async function withheldBecause(decision, deps, deadline) {
|
|
|
638
758
|
);
|
|
639
759
|
return null;
|
|
640
760
|
}
|
|
641
|
-
return balance < BigInt(decision.providerPriceAtomic) ?
|
|
761
|
+
return balance < BigInt(decision.providerPriceAtomic) ? {
|
|
762
|
+
withheld: "wallet needs USDC",
|
|
763
|
+
note: `Note: the wallet holds $${toMoney(balance.toString()).usd}; fund it with \`tenjin wallet fund\`.`
|
|
764
|
+
} : null;
|
|
765
|
+
}
|
|
766
|
+
async function vetOffer(offer, deps, deadline, canAskUser) {
|
|
767
|
+
const shortfall = await spendShortfall(termsOf(offer), deps, deadline);
|
|
768
|
+
if (shortfall === null) {
|
|
769
|
+
const note = await overCapNote(offer.hint, deps, canAskUser);
|
|
770
|
+
return { offer: note === null ? offer : { ...offer, hint: `${offer.hint} ${note}` } };
|
|
771
|
+
}
|
|
772
|
+
if (offer.action === "discovered" && canAskUser) {
|
|
773
|
+
return { offer: { ...offer, hint: `${offer.hint} ${shortfall.note}` } };
|
|
774
|
+
}
|
|
775
|
+
return { withheld: shortfall.withheld };
|
|
776
|
+
}
|
|
777
|
+
var LISTED_PRICE_RE = /about \$(\d+(?:\.\d+)?)(?= per call|: request\(| \(price can vary)|\$(\d+(?:\.\d+)?)(?=\): request\(| via https?:\/\/)/g;
|
|
778
|
+
var QUOTED_RE = /"(?:[^"\\]|\\.)*"/g;
|
|
779
|
+
async function overCapNote(hint, deps, canAskUser) {
|
|
780
|
+
const listed = [...hint.replace(QUOTED_RE, '""').matchAll(LISTED_PRICE_RE)].map(
|
|
781
|
+
(match) => match[1] ?? match[2]
|
|
782
|
+
);
|
|
783
|
+
if (listed.length === 0) return null;
|
|
784
|
+
let cap;
|
|
785
|
+
try {
|
|
786
|
+
cap = (await resolveContextSettings(hookContext(deps))).policy.maxAutoSpendAtomic;
|
|
787
|
+
} catch {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
const over = [
|
|
791
|
+
...new Set(
|
|
792
|
+
listed.filter((usd) => {
|
|
793
|
+
try {
|
|
794
|
+
return BigInt(parseUsdToAtomic(usd)) > cap;
|
|
795
|
+
} catch {
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
})
|
|
799
|
+
)
|
|
800
|
+
];
|
|
801
|
+
if (over.length === 0) return null;
|
|
802
|
+
const prices = over.map((usd) => `$${usd}`).join(" and ");
|
|
803
|
+
const which = over.length > 1 ? "those services" : "that service";
|
|
804
|
+
return `Note: ${prices} ${over.length > 1 ? "are" : "is"} above this machine's automatic per-call limit ($${toMoney(cap.toString()).usd}), so request returns needs_approval for ${which}; ` + (canAskUser ? "prefer one within the limit, or ask the user first." : "use one within the limit.");
|
|
642
805
|
}
|
|
643
806
|
async function walletAddress(dataDir) {
|
|
644
807
|
try {
|
|
@@ -662,40 +825,57 @@ function hookContext(deps) {
|
|
|
662
825
|
async function runPromptHook(raw, deps) {
|
|
663
826
|
const event = decodeEvent(raw);
|
|
664
827
|
if (event?.kind !== "prompt") return { response: null };
|
|
665
|
-
|
|
828
|
+
return offerOnUserText(event, event.prompt, "UserPromptSubmit", deps);
|
|
829
|
+
}
|
|
830
|
+
async function runAnswerHook(raw, deps) {
|
|
831
|
+
const event = decodeEvent(raw);
|
|
832
|
+
if (event?.kind !== "answer" || event.answers === null) return { response: null };
|
|
833
|
+
return offerOnUserText(event, event.answers, "PostToolUse", deps);
|
|
834
|
+
}
|
|
835
|
+
async function offerOnUserText(event, text, hookEventName, deps) {
|
|
836
|
+
const skipped = promptSkipReason(text);
|
|
666
837
|
if (skipped !== null) return { response: null, skipped };
|
|
667
838
|
const router = await routerFor(event.cwd, deps);
|
|
668
839
|
if (router === null) return { response: null };
|
|
669
840
|
const sealed = seal(
|
|
670
|
-
scoped(
|
|
671
|
-
await buildPromptPacket(event.transcriptPath, event.sessionId, event.prompt),
|
|
672
|
-
router.settings
|
|
673
|
-
)
|
|
841
|
+
scoped(await buildPromptPacket(event.transcriptPath, event.sessionId, text), router.settings)
|
|
674
842
|
);
|
|
675
843
|
const footer = await openFooter(deps, event.sessionId, "prompt");
|
|
676
844
|
const deadline = gateDeadline(deps);
|
|
677
|
-
const outcome = await decide(sealed, deps, router.config);
|
|
678
|
-
if (outcome
|
|
845
|
+
const outcome = await decide(sealed, deps, router.config, event.sessionId);
|
|
846
|
+
if (!isOffer(outcome)) {
|
|
679
847
|
await footer.close(outcome);
|
|
680
848
|
return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
|
|
681
849
|
}
|
|
682
|
-
const
|
|
683
|
-
if (withheld !==
|
|
684
|
-
await footer.close(outcome, { withheld });
|
|
685
|
-
return { response: null, action:
|
|
850
|
+
const vetted = await vetOffer(outcome, deps, deadline, true);
|
|
851
|
+
if (vetted.withheld !== void 0) {
|
|
852
|
+
await footer.close(outcome, { withheld: vetted.withheld });
|
|
853
|
+
return { response: null, action: outcome.action, withheld: true };
|
|
686
854
|
}
|
|
687
855
|
await footer.close(outcome);
|
|
688
|
-
return {
|
|
856
|
+
return {
|
|
857
|
+
action: outcome.action,
|
|
858
|
+
id: outcome.id,
|
|
859
|
+
...injection(hookEventName, attributed(vetted.offer.hint))
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function injection(hookEventName, line) {
|
|
863
|
+
return { response: { hookSpecificOutput: { hookEventName, additionalContext: line } } };
|
|
864
|
+
}
|
|
865
|
+
function isOffer(decision) {
|
|
866
|
+
return decision?.action === "execute" || decision?.action === "discovered";
|
|
689
867
|
}
|
|
690
|
-
function
|
|
868
|
+
function termsOf(offer) {
|
|
869
|
+
if (offer.action === "execute") return offer;
|
|
870
|
+
const { candidate } = offer;
|
|
691
871
|
return {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
872
|
+
provider: candidate.provider,
|
|
873
|
+
providerPriceAtomic: candidate.providerPriceAtomic,
|
|
874
|
+
endpoint: candidate.url
|
|
695
875
|
};
|
|
696
876
|
}
|
|
697
877
|
function isFree(offer) {
|
|
698
|
-
return offer.providerPriceAtomic === "0";
|
|
878
|
+
return offer.action === "execute" && offer.providerPriceAtomic === "0";
|
|
699
879
|
}
|
|
700
880
|
async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
701
881
|
const { nativeOutcome, repeated } = opts;
|
|
@@ -704,6 +884,11 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
704
884
|
if (event.agentId !== void 0 && await requestToolAccess(event.agentType, agentLookup(event.cwd, deps)) !== "allowed") {
|
|
705
885
|
return { offer: null, outcome: { response: null, noRequestTool: true } };
|
|
706
886
|
}
|
|
887
|
+
if (opts.redirected !== void 0 && await opts.redirected()) {
|
|
888
|
+
const footer2 = await openFooter(deps, event.sessionId, opts.operation ?? "search");
|
|
889
|
+
await footer2.close(null, { withheld: "already redirected once" });
|
|
890
|
+
return { offer: null, outcome: { response: null, alreadyRedirected: true } };
|
|
891
|
+
}
|
|
707
892
|
const sealed = seal(
|
|
708
893
|
scoped(
|
|
709
894
|
await buildNativePacket(event.transcriptPath, event.sessionId, pending, {
|
|
@@ -729,10 +914,10 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
729
914
|
);
|
|
730
915
|
return { offer: null, outcome: { response: null } };
|
|
731
916
|
}
|
|
732
|
-
const footer = await openFooter(deps, event.sessionId, "search");
|
|
917
|
+
const footer = await openFooter(deps, event.sessionId, opts.operation ?? "search");
|
|
733
918
|
const deadline = gateDeadline(deps);
|
|
734
|
-
const outcome = await decide(sealed, deps, router.config);
|
|
735
|
-
if (outcome
|
|
919
|
+
const outcome = await decide(sealed, deps, router.config, event.sessionId);
|
|
920
|
+
if (!isOffer(outcome)) {
|
|
736
921
|
await footer.close(outcome);
|
|
737
922
|
return {
|
|
738
923
|
offer: null,
|
|
@@ -743,20 +928,25 @@ async function routeNativeCall(event, pending, deps, opts = {}) {
|
|
|
743
928
|
await footer.close(outcome, { withheld: "free lookup, call runs" });
|
|
744
929
|
return { offer: outcome, free: true, baseUrl: resolveBaseUrl(deps, router.config) };
|
|
745
930
|
}
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
931
|
+
const vetted = await vetOffer(
|
|
932
|
+
outcome,
|
|
933
|
+
deps,
|
|
934
|
+
deadline,
|
|
935
|
+
event.agentId === void 0 && opts.canAskUser !== false
|
|
936
|
+
);
|
|
937
|
+
if (vetted.withheld !== void 0) {
|
|
938
|
+
await footer.close(outcome, { withheld: vetted.withheld });
|
|
939
|
+
return { offer: null, outcome: { response: null, action: outcome.action, withheld: true } };
|
|
750
940
|
}
|
|
751
941
|
if (repeated !== void 0 && await repeated()) {
|
|
752
942
|
await footer.close(outcome, { withheld: "already redirected once" });
|
|
753
943
|
return {
|
|
754
944
|
offer: null,
|
|
755
|
-
outcome: { response: null, action:
|
|
945
|
+
outcome: { response: null, action: outcome.action, alreadyRedirected: true }
|
|
756
946
|
};
|
|
757
947
|
}
|
|
758
948
|
await footer.close(outcome);
|
|
759
|
-
return { offer:
|
|
949
|
+
return { offer: vetted.offer };
|
|
760
950
|
}
|
|
761
951
|
async function runNativeHook(raw, deps) {
|
|
762
952
|
const event = decodeEvent(raw);
|
|
@@ -764,7 +954,8 @@ async function runNativeHook(raw, deps) {
|
|
|
764
954
|
const target = redirectTarget(event.pending);
|
|
765
955
|
const routed = await routeNativeCall(event, event.pending, deps, {
|
|
766
956
|
passFree: true,
|
|
767
|
-
repeated: async () => !await claimRedirect(deps.dataDir, event.sessionId, event.agentId, target, deps.now?.())
|
|
957
|
+
repeated: async () => !await claimRedirect(deps.dataDir, event.sessionId, event.agentId, target, deps.now?.()),
|
|
958
|
+
redirected: () => redirectClaimed(deps.dataDir, event.sessionId, event.agentId, target, deps.now?.())
|
|
768
959
|
});
|
|
769
960
|
if (routed.offer === null) return routed.outcome;
|
|
770
961
|
if (routed.free === true) {
|
|
@@ -791,21 +982,41 @@ async function runNativeHook(raw, deps) {
|
|
|
791
982
|
if (event.toolUseId !== void 0) {
|
|
792
983
|
await markOffered(deps.dataDir, event.sessionId, event.toolUseId, deps.now?.());
|
|
793
984
|
}
|
|
985
|
+
return redirect(routed.offer);
|
|
986
|
+
}
|
|
987
|
+
function redirect(offer, oneBlock = ONE_BLOCK) {
|
|
794
988
|
return {
|
|
795
989
|
response: {
|
|
796
990
|
hookSpecificOutput: {
|
|
797
991
|
hookEventName: "PreToolUse",
|
|
798
992
|
permissionDecision: "deny",
|
|
799
993
|
// THE SERVER'S LINE, attributed and tool-named, then this client's one
|
|
800
|
-
// sentence. The line already carries the id and the exact search
|
|
801
|
-
// that was denied.
|
|
802
|
-
permissionDecisionReason: `${attributed(
|
|
994
|
+
// sentence. The line already carries the id and the exact search, URL
|
|
995
|
+
// or question that was denied.
|
|
996
|
+
permissionDecisionReason: `${attributed(offer.hint)} ${oneBlock}`
|
|
803
997
|
}
|
|
804
998
|
},
|
|
805
|
-
action:
|
|
806
|
-
id:
|
|
999
|
+
action: offer.action,
|
|
1000
|
+
id: offer.id
|
|
807
1001
|
};
|
|
808
1002
|
}
|
|
1003
|
+
async function runAskHook(raw, deps) {
|
|
1004
|
+
const event = decodeEvent(raw);
|
|
1005
|
+
if (event?.kind !== "ask" || event.pending === null) return { response: null };
|
|
1006
|
+
const target = redirectTarget(event.pending);
|
|
1007
|
+
const routed = await routeNativeCall(event, event.pending, deps, {
|
|
1008
|
+
passFree: true,
|
|
1009
|
+
operation: "prompt",
|
|
1010
|
+
canAskUser: false,
|
|
1011
|
+
repeated: async () => !await claimRedirect(deps.dataDir, event.sessionId, event.agentId, target, deps.now?.()),
|
|
1012
|
+
redirected: () => redirectClaimed(deps.dataDir, event.sessionId, event.agentId, target, deps.now?.())
|
|
1013
|
+
});
|
|
1014
|
+
if (routed.offer === null) return routed.outcome;
|
|
1015
|
+
if (routed.free === true) {
|
|
1016
|
+
return { response: null, action: routed.offer.action, id: routed.offer.id, free: true };
|
|
1017
|
+
}
|
|
1018
|
+
return redirect(routed.offer, ONE_BLOCK_QUESTION);
|
|
1019
|
+
}
|
|
809
1020
|
async function runShortfallHook(raw, deps) {
|
|
810
1021
|
const event = decodeEvent(raw);
|
|
811
1022
|
if (event?.kind !== "shortfall") return { response: null };
|
|
@@ -840,7 +1051,7 @@ async function offerOnShortfall(event, deps, docsJustMissed = false) {
|
|
|
840
1051
|
}
|
|
841
1052
|
const routed = await routeNativeCall(event, pending, deps, { nativeOutcome });
|
|
842
1053
|
if (routed.offer === null) return { ...routed.outcome, nativeOutcome };
|
|
843
|
-
if (docsJustMissed && routed.offer
|
|
1054
|
+
if (docsJustMissed && isFree(routed.offer))
|
|
844
1055
|
return { response: null, nativeOutcome, action: "execute" };
|
|
845
1056
|
return {
|
|
846
1057
|
response: {
|
|
@@ -852,7 +1063,7 @@ async function offerOnShortfall(event, deps, docsJustMissed = false) {
|
|
|
852
1063
|
}
|
|
853
1064
|
},
|
|
854
1065
|
nativeOutcome,
|
|
855
|
-
action:
|
|
1066
|
+
action: routed.offer.action,
|
|
856
1067
|
id: routed.offer.id
|
|
857
1068
|
};
|
|
858
1069
|
}
|
|
@@ -880,15 +1091,15 @@ async function runDelegationHook(raw, deps) {
|
|
|
880
1091
|
if (sealed.packet.historyStatus !== "ok") return { response: null };
|
|
881
1092
|
const footer = await openFooter(deps, event.sessionId, "delegate");
|
|
882
1093
|
const deadline = gateDeadline(deps);
|
|
883
|
-
const outcome = await decide(sealed, deps, router.config);
|
|
884
|
-
if (outcome
|
|
1094
|
+
const outcome = await decide(sealed, deps, router.config, event.sessionId);
|
|
1095
|
+
if (!isOffer(outcome)) {
|
|
885
1096
|
await footer.close(outcome);
|
|
886
1097
|
return { response: null, ...outcome !== null ? { action: outcome.action } : {} };
|
|
887
1098
|
}
|
|
888
|
-
const
|
|
889
|
-
if (withheld !==
|
|
890
|
-
await footer.close(outcome, { withheld });
|
|
891
|
-
return { response: null, action:
|
|
1099
|
+
const vetted = await vetOffer(outcome, deps, deadline, false);
|
|
1100
|
+
if (vetted.withheld !== void 0) {
|
|
1101
|
+
await footer.close(outcome, { withheld: vetted.withheld });
|
|
1102
|
+
return { response: null, action: outcome.action, withheld: true };
|
|
892
1103
|
}
|
|
893
1104
|
await footer.close(outcome);
|
|
894
1105
|
return {
|
|
@@ -904,7 +1115,7 @@ ${delegationOffer(outcome.hint)}`
|
|
|
904
1115
|
}
|
|
905
1116
|
}
|
|
906
1117
|
},
|
|
907
|
-
action:
|
|
1118
|
+
action: outcome.action,
|
|
908
1119
|
id: outcome.id
|
|
909
1120
|
};
|
|
910
1121
|
}
|
|
@@ -934,7 +1145,7 @@ async function openFooter(deps, sessionId, operation) {
|
|
|
934
1145
|
},
|
|
935
1146
|
now()
|
|
936
1147
|
);
|
|
937
|
-
if (withheld === void 0 && decision
|
|
1148
|
+
if (withheld === void 0 && isOffer(decision)) {
|
|
938
1149
|
await bindDecision(deps.dataDir, sessionId, decision.id, now());
|
|
939
1150
|
}
|
|
940
1151
|
}
|
|
@@ -942,20 +1153,21 @@ async function openFooter(deps, sessionId, operation) {
|
|
|
942
1153
|
}
|
|
943
1154
|
function hookOutcome(decision) {
|
|
944
1155
|
if (decision === null) return "native tools (router unavailable)";
|
|
945
|
-
if (decision
|
|
1156
|
+
if (isOffer(decision)) return `paid lookup offered (${termsOf(decision).provider})`;
|
|
946
1157
|
if (decision.action === "native") return "native tools (no x402 payment)";
|
|
947
1158
|
return "needs input";
|
|
948
1159
|
}
|
|
949
|
-
async function decide({ packet }, deps, config) {
|
|
1160
|
+
async function decide({ packet }, deps, config, sessionId) {
|
|
950
1161
|
const baseUrl = resolveBaseUrl(deps, config);
|
|
951
1162
|
const warn = deps.warn ?? ((line) => process.stderr.write(`${line}
|
|
952
1163
|
`));
|
|
953
1164
|
const outcome = await requestDecision(
|
|
954
1165
|
"hook",
|
|
955
|
-
{ packet },
|
|
1166
|
+
{ packet, sessionId },
|
|
956
1167
|
{
|
|
957
1168
|
ctx: hookContext(deps),
|
|
958
1169
|
baseUrl,
|
|
1170
|
+
acceptsBazaar: resolveExperimentalBazaar(config).value === "on",
|
|
959
1171
|
timeoutMs: deps.timeoutMs ?? GATE_TIMEOUT_MS,
|
|
960
1172
|
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
961
1173
|
}
|
|
@@ -971,6 +1183,7 @@ function nullStream() {
|
|
|
971
1183
|
}
|
|
972
1184
|
function redirectTarget(pending) {
|
|
973
1185
|
if (pending.tool === "WebSearch") return `WebSearch ${pending.query}`;
|
|
1186
|
+
if (pending.tool === "AskUserQuestion") return `AskUserQuestion ${pending.question}`;
|
|
974
1187
|
let url = pending.url;
|
|
975
1188
|
try {
|
|
976
1189
|
url = new URL(url).toString();
|
|
@@ -1012,7 +1225,7 @@ async function runHookCommand(kind, io, deps) {
|
|
|
1012
1225
|
try {
|
|
1013
1226
|
const raw = await (deps.readEvent ?? readStdin)();
|
|
1014
1227
|
const event = JSON.parse(raw);
|
|
1015
|
-
const outcome = kind === "prompt" ? await runPromptHook(event, deps) : kind === "native" ? await runNativeHook(event, deps) : kind === "shortfall" ? await runShortfallHook(event, deps) : await runDelegationHook(event, deps);
|
|
1228
|
+
const outcome = kind === "prompt" ? await runPromptHook(event, deps) : kind === "native" ? await runNativeHook(event, deps) : kind === "shortfall" ? await runShortfallHook(event, deps) : kind === "ask" ? await runAskHook(event, deps) : kind === "answer" ? await runAnswerHook(event, deps) : await runDelegationHook(event, deps);
|
|
1016
1229
|
response = outcome.response;
|
|
1017
1230
|
} catch {
|
|
1018
1231
|
response = null;
|
|
@@ -1049,4 +1262,4 @@ export {
|
|
|
1049
1262
|
STDIN_TIMEOUT_MS,
|
|
1050
1263
|
runHookCommand
|
|
1051
1264
|
};
|
|
1052
|
-
//# sourceMappingURL=hook-command-
|
|
1265
|
+
//# sourceMappingURL=hook-command-VVV2Q23L.js.map
|