claudish 14.29.1 → 14.29.2
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/hooks.d.ts +7 -1
- package/dist/index.js +213 -113
- package/package.json +5 -5
package/dist/hooks.d.ts
CHANGED
|
@@ -237,8 +237,14 @@ export interface SessionIdleContext extends BaseContext {
|
|
|
237
237
|
readonly turn: {
|
|
238
238
|
/** 1-based within the session; a re-woken turn keeps its index */
|
|
239
239
|
index: number;
|
|
240
|
-
/** this turn's assistant text */
|
|
240
|
+
/** this turn's assistant text; "" when `answerWithheld` */
|
|
241
241
|
answer: string;
|
|
242
|
+
/**
|
|
243
|
+
* the turn's prompt went as a task file, and the model's Read tool calls in the main
|
|
244
|
+
* conversation did not return all of it: `answer` is "" whatever the model wrote. Reading
|
|
245
|
+
* it another way (a shell `cat`, a subagent) does not count as reading it.
|
|
246
|
+
*/
|
|
247
|
+
answerWithheld: boolean;
|
|
242
248
|
stopReason: string | null;
|
|
243
249
|
apiError: boolean;
|
|
244
250
|
/** this turn was started by an injection */
|
package/dist/index.js
CHANGED
|
@@ -5542,7 +5542,7 @@ var init_env_placeholder = __esm(() => {
|
|
|
5542
5542
|
});
|
|
5543
5543
|
|
|
5544
5544
|
// src/version.ts
|
|
5545
|
-
var VERSION = "14.29.
|
|
5545
|
+
var VERSION = "14.29.2";
|
|
5546
5546
|
|
|
5547
5547
|
// src/redact.ts
|
|
5548
5548
|
function isPlaceholder(value) {
|
|
@@ -14123,7 +14123,7 @@ var init_bundled_recommended_list = __esm(() => {
|
|
|
14123
14123
|
}
|
|
14124
14124
|
}
|
|
14125
14125
|
},
|
|
14126
|
-
fetchedAt: "2026-11-
|
|
14126
|
+
fetchedAt: "2026-11-26T09:10:24.949Z",
|
|
14127
14127
|
format: 1,
|
|
14128
14128
|
recommendations: {
|
|
14129
14129
|
contractVersion: 3,
|
|
@@ -67320,9 +67320,8 @@ function proxyProvesInBandError(code, record, turnStartedAt) {
|
|
|
67320
67320
|
return false;
|
|
67321
67321
|
return record.code === inBandErrorCodeKey(code);
|
|
67322
67322
|
}
|
|
67323
|
-
function parseInBandApiError(answer
|
|
67324
|
-
const
|
|
67325
|
-
const m = /^\[API Error: (\S+)([\s\S]*)\]$/.exec(trimmed) ?? (opts.trailing ? /\n\n\[API Error: (\S+)([^\n\]]*)\]$/.exec(trimmed) : null);
|
|
67323
|
+
function parseInBandApiError(answer) {
|
|
67324
|
+
const m = /^\[API Error: (\S+)([\s\S]*)\]$/.exec(answer.trim());
|
|
67326
67325
|
if (!m)
|
|
67327
67326
|
return null;
|
|
67328
67327
|
return { code: m[1], text: `${m[1]}${m[2]}` };
|
|
@@ -90020,6 +90019,7 @@ class EngineSessionHookBinding {
|
|
|
90020
90019
|
turn: Object.freeze({
|
|
90021
90020
|
index: turn.index,
|
|
90022
90021
|
answer: turn.answer,
|
|
90022
|
+
answerWithheld: turn.answerWithheld ?? false,
|
|
90023
90023
|
stopReason: turn.stopReason,
|
|
90024
90024
|
apiError: turn.apiError,
|
|
90025
90025
|
hookCaused: turn.hookCaused,
|
|
@@ -90976,13 +90976,27 @@ function renderTurnFile(text, limit = READ_LINE_LIMIT) {
|
|
|
90976
90976
|
function turnFilePath(turnDir, turnIndex) {
|
|
90977
90977
|
return join40(turnDir, `turn-${turnIndex}.md`);
|
|
90978
90978
|
}
|
|
90979
|
+
function turnFileToken(file) {
|
|
90980
|
+
return `\`${file}\``;
|
|
90981
|
+
}
|
|
90979
90982
|
function fileTemplate(file, marker) {
|
|
90980
|
-
const base = `Your task is in the file
|
|
90983
|
+
const base = `Your task is in the file ${turnFileToken(file)}. Read all of it with the Read tool (in parts if it is long), then do exactly what it says, treating its content as the user's message.`;
|
|
90981
90984
|
return marker ? `${base} Lines ending in ${marker} were split for reading: join each with the next line, dropping the ${marker}.` : base;
|
|
90982
90985
|
}
|
|
90983
90986
|
function commandPointer(name, file) {
|
|
90984
90987
|
return `/${name} \u2014 the full arguments are in the file \`${file}\`; read all of it first.`;
|
|
90985
90988
|
}
|
|
90989
|
+
function typedPlan(text, readAvailable) {
|
|
90990
|
+
if (isPlainLine(text))
|
|
90991
|
+
return { mode: "typed", line: text, witness: { kind: "text", text } };
|
|
90992
|
+
const line = normalizedLine(text);
|
|
90993
|
+
if (isPlainLine(line))
|
|
90994
|
+
return { mode: "typed", line, witness: { kind: "text", text: line }, normalized: true };
|
|
90995
|
+
return {
|
|
90996
|
+
mode: "refused",
|
|
90997
|
+
reason: readAvailable ? "the prompt is not a plain single line and the session has no turn directory, so it cannot be delivered as a file" : "the prompt is not a plain single line and the Read tool is unavailable, so it cannot be delivered as a file"
|
|
90998
|
+
};
|
|
90999
|
+
}
|
|
90986
91000
|
function planDelivery(text, turnDir, turnIndex, readAvailable) {
|
|
90987
91001
|
const trimmed = text.trim();
|
|
90988
91002
|
if (trimmed === "/exit" || trimmed === "/quit")
|
|
@@ -91020,17 +91034,8 @@ function planDelivery(text, turnDir, turnIndex, readAvailable) {
|
|
|
91020
91034
|
lines: tf.lines
|
|
91021
91035
|
};
|
|
91022
91036
|
}
|
|
91023
|
-
if (
|
|
91024
|
-
return
|
|
91025
|
-
if (!readAvailable) {
|
|
91026
|
-
const line = normalizedLine(text);
|
|
91027
|
-
if (isPlainLine(line))
|
|
91028
|
-
return { mode: "typed", line, witness: { kind: "text", text: line }, normalized: true };
|
|
91029
|
-
return {
|
|
91030
|
-
mode: "refused",
|
|
91031
|
-
reason: "the prompt is not a plain single line and the Read tool is unavailable, so it cannot be delivered as a file"
|
|
91032
|
-
};
|
|
91033
|
-
}
|
|
91037
|
+
if (!readAvailable || turnDir === "")
|
|
91038
|
+
return typedPlan(text, readAvailable);
|
|
91034
91039
|
const file = turnFilePath(turnDir, turnIndex);
|
|
91035
91040
|
const tf = renderTurnFile(text);
|
|
91036
91041
|
const line = fileTemplate(file, tf.marker);
|
|
@@ -91040,7 +91045,7 @@ function planDelivery(text, turnDir, turnIndex, readAvailable) {
|
|
|
91040
91045
|
file,
|
|
91041
91046
|
fileContent: tf.content,
|
|
91042
91047
|
lines: tf.lines,
|
|
91043
|
-
witness: { kind: "
|
|
91048
|
+
witness: { kind: "turn_file", file, line }
|
|
91044
91049
|
};
|
|
91045
91050
|
}
|
|
91046
91051
|
function deliveryRefusal(text, readAvailable) {
|
|
@@ -91182,12 +91187,12 @@ function flatText(lines) {
|
|
|
91182
91187
|
function squash(s) {
|
|
91183
91188
|
return s.replace(/\s+/g, "");
|
|
91184
91189
|
}
|
|
91190
|
+
function renderedInline(line) {
|
|
91191
|
+
return line.replace(/(`+)(?!`)([\s\S]*?[^`])\1(?!`)/g, "$2").replace(/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1").replace(/\*(?=[^\s*])([^*]*?[^\s*])?\*/g, (m, inner) => inner === undefined ? m : inner).replace(/~~(?=\S)([\s\S]*?\S)~~/g, "$1").replace(/~(?=[^\s~])([^~]*?[^\s~])?~/g, (m, inner) => inner === undefined ? m : inner);
|
|
91192
|
+
}
|
|
91185
91193
|
function echoHeadLength(cols) {
|
|
91186
91194
|
return Math.max(1, Math.min(40, cols - 4));
|
|
91187
91195
|
}
|
|
91188
|
-
function echoHead(line, cols) {
|
|
91189
|
-
return line.slice(0, echoHeadLength(cols));
|
|
91190
|
-
}
|
|
91191
91196
|
function visibleText2(line, spans) {
|
|
91192
91197
|
if (!spans?.length)
|
|
91193
91198
|
return line;
|
|
@@ -91200,26 +91205,59 @@ function visibleText2(line, spans) {
|
|
|
91200
91205
|
}
|
|
91201
91206
|
return chars.join("");
|
|
91202
91207
|
}
|
|
91203
|
-
function echoAt(lines, i,
|
|
91208
|
+
function echoAt(lines, i, line, headLength = Number.POSITIVE_INFINITY) {
|
|
91204
91209
|
const first = lines[i] ?? "";
|
|
91205
91210
|
if (!first.startsWith("\u276F "))
|
|
91206
91211
|
return false;
|
|
91207
|
-
const
|
|
91212
|
+
const wants = [line, renderedInline(line)].map((l) => squash(l.slice(0, headLength))).filter((w) => w.length > 0);
|
|
91213
|
+
if (wants.length === 0)
|
|
91214
|
+
return false;
|
|
91215
|
+
const longest = Math.max(...wants.map((w) => w.length));
|
|
91208
91216
|
let got = squash(first.slice(2));
|
|
91209
|
-
for (let j = i + 1;got.length <
|
|
91217
|
+
for (let j = i + 1;got.length < longest && j < lines.length; j++) {
|
|
91210
91218
|
const row = lines[j] ?? "";
|
|
91211
91219
|
if (!/^ {2}\S/.test(row))
|
|
91212
91220
|
break;
|
|
91213
91221
|
got += squash(row);
|
|
91214
91222
|
}
|
|
91215
|
-
return got.startsWith(
|
|
91223
|
+
return wants.some((w) => got.startsWith(w));
|
|
91216
91224
|
}
|
|
91217
|
-
function hasEcho(lines,
|
|
91225
|
+
function hasEcho(lines, line, headLength = Number.POSITIVE_INFINITY) {
|
|
91218
91226
|
for (let i = 0;i < lines.length; i++)
|
|
91219
|
-
if (echoAt(lines, i,
|
|
91227
|
+
if (echoAt(lines, i, line, headLength))
|
|
91220
91228
|
return true;
|
|
91221
91229
|
return false;
|
|
91222
91230
|
}
|
|
91231
|
+
function squashedEchoAt(lines, i) {
|
|
91232
|
+
const first = lines[i] ?? "";
|
|
91233
|
+
if (!first.startsWith("\u276F "))
|
|
91234
|
+
return null;
|
|
91235
|
+
let got = squash(first.slice(2));
|
|
91236
|
+
for (let j = i + 1;j < lines.length; j++) {
|
|
91237
|
+
const row = lines[j] ?? "";
|
|
91238
|
+
if (!/^ {2}\S/.test(row))
|
|
91239
|
+
break;
|
|
91240
|
+
got += squash(row);
|
|
91241
|
+
}
|
|
91242
|
+
return got;
|
|
91243
|
+
}
|
|
91244
|
+
function pointerEchoAt(lines, i, line) {
|
|
91245
|
+
return squashedEchoAt(lines, i)?.startsWith(squash(renderedInline(line))) ?? false;
|
|
91246
|
+
}
|
|
91247
|
+
function echoRowOf(lines, end, line, turnFile, headLength = Number.POSITIVE_INFINITY) {
|
|
91248
|
+
const above = lines.slice(0, end);
|
|
91249
|
+
for (let i = end - 1;i >= 0; i--)
|
|
91250
|
+
if (turnFile === null ? echoAt(above, i, line, headLength) : pointerEchoAt(above, i, line))
|
|
91251
|
+
return i;
|
|
91252
|
+
return -1;
|
|
91253
|
+
}
|
|
91254
|
+
function lineSubmittedOnScreen(lines, line, turnFile) {
|
|
91255
|
+
if (turnFile === null) {
|
|
91256
|
+
const head = line.slice(0, 40);
|
|
91257
|
+
return lines.some((l) => l.startsWith(`\u276F ${head}`));
|
|
91258
|
+
}
|
|
91259
|
+
return echoRowOf(lines, lines.length, line, turnFile) >= 0;
|
|
91260
|
+
}
|
|
91223
91261
|
function inputBox(s) {
|
|
91224
91262
|
const top = boxTopRow(s.lines, s.cols);
|
|
91225
91263
|
if (top < 0)
|
|
@@ -91323,11 +91361,11 @@ function isToolHeader(lines, i) {
|
|
|
91323
91361
|
}
|
|
91324
91362
|
return false;
|
|
91325
91363
|
}
|
|
91326
|
-
function screenAnswer(s, echo) {
|
|
91364
|
+
function screenAnswer(s, echo, turnFile = null) {
|
|
91327
91365
|
const lines = s.lines;
|
|
91328
91366
|
const top = boxTopRow(lines, s.cols);
|
|
91329
91367
|
const end = top >= 0 ? top : lines.length;
|
|
91330
|
-
const start =
|
|
91368
|
+
const start = echoRowOf(lines, end, echo, turnFile, echoHeadLength(s.cols)) + 1;
|
|
91331
91369
|
if (start <= 0)
|
|
91332
91370
|
return "";
|
|
91333
91371
|
const out = [];
|
|
@@ -91341,13 +91379,6 @@ function screenAnswer(s, echo) {
|
|
|
91341
91379
|
return out.join(`
|
|
91342
91380
|
`).trim();
|
|
91343
91381
|
}
|
|
91344
|
-
function echoRow(lines, end, head) {
|
|
91345
|
-
const above = lines.slice(0, end);
|
|
91346
|
-
for (let i = end - 1;i >= 0; i--)
|
|
91347
|
-
if (echoAt(above, i, head))
|
|
91348
|
-
return i;
|
|
91349
|
-
return -1;
|
|
91350
|
-
}
|
|
91351
91382
|
function answerRow(lines, i, inProse) {
|
|
91352
91383
|
const l = lines[i] ?? "";
|
|
91353
91384
|
if (BULLET.test(l)) {
|
|
@@ -91551,6 +91582,43 @@ var init_settle_rule = __esm(() => {
|
|
|
91551
91582
|
CORROBORATION_GRACE_MS = SECONDARY_QUIET_MS;
|
|
91552
91583
|
});
|
|
91553
91584
|
|
|
91585
|
+
// src/pane/settled-turn.ts
|
|
91586
|
+
function answerOf(t, mode) {
|
|
91587
|
+
return answerWithheld(t, mode) ? "" : t.assistantText.join(`
|
|
91588
|
+
|
|
91589
|
+
`);
|
|
91590
|
+
}
|
|
91591
|
+
function answerWithheld(t, mode) {
|
|
91592
|
+
if (!t.delivery || t.readCoverage.complete)
|
|
91593
|
+
return false;
|
|
91594
|
+
return !(mode === "command" && t.readCoverage.reads === 0);
|
|
91595
|
+
}
|
|
91596
|
+
function settledTurnCoreOf(t, decision, ctx) {
|
|
91597
|
+
const d = ctx.delivery;
|
|
91598
|
+
const unverified = d?.mode === "command" && !!t.delivery && t.readCoverage.reads === 0;
|
|
91599
|
+
const local = decision.by === "local_command";
|
|
91600
|
+
const core = {
|
|
91601
|
+
index: t.index,
|
|
91602
|
+
answer: local ? t.localCommandOutput ?? "" : answerOf(t, d?.mode ?? null),
|
|
91603
|
+
...local || !t.lastResponseEnd ? {} : { lastResponseEnd: t.lastResponseEnd },
|
|
91604
|
+
acceptedAt: t.acceptedAt,
|
|
91605
|
+
apiError: t.apiError,
|
|
91606
|
+
stopReason: decision.stopReason,
|
|
91607
|
+
captureSource: "transcript",
|
|
91608
|
+
settledBy: decision.by,
|
|
91609
|
+
shape: ctx.shape,
|
|
91610
|
+
delivery: {
|
|
91611
|
+
mode: d && d.mode !== "refused" ? d.mode : "typed",
|
|
91612
|
+
linesTotal: t.delivery ? t.delivery.lines : null,
|
|
91613
|
+
linesRead: t.delivery ? t.readCoverage.linesReturned : null,
|
|
91614
|
+
complete: t.delivery && !unverified ? t.readCoverage.complete : null,
|
|
91615
|
+
preambleBytes: t.preambleBytes
|
|
91616
|
+
},
|
|
91617
|
+
writtenFiles: local ? [] : t.writtenFiles
|
|
91618
|
+
};
|
|
91619
|
+
return { core, unverified };
|
|
91620
|
+
}
|
|
91621
|
+
|
|
91554
91622
|
// src/pane/slot-steps.ts
|
|
91555
91623
|
function oneLine6(text) {
|
|
91556
91624
|
if (typeof text !== "string")
|
|
@@ -92026,18 +92094,43 @@ function wholeCopies(text, line) {
|
|
|
92026
92094
|
const core = line.trim();
|
|
92027
92095
|
if (!core)
|
|
92028
92096
|
return got === core ? 1 : 0;
|
|
92029
|
-
|
|
92030
|
-
|
|
92031
|
-
|
|
92032
|
-
|
|
92033
|
-
|
|
92034
|
-
|
|
92035
|
-
|
|
92036
|
-
|
|
92097
|
+
if (got.length % core.length !== 0)
|
|
92098
|
+
return 0;
|
|
92099
|
+
const k = got.length / core.length;
|
|
92100
|
+
return k >= 1 && got === core.repeat(k) ? k : 0;
|
|
92101
|
+
}
|
|
92102
|
+
function isPromptRecord(r) {
|
|
92103
|
+
if (!isMainUser(r) || r.isMeta || hasToolResult(r) || r.isCompactSummary)
|
|
92104
|
+
return false;
|
|
92105
|
+
if (isTaskNotification(r))
|
|
92106
|
+
return false;
|
|
92107
|
+
const origin = r.origin;
|
|
92108
|
+
return origin === undefined || origin === null || origin?.kind === "human";
|
|
92109
|
+
}
|
|
92110
|
+
function countOccurrences(text, token) {
|
|
92111
|
+
if (!token)
|
|
92112
|
+
return 0;
|
|
92113
|
+
let n = 0;
|
|
92114
|
+
for (let at = text.indexOf(token);at >= 0; at = text.indexOf(token, at + token.length))
|
|
92115
|
+
n++;
|
|
92116
|
+
return n;
|
|
92117
|
+
}
|
|
92118
|
+
function turnFileCopies(r, w) {
|
|
92119
|
+
return isPromptRecord(r) ? countOccurrences(userText2(r), turnFileToken(w.file)) : 0;
|
|
92120
|
+
}
|
|
92121
|
+
function carriesPointerInto(r, turnDir) {
|
|
92122
|
+
const open = turnFileToken(join41(turnDir, "turn-")).slice(0, -1);
|
|
92123
|
+
const text = userText2(r);
|
|
92124
|
+
for (let at = text.indexOf(open);at !== -1; at = text.indexOf(open, at + 1))
|
|
92125
|
+
if (/^\d+\.md`/.test(text.slice(at + open.length)))
|
|
92126
|
+
return true;
|
|
92127
|
+
return false;
|
|
92037
92128
|
}
|
|
92038
92129
|
function matchesWitness(r, w) {
|
|
92039
92130
|
if (w.kind === "human")
|
|
92040
|
-
return isHumanPrompt(r);
|
|
92131
|
+
return isHumanPrompt(r) && !(w.notTurnDir && carriesPointerInto(r, w.notTurnDir));
|
|
92132
|
+
if (w.kind === "turn_file")
|
|
92133
|
+
return turnFileCopies(r, w) > 0;
|
|
92041
92134
|
if (w.kind === "command" && isLocalCommandSystem(r))
|
|
92042
92135
|
return isCommandRecordOf(String(r.content ?? ""), w);
|
|
92043
92136
|
if (!isMainUser(r) || hasToolResult(r))
|
|
@@ -92337,6 +92430,8 @@ function takeDepartedRecord(state, r, offset) {
|
|
|
92337
92430
|
return true;
|
|
92338
92431
|
}
|
|
92339
92432
|
function isOneCopyOf(r, w) {
|
|
92433
|
+
if (w.kind === "turn_file")
|
|
92434
|
+
return false;
|
|
92340
92435
|
if (w.kind === "text")
|
|
92341
92436
|
return isMainUser(r) && !r.isMeta && !hasToolResult(r) && userText2(r).trim() === w.text.trim();
|
|
92342
92437
|
return w.kind === "command" && matchesWitness(r, w);
|
|
@@ -92349,6 +92444,8 @@ function acceptUnlessHeld(state, t, r, offset, departed) {
|
|
|
92349
92444
|
}
|
|
92350
92445
|
function heldMayAccept(state, t, r) {
|
|
92351
92446
|
const w = t.witness;
|
|
92447
|
+
if (w.kind === "turn_file")
|
|
92448
|
+
return matchesWitness(r, w);
|
|
92352
92449
|
const c = state.copy?.witness;
|
|
92353
92450
|
if (w.kind === "command")
|
|
92354
92451
|
return c?.kind === "command" && c.name === w.name && c.line === w.line && matchesWitness(r, w);
|
|
@@ -92361,9 +92458,16 @@ function acceptIfWitness(t, r, offset) {
|
|
|
92361
92458
|
return;
|
|
92362
92459
|
t.acceptedAt = typeof r.timestamp === "string" ? r.timestamp : new Date().toISOString();
|
|
92363
92460
|
t.acceptedOffset = offset;
|
|
92364
|
-
t.witnessCopies =
|
|
92461
|
+
t.witnessCopies = witnessCopiesOf(r, t.witness);
|
|
92365
92462
|
t.lastChatOffset = offset;
|
|
92366
92463
|
}
|
|
92464
|
+
function witnessCopiesOf(r, w) {
|
|
92465
|
+
if (w.kind === "text")
|
|
92466
|
+
return wholeCopies(userText2(r), w.text);
|
|
92467
|
+
if (w.kind === "turn_file")
|
|
92468
|
+
return turnFileCopies(r, w);
|
|
92469
|
+
return 1;
|
|
92470
|
+
}
|
|
92367
92471
|
function noteMainAssistant(state, r) {
|
|
92368
92472
|
const id = r.type === "assistant" ? r.message?.id : undefined;
|
|
92369
92473
|
if (typeof id !== "string" || !id)
|
|
@@ -92399,8 +92503,7 @@ function applyRecord(state, record, offset) {
|
|
|
92399
92503
|
t.shadow = null;
|
|
92400
92504
|
return state;
|
|
92401
92505
|
}
|
|
92402
|
-
|
|
92403
|
-
t.unwitnessedChat = offset;
|
|
92506
|
+
noteUnwitnessed(t, r, offset);
|
|
92404
92507
|
if (t.shadow)
|
|
92405
92508
|
foldTurnRecord(state, t.shadow, r, offset);
|
|
92406
92509
|
return state;
|
|
@@ -92422,6 +92525,19 @@ function foldTurnRecord(state, t, r, offset) {
|
|
|
92422
92525
|
applyTurnDuration(state, t, r);
|
|
92423
92526
|
applyQueuedNotification(t, r);
|
|
92424
92527
|
}
|
|
92528
|
+
function noteUnwitnessed(t, r, offset) {
|
|
92529
|
+
if (t.foreignPointerAt !== null && r.type === "system" && r.subtype === "turn_duration") {
|
|
92530
|
+
t.foreignPointerAt = null;
|
|
92531
|
+
return;
|
|
92532
|
+
}
|
|
92533
|
+
if (t.foreignPointerAt === null && isForeignPointer(r, t.witness))
|
|
92534
|
+
t.foreignPointerAt = offset;
|
|
92535
|
+
if (t.unwitnessedChat === null && t.foreignPointerAt === null && wakesModel(r))
|
|
92536
|
+
t.unwitnessedChat = offset;
|
|
92537
|
+
}
|
|
92538
|
+
function isForeignPointer(r, w) {
|
|
92539
|
+
return w.kind === "human" && !!w.notTurnDir && isPromptRecord(r) && carriesPointerInto(r, w.notTurnDir);
|
|
92540
|
+
}
|
|
92425
92541
|
function wakesModel(r) {
|
|
92426
92542
|
if (r.type === "assistant")
|
|
92427
92543
|
return true;
|
|
@@ -92495,6 +92611,7 @@ function newTurnState(t) {
|
|
|
92495
92611
|
localOutput: null,
|
|
92496
92612
|
steps: [],
|
|
92497
92613
|
unwitnessedChat: null,
|
|
92614
|
+
foreignPointerAt: null,
|
|
92498
92615
|
witnessCopies: null,
|
|
92499
92616
|
shadow: null
|
|
92500
92617
|
};
|
|
@@ -92789,6 +92906,7 @@ function parseRecord3(line) {
|
|
|
92789
92906
|
}
|
|
92790
92907
|
var LOCAL_COMMAND_RE, INTERRUPT_PREFIX = "[Request interrupted by user", COMMAND_TAG, STDOUT_RE, ANSI_RE, AGENT_FILE_RE, AGENT_META_RE;
|
|
92791
92908
|
var init_transcript_follower = __esm(() => {
|
|
92909
|
+
init_prompt_delivery();
|
|
92792
92910
|
init_slot_steps();
|
|
92793
92911
|
init_subagent_ledger();
|
|
92794
92912
|
LOCAL_COMMAND_RE = /^\s*<(local-command-caveat|command-name|local-command-stdout|local-command-stderr)>/;
|
|
@@ -93698,7 +93816,7 @@ class InteractiveDriver {
|
|
|
93698
93816
|
const turn = {
|
|
93699
93817
|
index: this.lastAcceptedIndex + 1,
|
|
93700
93818
|
offset,
|
|
93701
|
-
witness: { kind: "human" },
|
|
93819
|
+
witness: { kind: "human", notTurnDir: this.o.turnDir },
|
|
93702
93820
|
delivery: null,
|
|
93703
93821
|
hookCaused: false
|
|
93704
93822
|
};
|
|
@@ -93815,9 +93933,8 @@ class InteractiveDriver {
|
|
|
93815
93933
|
this.settledTurn = cur;
|
|
93816
93934
|
const info = {
|
|
93817
93935
|
index: cur.index,
|
|
93818
|
-
answer: localCommand ? t.localCommandOutput ?? "" : t
|
|
93819
|
-
|
|
93820
|
-
`),
|
|
93936
|
+
answer: localCommand ? t.localCommandOutput ?? "" : answerOf(t, null),
|
|
93937
|
+
answerWithheld: !localCommand && answerWithheld(t, null),
|
|
93821
93938
|
stopReason,
|
|
93822
93939
|
apiError: t.apiError !== null,
|
|
93823
93940
|
hookCaused: cur.hookCaused,
|
|
@@ -94021,6 +94138,7 @@ class InteractiveDriver {
|
|
|
94021
94138
|
} catch {}
|
|
94022
94139
|
this.transition("deliver");
|
|
94023
94140
|
const adm = this.admission;
|
|
94141
|
+
const turnFile = plan.mode === "file" ? plan.file : null;
|
|
94024
94142
|
const rt = SEND_READY_WAIT_DEFAULT_MS;
|
|
94025
94143
|
const timeout = sendBudgetMs({ readyTimeoutMs: rt, text: plan.line, keys: 1, submit: true }) + SEND_CLIENT_SLACK_MS;
|
|
94026
94144
|
client.request({ type: "send", pane, text: plan.line, typed: true, enter: true, readyTimeoutMs: rt }, timeout).then(async (r) => {
|
|
@@ -94028,7 +94146,7 @@ class InteractiveDriver {
|
|
|
94028
94146
|
return;
|
|
94029
94147
|
const out = classifySendReply(r);
|
|
94030
94148
|
if (out.kind === "reply_lost" && out.code !== "timeout") {
|
|
94031
|
-
if (await this.landedAfterLostReply(adm, pane, plan.line))
|
|
94149
|
+
if (await this.landedAfterLostReply(adm, pane, plan.line, turnFile))
|
|
94032
94150
|
return;
|
|
94033
94151
|
} else if (out.kind === "not_accepted" && enterMayHaveBeenPressed(out)) {
|
|
94034
94152
|
log(`[hooks] interactive driver: send not confirmed (${out.reason}); awaiting the witness`);
|
|
@@ -94038,8 +94156,7 @@ class InteractiveDriver {
|
|
|
94038
94156
|
this.step(() => this.admitFailed(`send refused: ${r.code} ${r.error}`));
|
|
94039
94157
|
});
|
|
94040
94158
|
}
|
|
94041
|
-
async landedAfterLostReply(adm, pane, line) {
|
|
94042
|
-
const head = line.slice(0, 40);
|
|
94159
|
+
async landedAfterLostReply(adm, pane, line, turnFile) {
|
|
94043
94160
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
94044
94161
|
const seen = this.screen.seq;
|
|
94045
94162
|
const client = await this.connectedClient(RECONNECT_WAIT_MS);
|
|
@@ -94055,8 +94172,10 @@ class InteractiveDriver {
|
|
|
94055
94172
|
if (r.ok)
|
|
94056
94173
|
return true;
|
|
94057
94174
|
log(`[hooks] interactive driver: Enter after a lost reply: ${r.code} ${r.error}`);
|
|
94175
|
+
if (enterMayHaveLanded(classifySendReply(r)))
|
|
94176
|
+
return true;
|
|
94058
94177
|
}
|
|
94059
|
-
const landed = this.submitted(
|
|
94178
|
+
const landed = this.submitted(line, turnFile);
|
|
94060
94179
|
if (landed)
|
|
94061
94180
|
log("[hooks] interactive driver: send reply lost; the line was submitted");
|
|
94062
94181
|
return landed;
|
|
@@ -94076,9 +94195,9 @@ class InteractiveDriver {
|
|
|
94076
94195
|
}
|
|
94077
94196
|
return false;
|
|
94078
94197
|
}
|
|
94079
|
-
submitted(
|
|
94198
|
+
submitted(line, turnFile) {
|
|
94080
94199
|
const t = this.pollFollower(true)?.current;
|
|
94081
|
-
return (t?.acceptedAt ?? null) !== null || this.screen.lines
|
|
94200
|
+
return (t?.acceptedAt ?? null) !== null || lineSubmittedOnScreen(this.screen.lines, line, turnFile);
|
|
94082
94201
|
}
|
|
94083
94202
|
async connectedClient(ms) {
|
|
94084
94203
|
const end = Date.now() + ms;
|
|
@@ -94124,6 +94243,11 @@ function screenNotIdleReason(screen) {
|
|
|
94124
94243
|
return "no_input_box";
|
|
94125
94244
|
return box.text === "" ? null : "box_not_empty";
|
|
94126
94245
|
}
|
|
94246
|
+
function enterMayHaveLanded(o) {
|
|
94247
|
+
if (o.kind === "reply_lost")
|
|
94248
|
+
return true;
|
|
94249
|
+
return o.kind === "not_accepted" && enterMayHaveBeenPressed(o);
|
|
94250
|
+
}
|
|
94127
94251
|
function enterMayHaveBeenPressed(o) {
|
|
94128
94252
|
return o.reason === "still_in_box" || o.reason === "unconfirmed" || o.maybeSubmitted;
|
|
94129
94253
|
}
|
|
@@ -117217,7 +117341,7 @@ function inBandErrorOf(input) {
|
|
|
117217
117341
|
const proven = marker !== null && proxyProvesInBandError(marker.code, input.proxyInBandError, input.turnStartedAt);
|
|
117218
117342
|
return proven ? marker : null;
|
|
117219
117343
|
}
|
|
117220
|
-
return parseInBandApiError(input.answer
|
|
117344
|
+
return parseInBandApiError(input.answer);
|
|
117221
117345
|
}
|
|
117222
117346
|
function classifyTurnSignals(input) {
|
|
117223
117347
|
const { stopReason, promptRead } = input;
|
|
@@ -121716,35 +121840,6 @@ var init_session_registry = __esm(() => {
|
|
|
121716
121840
|
KNOWN_STATUSES = new Set(["idle", "busy", "waiting", "shell"]);
|
|
121717
121841
|
});
|
|
121718
121842
|
|
|
121719
|
-
// src/pane/settled-turn.ts
|
|
121720
|
-
function settledTurnCoreOf(t, decision, ctx) {
|
|
121721
|
-
const d = ctx.delivery;
|
|
121722
|
-
const unverified = d?.mode === "command" && !!t.delivery && t.readCoverage.reads === 0;
|
|
121723
|
-
const local = decision.by === "local_command";
|
|
121724
|
-
const core = {
|
|
121725
|
-
index: t.index,
|
|
121726
|
-
answer: local ? t.localCommandOutput ?? "" : t.assistantText.join(`
|
|
121727
|
-
|
|
121728
|
-
`),
|
|
121729
|
-
...local || !t.lastResponseEnd ? {} : { lastResponseEnd: t.lastResponseEnd },
|
|
121730
|
-
acceptedAt: t.acceptedAt,
|
|
121731
|
-
apiError: t.apiError,
|
|
121732
|
-
stopReason: decision.stopReason,
|
|
121733
|
-
captureSource: "transcript",
|
|
121734
|
-
settledBy: decision.by,
|
|
121735
|
-
shape: ctx.shape,
|
|
121736
|
-
delivery: {
|
|
121737
|
-
mode: d && d.mode !== "refused" ? d.mode : "typed",
|
|
121738
|
-
linesTotal: t.delivery ? t.delivery.lines : null,
|
|
121739
|
-
linesRead: t.delivery ? t.readCoverage.linesReturned : null,
|
|
121740
|
-
complete: t.delivery && !unverified ? t.readCoverage.complete : null,
|
|
121741
|
-
preambleBytes: t.preambleBytes
|
|
121742
|
-
},
|
|
121743
|
-
writtenFiles: local ? [] : t.writtenFiles
|
|
121744
|
-
};
|
|
121745
|
-
return { core, unverified };
|
|
121746
|
-
}
|
|
121747
|
-
|
|
121748
121843
|
// src/pane/slot-state.ts
|
|
121749
121844
|
function nextPhase(from, ev) {
|
|
121750
121845
|
const row = TRANSITIONS2[from];
|
|
@@ -122855,20 +122950,15 @@ ${gate}`
|
|
|
122855
122950
|
this.abandonedIndex = null;
|
|
122856
122951
|
if (plan.mode === "refused" || plan.mode === "control") {
|
|
122857
122952
|
this.anomaly(`delivery_refused:${plan.mode === "refused" ? plan.reason : "control"}`);
|
|
122858
|
-
this.
|
|
122859
|
-
if (item.kind === "hook") {
|
|
122860
|
-
this.hookAdmissionFailed(item);
|
|
122861
|
-
return;
|
|
122862
|
-
}
|
|
122863
|
-
this.fire(initial ? "admit_deadline" : "admit_abandoned", {
|
|
122864
|
-
detail: plan.mode === "refused" ? plan.reason : undefined
|
|
122865
|
-
});
|
|
122953
|
+
this.failAdmissionUntyped(item, initial, plan.mode === "refused" ? plan.reason : undefined);
|
|
122866
122954
|
return;
|
|
122867
122955
|
}
|
|
122868
122956
|
try {
|
|
122869
122957
|
writeTurnFile(plan);
|
|
122870
122958
|
} catch (e) {
|
|
122871
122959
|
this.anomaly(`turn_file_failed:${e instanceof Error ? e.message : String(e)}`);
|
|
122960
|
+
this.failAdmissionUntyped(item, initial, "turn_file_failed");
|
|
122961
|
+
return;
|
|
122872
122962
|
}
|
|
122873
122963
|
const delivery = (plan.mode === "file" || plan.mode === "command") && plan.file && plan.fileContent !== undefined ? { file: plan.file, text: plan.fileContent } : null;
|
|
122874
122964
|
this.follower.openTurn({ index, offset, witness: plan.witness, delivery });
|
|
@@ -122884,6 +122974,14 @@ ${gate}`
|
|
|
122884
122974
|
this.admission = adm;
|
|
122885
122975
|
this.runAdmission(adm);
|
|
122886
122976
|
}
|
|
122977
|
+
failAdmissionUntyped(item, initial, detail) {
|
|
122978
|
+
this.admission = null;
|
|
122979
|
+
if (item.kind === "hook") {
|
|
122980
|
+
this.hookAdmissionFailed(item);
|
|
122981
|
+
return;
|
|
122982
|
+
}
|
|
122983
|
+
this.fire(initial ? "admit_deadline" : "admit_abandoned", { detail });
|
|
122984
|
+
}
|
|
122887
122985
|
admitting(adm) {
|
|
122888
122986
|
return this.admission === adm && this.phase === "ADMITTING";
|
|
122889
122987
|
}
|
|
@@ -123250,7 +123348,7 @@ ${gate}`
|
|
|
123250
123348
|
this.acceptAdmission(adm);
|
|
123251
123349
|
return;
|
|
123252
123350
|
}
|
|
123253
|
-
if (copy === adm.line && this.unreadCopy === copy) {
|
|
123351
|
+
if (copy === adm.line && this.unreadCopy === copy && this.unreadCopyWitness?.kind !== "turn_file") {
|
|
123254
123352
|
adm.leftoverOf = copy;
|
|
123255
123353
|
this.unreadCopyReadWhole = true;
|
|
123256
123354
|
await this.awaitCopyRecord(adm);
|
|
@@ -123262,8 +123360,9 @@ ${gate}`
|
|
|
123262
123360
|
this.forgetCopy();
|
|
123263
123361
|
}
|
|
123264
123362
|
departCopy() {
|
|
123265
|
-
|
|
123266
|
-
|
|
123363
|
+
const w = this.unreadCopyWitness;
|
|
123364
|
+
if (w && w.kind !== "turn_file")
|
|
123365
|
+
this.follower.refuseDeparted(w, this.unreadCopyAfter);
|
|
123267
123366
|
this.forgetCopy();
|
|
123268
123367
|
}
|
|
123269
123368
|
async awaitCopyRecord(adm) {
|
|
@@ -123705,6 +123804,8 @@ ${screenTailOf(this.screen)}` });
|
|
|
123705
123804
|
return;
|
|
123706
123805
|
}
|
|
123707
123806
|
if (adm.readWhole && adm.submittedUnproven !== null) {
|
|
123807
|
+
if ("witness" in adm.plan && adm.plan.witness.kind === "turn_file")
|
|
123808
|
+
return;
|
|
123708
123809
|
this.rememberCopy(adm.line, "witness" in adm.plan ? adm.plan.witness : { kind: "text", text: adm.line }, adm.mark);
|
|
123709
123810
|
this.unreadCopyReadWhole = true;
|
|
123710
123811
|
return;
|
|
@@ -123831,6 +123932,7 @@ ${screenTailOf(this.screen)}`
|
|
|
123831
123932
|
this.returnToLiveBottom(SCROLL_REPLY_MS);
|
|
123832
123933
|
this.screenTurn = {
|
|
123833
123934
|
echo: d && d.mode !== "refused" ? d.line : "",
|
|
123935
|
+
turnFile: d && d.mode === "file" ? d.file : null,
|
|
123834
123936
|
acceptedAt: at,
|
|
123835
123937
|
errorLogSize: this.turnErrorLogSize
|
|
123836
123938
|
};
|
|
@@ -124099,6 +124201,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124099
124201
|
p = Promise.resolve(binding.settle({
|
|
124100
124202
|
index: turn.index,
|
|
124101
124203
|
answer: turn.answer,
|
|
124204
|
+
answerWithheld: turn.delivery.complete === false,
|
|
124102
124205
|
stopReason: turn.stopReason,
|
|
124103
124206
|
apiError: turn.apiError !== null,
|
|
124104
124207
|
hookCaused: turn.hookCaused,
|
|
@@ -124329,7 +124432,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124329
124432
|
return;
|
|
124330
124433
|
if (!this.client)
|
|
124331
124434
|
return;
|
|
124332
|
-
const answer = screenAnswer(this.screen, st.echo);
|
|
124435
|
+
const answer = screenAnswer(this.screen, st.echo, st.turnFile);
|
|
124333
124436
|
const apiError = this.screenApiError(st, answer);
|
|
124334
124437
|
this.activity = "thinking";
|
|
124335
124438
|
if (!this.screenViewLive() || !this.screenSettleReady(view, answer, apiError))
|
|
@@ -124382,10 +124485,10 @@ ${screenTailOf(this.screen)}`
|
|
|
124382
124485
|
return false;
|
|
124383
124486
|
const notes = [];
|
|
124384
124487
|
let core = this.settledTurnOf(turn, decision, (key) => notes.push(key));
|
|
124385
|
-
if (!core.answer && !core.apiError) {
|
|
124488
|
+
if (!core.answer && !core.apiError && core.delivery.complete !== false) {
|
|
124386
124489
|
if (!this.client || !this.screenViewLive())
|
|
124387
124490
|
return false;
|
|
124388
|
-
const answer = screenAnswer(this.screen, st.echo);
|
|
124491
|
+
const answer = screenAnswer(this.screen, st.echo, st.turnFile);
|
|
124389
124492
|
core = {
|
|
124390
124493
|
...core,
|
|
124391
124494
|
answer,
|
|
@@ -124522,9 +124625,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124522
124625
|
tokensIn: hasTranscript ? view.usage.tokensIn : null,
|
|
124523
124626
|
tokensOut: hasTranscript ? view.usage.tokensOut : null,
|
|
124524
124627
|
toolCalls: view.toolCalls,
|
|
124525
|
-
liveAnswerBytes: cur ? Buffer.byteLength(
|
|
124526
|
-
|
|
124527
|
-
`)) : 0,
|
|
124628
|
+
liveAnswerBytes: cur ? Buffer.byteLength(this.liveAnswerOf(cur)) : 0,
|
|
124528
124629
|
exitCode: this.exitCode,
|
|
124529
124630
|
captureSource: this.lastCaptureSource,
|
|
124530
124631
|
turnSource: this.turnSource,
|
|
@@ -124795,18 +124896,17 @@ ${screenTailOf(this.screen)}`
|
|
|
124795
124896
|
if (done !== undefined)
|
|
124796
124897
|
return done;
|
|
124797
124898
|
const cur = this.follower.view().current;
|
|
124798
|
-
return cur && cur.index === index ?
|
|
124799
|
-
|
|
124800
|
-
|
|
124899
|
+
return cur && cur.index === index ? this.liveAnswerOf(cur) : "";
|
|
124900
|
+
}
|
|
124901
|
+
liveAnswerOf(cur) {
|
|
124902
|
+
return answerOf(cur, this.currentDelivery?.mode ?? null);
|
|
124801
124903
|
}
|
|
124802
124904
|
chainText() {
|
|
124803
124905
|
const parts = this.chain.map((c) => c.answer);
|
|
124804
124906
|
const lastIndex = this.chain[this.chain.length - 1]?.index ?? 0;
|
|
124805
124907
|
const cur = this.follower.view().current;
|
|
124806
124908
|
if (cur && cur.index > lastIndex)
|
|
124807
|
-
parts.push(
|
|
124808
|
-
|
|
124809
|
-
`));
|
|
124909
|
+
parts.push(this.liveAnswerOf(cur));
|
|
124810
124910
|
return parts.filter((a) => a !== "").join(`
|
|
124811
124911
|
|
|
124812
124912
|
`);
|
|
@@ -126223,7 +126323,7 @@ var init_transcript_lines = __esm(() => {
|
|
|
126223
126323
|
CronCreate: (i) => str5(i.cron),
|
|
126224
126324
|
ScheduleWakeup: (i) => str5(i.reason)
|
|
126225
126325
|
};
|
|
126226
|
-
TASK_FILE_RE = /\/launch-[A-Za-z0-9]{6}\/turn-\d+\.md$/;
|
|
126326
|
+
TASK_FILE_RE = /\/(?:launch|claudish-turns)-[A-Za-z0-9]{6}\/turn-\d+\.md$/;
|
|
126227
126327
|
COMMAND_NAME_RE = /<command-name>([\s\S]*?)<\/command-name>/;
|
|
126228
126328
|
COMMAND_ARGS_RE = /<command-args>([\s\S]*?)<\/command-args>/;
|
|
126229
126329
|
CAVEAT_RE = /^\s*<local-command-caveat>/;
|
|
@@ -132256,7 +132356,7 @@ var init_serve_command = __esm(() => {
|
|
|
132256
132356
|
});
|
|
132257
132357
|
|
|
132258
132358
|
// src/hooks/ambient-dts.generated.ts
|
|
132259
|
-
var HOOKS_AMBIENT_DTS = '// claudish hook types \u2014 written by `claudish hooks init`. Do not edit: run\n// `claudish hooks init` from a newer claudish to refresh it.\n// With this file beside your hook, `import type { HookDefinition } from\n// "claudish/hooks"` type-checks with nothing installed.\ndeclare module "claudish/hooks" {\n /**\n * claudish/hooks \u2014 the public hook contract.\n *\n * Everything a hook author can import lives here, and nothing else does. This\n * file imports nothing from the rest of claudish and has no side effects, so it\n * can be built on its own into `dist/hooks.js` + `dist/hooks.d.ts` and served to\n * user modules as the `claudish/hooks` virtual module (see `loader.ts`).\n *\n * Every internal hooks module takes its types from here, so the contract has a\n * single source.\n *\n * ## Process isolation\n *\n * A hook module\'s top-level state is PER PROCESS. In the interactive launcher,\n * proxy events (`request` \u2026 `responseEnd`, raw) and session events\n * (`sessionStart` \u2026 `sessionEnd`) run in one process. In `create_session` and\n * team children they do not: proxy events run in the pane child, and session\n * events run in the MCP server or the CLI process that drives the pane. Pass\n * per-turn data from a proxy event to `sessionIdle` with `annotateTurn`, never\n * with module variables.\n *\n * ## Execution: a hook chain\n *\n * The hooks of one event run one after another, in effective order. Each hook\'s\n * actions are applied before the next hook is called, so `ctx.request`,\n * `ctx.tool.args` and `ctx.response` show what the earlier hooks did, and\n * `ctx.prior` lists it. A warn-severity or failing hook changes nothing for the\n * next one. Each event has a budget for all its hooks together; a hook\'s timeout\n * is cut to what is left of it.\n *\n * ## Output\n *\n * Log with `ctx.log`. `console.*` and `process.stdout`/`stderr` writes made by a\n * hook are routed to claudish\'s debug log, never to the terminal or the MCP\n * protocol stream.\n */\n export const HOOK_API_VERSION = 1;\n export type Severity = "off" | "warn" | "fix";\n export type HookOrder = "pre" | "normal" | "post";\n /** native = RouteInfo.native true; foreign = RouteInfo.native false; all = both */\n export type RouteScope = "foreign" | "native" | "all";\n export type HostMode = "interactive" | "pane-child" | "serve" | "mcp" | "other";\n export type JsonValue = string | number | boolean | null | ReadonlyArray<JsonValue> | {\n readonly [k: string]: JsonValue;\n };\n export interface HarnessFacts {\n readonly planModeActive: boolean;\n readonly planFilePath?: string;\n readonly planDir?: string;\n /** Claude Code session id from request metadata */\n readonly sessionId?: string;\n /** empty = no listing found, not "no skills" */\n readonly skills?: ReadonlyArray<{\n name: string;\n description: string;\n }>;\n }\n export interface RouteInfo {\n /** bare model name the handler serves, e.g. "glm-5" */\n readonly modelId: string;\n /** claudish provider name, e.g. "openrouter"; "anthropic" for native */\n readonly provider: string;\n /**\n * true when the request is served by the native Anthropic handler, OR when\n * !forceForeignModel && (/^claude[-.]/i.test(modelId) || provider === "anthropic")\n * where forceForeignModel is the provider profile\'s opt-in override. This is the exact\n * rule the plan-mode built-in has always used (a claude-* uid on an aggregator that sets\n * forceForeignModel is foreign).\n */\n readonly native: boolean;\n }\n export interface ClaudeTool {\n name: string;\n description?: string;\n input_schema?: unknown;\n }\n /** A Claude-format content block. Only `text` blocks are editable by closed actions. */\n export type ClaudeContentBlock = {\n type: "text";\n text: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "tool_result";\n tool_use_id: string;\n content?: unknown;\n is_error?: boolean;\n } | {\n type: "thinking";\n thinking: string;\n signature?: string;\n } | {\n type: string;\n [k: string]: unknown;\n };\n export interface ClaudeMessage {\n role: "user" | "assistant";\n content: string | ReadonlyArray<ClaudeContentBlock>;\n }\n /**\n * In `request`, the request as the earlier steps of the hook chain left it. On\n * the response side and in `claims()`, the request chain\'s final view.\n */\n export interface RequestFacts {\n /** as Claude Code asked for it; frozen */\n readonly model: string;\n /** frozen */\n readonly stream: boolean;\n /** system prompt flattened to text, after earlier steps */\n readonly systemText: string;\n /** read-only view after earlier steps; change it through actions */\n readonly messages: ReadonlyArray<ClaudeMessage>;\n /**\n * read-only view after earlier steps; `description` includes earlier description actions as\n * stage B will apply them to the Claude-format tool (the provider copy may be summarised)\n */\n readonly tools: ReadonlyArray<ClaudeTool>;\n }\n /** Which session a proxy event belongs to, when claudish knows. */\n export interface ProxySessionRef {\n readonly kind: SessionKind;\n readonly id: string;\n readonly role: "slot" | "judge" | null;\n }\n /** One action an earlier step of this hook chain applied or handed on. */\n export interface PriorAction {\n readonly hookId: string;\n readonly action: HookAction;\n }\n interface BaseContext {\n readonly hookId: string;\n /** "warn" or "fix" (an "off" hook is never called) */\n readonly severity: Severity;\n /** writes to claudish\'s debug log; never to the terminal */\n log(message: string): void;\n /**\n * this step\'s own signal: aborted when its step timeout elapses (its own timeout, or the\n * event budget left, whichever is shorter) or when the dispatch is aborted. Never shared\n * with another hook\'s step.\n */\n readonly signal: AbortSignal;\n /**\n * actions earlier steps of this hook chain applied (or, for responseEnd/sessionStart/\n * sessionIdle, handed on), in order. Empty for the first step and in claims()/the toolCall\n * predicate. Never lists warn actions or anything a warn-severity hook returned.\n */\n readonly prior: ReadonlyArray<PriorAction>;\n }\n export interface ProxyContext extends BaseContext {\n readonly host: {\n mode: HostMode;\n };\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n readonly harness: HarnessFacts;\n readonly session: ProxySessionRef | null;\n }\n export interface RequestContext extends ProxyContext {\n readonly event: "request";\n }\n export interface ToolCallContext extends ProxyContext {\n readonly event: "toolCall";\n readonly tool: {\n id: string;\n name: string;\n /** the arguments after every repair earlier hooks in the chain applied */\n args: Readonly<Record<string, unknown>>;\n /** the argument JSON exactly as the model produced it; never rewritten */\n rawArgs: string;\n };\n }\n export type ResponseBlock = {\n type: "text";\n text: string;\n } | {\n type: "thinking";\n thinking: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "other";\n blockType: string;\n };\n export interface ResponseView {\n blocks: ReadonlyArray<ResponseBlock>;\n /** every text block, joined with "\\n\\n" */\n text: string;\n /** every thinking block, joined with "\\n\\n" */\n reasoning: string;\n toolNames: ReadonlyArray<string>;\n /** "tool_use" = an intermediate step of a tool loop; the turn continues after the tool runs */\n stopReason: string | null;\n }\n /** response = the held response after every text action earlier hooks in the chain applied */\n export interface ResponseRewriteContext extends ProxyContext {\n readonly event: "responseRewrite";\n readonly response: ResponseView;\n }\n /** response = the final bytes the client received: after any rewrite AND any raw `response` replacement */\n export interface ResponseEndContext extends ProxyContext {\n readonly event: "responseEnd";\n readonly response: ResponseView;\n }\n export type SessionKind = "interactive" | "channel" | "team";\n export interface SessionInfo {\n kind: SessionKind;\n /** team only; null otherwise */\n role: "slot" | "judge" | null;\n /** channel: the 8-hex session_id \xB7 team: "<run_id>:<slot id>" \xB7 interactive: the Claude Code session id */\n id: string;\n claudeSessionId: string | null;\n /** as the caller asked for it */\n model: string;\n cwd: string;\n /** a one-shot session stays "one-shot" through a hook-extended turn chain */\n shape: "interactive" | "one-shot";\n injection: "available" | "unavailable";\n }\n export interface SessionStartContext extends BaseContext {\n readonly event: "sessionStart";\n readonly session: SessionInfo;\n }\n export interface TurnAnnotation {\n hookId: string;\n key: string;\n value: JsonValue;\n }\n export interface SessionIdleContext extends BaseContext {\n readonly event: "sessionIdle";\n readonly session: SessionInfo;\n readonly turn: {\n /** 1-based within the session; a re-woken turn keeps its index */\n index: number;\n /** this turn\'s assistant text */\n answer: string;\n stopReason: string | null;\n apiError: boolean;\n /** this turn was started by an injection */\n hookCaused: boolean;\n /** annotateTurn actions from this turn\'s responses, in arrival order */\n annotations: ReadonlyArray<TurnAnnotation>;\n };\n readonly consecutiveHookTurns: number;\n /** caller/human input is queued; an injection returned now will be dropped as stale */\n readonly callerInputPending: boolean;\n }\n export interface SessionBlockedContext extends BaseContext {\n readonly event: "sessionBlocked";\n readonly session: SessionInfo;\n readonly block: {\n kind: "question" | "permission";\n text: string;\n };\n }\n export interface SessionEndContext extends BaseContext {\n readonly event: "sessionEnd";\n readonly session: SessionInfo;\n readonly outcome: {\n state: string;\n reason: string | null;\n exitCode: number | null;\n };\n }\n type TextMatch = {\n find: string;\n regex?: boolean;\n flags?: string;\n };\n /** default ["user"] */\n type MessageRoles = {\n roles?: ReadonlyArray<"user" | "assistant">;\n };\n export type InjectSystemNote = {\n type: "injectSystemNote";\n text: string;\n };\n export type AppendUserText = {\n type: "appendUserText";\n text: string;\n };\n export type ReplaceMessageText = {\n type: "replaceMessageText";\n replace: string;\n } & TextMatch & MessageRoles;\n export type RemoveMessageText = {\n type: "removeMessageText";\n } & TextMatch & MessageRoles;\n export type RewriteToolDescription = {\n type: "rewriteToolDescription";\n tool: string;\n append: string;\n };\n export type ReplaceToolDescription = {\n type: "replaceToolDescription";\n tool: string;\n description: string;\n };\n export type ReplaceToolSchema = {\n type: "replaceToolSchema";\n tool: string;\n inputSchema: {\n type: "object";\n [k: string]: unknown;\n };\n };\n export type RemoveTool = {\n type: "removeTool";\n tool: string;\n };\n export type RepairToolArgs = {\n type: "repairToolArgs";\n args: Record<string, unknown>;\n reason: string;\n };\n export type AppendText = {\n type: "appendText";\n text: string;\n };\n export type PrependText = {\n type: "prependText";\n text: string;\n };\n export type ReplaceText = {\n type: "replaceText";\n replace: string;\n } & TextMatch;\n export type RemoveText = {\n type: "removeText";\n } & TextMatch;\n export type InjectUserTurn = {\n type: "injectUserTurn";\n text: string;\n };\n export type AnnotateTurn = {\n type: "annotateTurn";\n key: string;\n value: JsonValue;\n };\n export type Warn = {\n type: "warn";\n message: string;\n };\n export type RequestAction = InjectSystemNote | AppendUserText | ReplaceMessageText | RemoveMessageText | RewriteToolDescription | ReplaceToolDescription | ReplaceToolSchema | RemoveTool | Warn;\n export type ToolCallAction = RepairToolArgs | Warn;\n export type RewriteAction = AppendText | PrependText | ReplaceText | RemoveText | Warn;\n export type ResponseEndAction = InjectSystemNote | InjectUserTurn | AnnotateTurn | Warn;\n export type SessionAction = InjectUserTurn | Warn;\n export type ObserveAction = Warn;\n export type HookAction = RequestAction | ToolCallAction | RewriteAction | ResponseEndAction | SessionAction;\n export type HookResult<A> = A[] | void | Promise<A[] | void>;\n export interface HookHandlers {\n request?(ctx: RequestContext): HookResult<RequestAction>;\n toolCall?: {\n /** tool names whose completed arguments this hook sees; "*" = every tool (costs streaming of all tool input) */\n tools: ReadonlyArray<string>;\n /** synchronous, per request; default true. false = not armed for this request */\n armed?(ctx: RequestContext): boolean;\n /** true = see the call after it was forwarded; can only warn; never holds the stream */\n observe?: boolean;\n handle(ctx: ToolCallContext): HookResult<ToolCallAction>;\n };\n responseRewrite?: {\n /** synchronous, per request, evaluated before the response starts; default true */\n claims?(ctx: RequestContext): boolean;\n handle(ctx: ResponseRewriteContext): HookResult<RewriteAction>;\n };\n responseEnd?(ctx: ResponseEndContext): HookResult<ResponseEndAction>;\n sessionStart?(ctx: SessionStartContext): HookResult<SessionAction>;\n sessionIdle?(ctx: SessionIdleContext): HookResult<SessionAction>;\n sessionBlocked?(ctx: SessionBlockedContext): HookResult<ObserveAction>;\n sessionEnd?(ctx: SessionEndContext): HookResult<ObserveAction>;\n }\n export interface RawProviderRequestContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n claudeRequest: any;\n messages: any[];\n tools: any[];\n }\n export interface RawProviderChunkContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n /** A clone of the parsed provider event. Whatever this field holds when the call returns is\n * what the parser reads from then on, so it may be edited in place or replaced. */\n chunk: any;\n /** The delta object inside `chunk` at call time (Responses wire: `chunk` itself). Edit it in\n * place; assigning a new object to this field has no effect. */\n delta: any;\n /** per-stream, shared across this hook\'s chunk calls; never cloned */\n metadata: Map<string, unknown>;\n }\n export interface RawProviderStreamEndContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n metadata: Map<string, unknown>;\n }\n export interface RawResponseContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n /** A replay of the current Claude-format response (SSE, or JSON for stream:false), read at the\n * hook\'s own pace. claudish drains the original itself, so leaving this unread delays nothing. */\n response: Response;\n }\n export interface RawMiddleware {\n /**\n * Receives clones. They replace the live request only when this call returns (or its promise\n * resolves) within its timeout. A throw, a rejection or a timeout discards every change.\n */\n providerRequest?(ctx: RawProviderRequestContext): void | Promise<void>;\n /**\n * MUST be synchronous. Called on the parser\'s loop, on a clone of the chunk. On a normal return\n * of anything but a thenable, the clone (whatever `ctx.chunk` holds then) is committed: it\n * becomes the object the parser reads, deletions included. On a throw nothing is committed.\n * A declared `async` function is rejected at load. Any other thenable return is an invalid\n * invocation: the clone is discarded even if the hook mutated it before returning, the call is\n * journaled `invalid` (`async_return`) and counts toward the circuit breaker, and a rejection\n * handler is attached, so a rejection is journaled `error` and never becomes an\n * unhandledRejection.\n */\n providerChunk?(ctx: RawProviderChunkContext): void;\n providerStreamEnd?(ctx: RawProviderStreamEndContext): void | Promise<void>;\n /**\n * Return a replacement Response, or nothing to keep the current one. A replacement is read\n * whole and forwarded only when it completes cleanly; on any failure the original is forwarded.\n * The client never sees a partial replacement. A replacement must close within this hook\'s\n * timeout after the later of this call\'s return and the end of the original; the original\'s end\n * never depends on whether `ctx.response` is read.\n */\n response?(ctx: RawResponseContext): Response | void | Promise<Response | void>;\n }\n interface HookBase {\n apiVersion: 1;\n id: string;\n description?: string;\n /** default "fix" for user hooks */\n defaultSeverity?: Severity;\n /** default "normal" */\n order?: HookOrder;\n /** globs on RouteInfo.modelId; default "*"; proxy events only */\n models?: string | ReadonlyArray<string>;\n /** default "all"; proxy events only */\n routes?: RouteScope;\n /** per call; clamped to the event\'s maximum and to the event budget left when the hook\'s turn comes */\n timeoutMs?: number;\n on?: HookHandlers;\n }\n export interface SafeHook extends HookBase {\n unsafe?: never;\n raw?: never;\n }\n export interface UnsafeHook extends HookBase {\n unsafe: true;\n raw: RawMiddleware;\n }\n /**\n * One hook. Module-level state is per process: in `create_session` and team\n * children, proxy events run in the pane child and session events in the MCP\n * server or CLI process. Pass per-turn data from proxy events to `sessionIdle`\n * with `annotateTurn`, never with module variables.\n */\n export type HookDefinition = SafeHook | UnsafeHook;\n /** Identity function: gives editor type-checking and inference. */\n export function defineHook<const H extends HookDefinition>(hook: H): H;\n /** Action constructors (plain data; equivalent to writing the object literal). */\n export const act: {\n injectSystemNote(text: string): InjectSystemNote;\n appendUserText(text: string): AppendUserText;\n replaceMessageText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): ReplaceMessageText;\n removeMessageText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): RemoveMessageText;\n rewriteToolDescription(tool: string, append: string): RewriteToolDescription;\n replaceToolDescription(tool: string, description: string): ReplaceToolDescription;\n replaceToolSchema(tool: string, inputSchema: {\n type: "object";\n [k: string]: unknown;\n }): ReplaceToolSchema;\n removeTool(tool: string): RemoveTool;\n repairToolArgs(args: Record<string, unknown>, reason: string): RepairToolArgs;\n appendText(text: string): AppendText;\n prependText(text: string): PrependText;\n replaceText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): ReplaceText;\n removeText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): RemoveText;\n injectUserTurn(text: string): InjectUserTurn;\n annotateTurn(key: string, value: JsonValue): AnnotateTurn;\n warn(message: string): Warn;\n };\n}\n';
|
|
132359
|
+
var HOOKS_AMBIENT_DTS = '// claudish hook types \u2014 written by `claudish hooks init`. Do not edit: run\n// `claudish hooks init` from a newer claudish to refresh it.\n// With this file beside your hook, `import type { HookDefinition } from\n// "claudish/hooks"` type-checks with nothing installed.\ndeclare module "claudish/hooks" {\n /**\n * claudish/hooks \u2014 the public hook contract.\n *\n * Everything a hook author can import lives here, and nothing else does. This\n * file imports nothing from the rest of claudish and has no side effects, so it\n * can be built on its own into `dist/hooks.js` + `dist/hooks.d.ts` and served to\n * user modules as the `claudish/hooks` virtual module (see `loader.ts`).\n *\n * Every internal hooks module takes its types from here, so the contract has a\n * single source.\n *\n * ## Process isolation\n *\n * A hook module\'s top-level state is PER PROCESS. In the interactive launcher,\n * proxy events (`request` \u2026 `responseEnd`, raw) and session events\n * (`sessionStart` \u2026 `sessionEnd`) run in one process. In `create_session` and\n * team children they do not: proxy events run in the pane child, and session\n * events run in the MCP server or the CLI process that drives the pane. Pass\n * per-turn data from a proxy event to `sessionIdle` with `annotateTurn`, never\n * with module variables.\n *\n * ## Execution: a hook chain\n *\n * The hooks of one event run one after another, in effective order. Each hook\'s\n * actions are applied before the next hook is called, so `ctx.request`,\n * `ctx.tool.args` and `ctx.response` show what the earlier hooks did, and\n * `ctx.prior` lists it. A warn-severity or failing hook changes nothing for the\n * next one. Each event has a budget for all its hooks together; a hook\'s timeout\n * is cut to what is left of it.\n *\n * ## Output\n *\n * Log with `ctx.log`. `console.*` and `process.stdout`/`stderr` writes made by a\n * hook are routed to claudish\'s debug log, never to the terminal or the MCP\n * protocol stream.\n */\n export const HOOK_API_VERSION = 1;\n export type Severity = "off" | "warn" | "fix";\n export type HookOrder = "pre" | "normal" | "post";\n /** native = RouteInfo.native true; foreign = RouteInfo.native false; all = both */\n export type RouteScope = "foreign" | "native" | "all";\n export type HostMode = "interactive" | "pane-child" | "serve" | "mcp" | "other";\n export type JsonValue = string | number | boolean | null | ReadonlyArray<JsonValue> | {\n readonly [k: string]: JsonValue;\n };\n export interface HarnessFacts {\n readonly planModeActive: boolean;\n readonly planFilePath?: string;\n readonly planDir?: string;\n /** Claude Code session id from request metadata */\n readonly sessionId?: string;\n /** empty = no listing found, not "no skills" */\n readonly skills?: ReadonlyArray<{\n name: string;\n description: string;\n }>;\n }\n export interface RouteInfo {\n /** bare model name the handler serves, e.g. "glm-5" */\n readonly modelId: string;\n /** claudish provider name, e.g. "openrouter"; "anthropic" for native */\n readonly provider: string;\n /**\n * true when the request is served by the native Anthropic handler, OR when\n * !forceForeignModel && (/^claude[-.]/i.test(modelId) || provider === "anthropic")\n * where forceForeignModel is the provider profile\'s opt-in override. This is the exact\n * rule the plan-mode built-in has always used (a claude-* uid on an aggregator that sets\n * forceForeignModel is foreign).\n */\n readonly native: boolean;\n }\n export interface ClaudeTool {\n name: string;\n description?: string;\n input_schema?: unknown;\n }\n /** A Claude-format content block. Only `text` blocks are editable by closed actions. */\n export type ClaudeContentBlock = {\n type: "text";\n text: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "tool_result";\n tool_use_id: string;\n content?: unknown;\n is_error?: boolean;\n } | {\n type: "thinking";\n thinking: string;\n signature?: string;\n } | {\n type: string;\n [k: string]: unknown;\n };\n export interface ClaudeMessage {\n role: "user" | "assistant";\n content: string | ReadonlyArray<ClaudeContentBlock>;\n }\n /**\n * In `request`, the request as the earlier steps of the hook chain left it. On\n * the response side and in `claims()`, the request chain\'s final view.\n */\n export interface RequestFacts {\n /** as Claude Code asked for it; frozen */\n readonly model: string;\n /** frozen */\n readonly stream: boolean;\n /** system prompt flattened to text, after earlier steps */\n readonly systemText: string;\n /** read-only view after earlier steps; change it through actions */\n readonly messages: ReadonlyArray<ClaudeMessage>;\n /**\n * read-only view after earlier steps; `description` includes earlier description actions as\n * stage B will apply them to the Claude-format tool (the provider copy may be summarised)\n */\n readonly tools: ReadonlyArray<ClaudeTool>;\n }\n /** Which session a proxy event belongs to, when claudish knows. */\n export interface ProxySessionRef {\n readonly kind: SessionKind;\n readonly id: string;\n readonly role: "slot" | "judge" | null;\n }\n /** One action an earlier step of this hook chain applied or handed on. */\n export interface PriorAction {\n readonly hookId: string;\n readonly action: HookAction;\n }\n interface BaseContext {\n readonly hookId: string;\n /** "warn" or "fix" (an "off" hook is never called) */\n readonly severity: Severity;\n /** writes to claudish\'s debug log; never to the terminal */\n log(message: string): void;\n /**\n * this step\'s own signal: aborted when its step timeout elapses (its own timeout, or the\n * event budget left, whichever is shorter) or when the dispatch is aborted. Never shared\n * with another hook\'s step.\n */\n readonly signal: AbortSignal;\n /**\n * actions earlier steps of this hook chain applied (or, for responseEnd/sessionStart/\n * sessionIdle, handed on), in order. Empty for the first step and in claims()/the toolCall\n * predicate. Never lists warn actions or anything a warn-severity hook returned.\n */\n readonly prior: ReadonlyArray<PriorAction>;\n }\n export interface ProxyContext extends BaseContext {\n readonly host: {\n mode: HostMode;\n };\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n readonly harness: HarnessFacts;\n readonly session: ProxySessionRef | null;\n }\n export interface RequestContext extends ProxyContext {\n readonly event: "request";\n }\n export interface ToolCallContext extends ProxyContext {\n readonly event: "toolCall";\n readonly tool: {\n id: string;\n name: string;\n /** the arguments after every repair earlier hooks in the chain applied */\n args: Readonly<Record<string, unknown>>;\n /** the argument JSON exactly as the model produced it; never rewritten */\n rawArgs: string;\n };\n }\n export type ResponseBlock = {\n type: "text";\n text: string;\n } | {\n type: "thinking";\n thinking: string;\n } | {\n type: "tool_use";\n id: string;\n name: string;\n input: unknown;\n } | {\n type: "other";\n blockType: string;\n };\n export interface ResponseView {\n blocks: ReadonlyArray<ResponseBlock>;\n /** every text block, joined with "\\n\\n" */\n text: string;\n /** every thinking block, joined with "\\n\\n" */\n reasoning: string;\n toolNames: ReadonlyArray<string>;\n /** "tool_use" = an intermediate step of a tool loop; the turn continues after the tool runs */\n stopReason: string | null;\n }\n /** response = the held response after every text action earlier hooks in the chain applied */\n export interface ResponseRewriteContext extends ProxyContext {\n readonly event: "responseRewrite";\n readonly response: ResponseView;\n }\n /** response = the final bytes the client received: after any rewrite AND any raw `response` replacement */\n export interface ResponseEndContext extends ProxyContext {\n readonly event: "responseEnd";\n readonly response: ResponseView;\n }\n export type SessionKind = "interactive" | "channel" | "team";\n export interface SessionInfo {\n kind: SessionKind;\n /** team only; null otherwise */\n role: "slot" | "judge" | null;\n /** channel: the 8-hex session_id \xB7 team: "<run_id>:<slot id>" \xB7 interactive: the Claude Code session id */\n id: string;\n claudeSessionId: string | null;\n /** as the caller asked for it */\n model: string;\n cwd: string;\n /** a one-shot session stays "one-shot" through a hook-extended turn chain */\n shape: "interactive" | "one-shot";\n injection: "available" | "unavailable";\n }\n export interface SessionStartContext extends BaseContext {\n readonly event: "sessionStart";\n readonly session: SessionInfo;\n }\n export interface TurnAnnotation {\n hookId: string;\n key: string;\n value: JsonValue;\n }\n export interface SessionIdleContext extends BaseContext {\n readonly event: "sessionIdle";\n readonly session: SessionInfo;\n readonly turn: {\n /** 1-based within the session; a re-woken turn keeps its index */\n index: number;\n /** this turn\'s assistant text; "" when `answerWithheld` */\n answer: string;\n /**\n * the turn\'s prompt went as a task file, and the model\'s Read tool calls in the main\n * conversation did not return all of it: `answer` is "" whatever the model wrote. Reading\n * it another way (a shell `cat`, a subagent) does not count as reading it.\n */\n answerWithheld: boolean;\n stopReason: string | null;\n apiError: boolean;\n /** this turn was started by an injection */\n hookCaused: boolean;\n /** annotateTurn actions from this turn\'s responses, in arrival order */\n annotations: ReadonlyArray<TurnAnnotation>;\n };\n readonly consecutiveHookTurns: number;\n /** caller/human input is queued; an injection returned now will be dropped as stale */\n readonly callerInputPending: boolean;\n }\n export interface SessionBlockedContext extends BaseContext {\n readonly event: "sessionBlocked";\n readonly session: SessionInfo;\n readonly block: {\n kind: "question" | "permission";\n text: string;\n };\n }\n export interface SessionEndContext extends BaseContext {\n readonly event: "sessionEnd";\n readonly session: SessionInfo;\n readonly outcome: {\n state: string;\n reason: string | null;\n exitCode: number | null;\n };\n }\n type TextMatch = {\n find: string;\n regex?: boolean;\n flags?: string;\n };\n /** default ["user"] */\n type MessageRoles = {\n roles?: ReadonlyArray<"user" | "assistant">;\n };\n export type InjectSystemNote = {\n type: "injectSystemNote";\n text: string;\n };\n export type AppendUserText = {\n type: "appendUserText";\n text: string;\n };\n export type ReplaceMessageText = {\n type: "replaceMessageText";\n replace: string;\n } & TextMatch & MessageRoles;\n export type RemoveMessageText = {\n type: "removeMessageText";\n } & TextMatch & MessageRoles;\n export type RewriteToolDescription = {\n type: "rewriteToolDescription";\n tool: string;\n append: string;\n };\n export type ReplaceToolDescription = {\n type: "replaceToolDescription";\n tool: string;\n description: string;\n };\n export type ReplaceToolSchema = {\n type: "replaceToolSchema";\n tool: string;\n inputSchema: {\n type: "object";\n [k: string]: unknown;\n };\n };\n export type RemoveTool = {\n type: "removeTool";\n tool: string;\n };\n export type RepairToolArgs = {\n type: "repairToolArgs";\n args: Record<string, unknown>;\n reason: string;\n };\n export type AppendText = {\n type: "appendText";\n text: string;\n };\n export type PrependText = {\n type: "prependText";\n text: string;\n };\n export type ReplaceText = {\n type: "replaceText";\n replace: string;\n } & TextMatch;\n export type RemoveText = {\n type: "removeText";\n } & TextMatch;\n export type InjectUserTurn = {\n type: "injectUserTurn";\n text: string;\n };\n export type AnnotateTurn = {\n type: "annotateTurn";\n key: string;\n value: JsonValue;\n };\n export type Warn = {\n type: "warn";\n message: string;\n };\n export type RequestAction = InjectSystemNote | AppendUserText | ReplaceMessageText | RemoveMessageText | RewriteToolDescription | ReplaceToolDescription | ReplaceToolSchema | RemoveTool | Warn;\n export type ToolCallAction = RepairToolArgs | Warn;\n export type RewriteAction = AppendText | PrependText | ReplaceText | RemoveText | Warn;\n export type ResponseEndAction = InjectSystemNote | InjectUserTurn | AnnotateTurn | Warn;\n export type SessionAction = InjectUserTurn | Warn;\n export type ObserveAction = Warn;\n export type HookAction = RequestAction | ToolCallAction | RewriteAction | ResponseEndAction | SessionAction;\n export type HookResult<A> = A[] | void | Promise<A[] | void>;\n export interface HookHandlers {\n request?(ctx: RequestContext): HookResult<RequestAction>;\n toolCall?: {\n /** tool names whose completed arguments this hook sees; "*" = every tool (costs streaming of all tool input) */\n tools: ReadonlyArray<string>;\n /** synchronous, per request; default true. false = not armed for this request */\n armed?(ctx: RequestContext): boolean;\n /** true = see the call after it was forwarded; can only warn; never holds the stream */\n observe?: boolean;\n handle(ctx: ToolCallContext): HookResult<ToolCallAction>;\n };\n responseRewrite?: {\n /** synchronous, per request, evaluated before the response starts; default true */\n claims?(ctx: RequestContext): boolean;\n handle(ctx: ResponseRewriteContext): HookResult<RewriteAction>;\n };\n responseEnd?(ctx: ResponseEndContext): HookResult<ResponseEndAction>;\n sessionStart?(ctx: SessionStartContext): HookResult<SessionAction>;\n sessionIdle?(ctx: SessionIdleContext): HookResult<SessionAction>;\n sessionBlocked?(ctx: SessionBlockedContext): HookResult<ObserveAction>;\n sessionEnd?(ctx: SessionEndContext): HookResult<ObserveAction>;\n }\n export interface RawProviderRequestContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n claudeRequest: any;\n messages: any[];\n tools: any[];\n }\n export interface RawProviderChunkContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n /** A clone of the parsed provider event. Whatever this field holds when the call returns is\n * what the parser reads from then on, so it may be edited in place or replaced. */\n chunk: any;\n /** The delta object inside `chunk` at call time (Responses wire: `chunk` itself). Edit it in\n * place; assigning a new object to this field has no effect. */\n delta: any;\n /** per-stream, shared across this hook\'s chunk calls; never cloned */\n metadata: Map<string, unknown>;\n }\n export interface RawProviderStreamEndContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n metadata: Map<string, unknown>;\n }\n export interface RawResponseContext {\n readonly hookId: string;\n readonly route: RouteInfo;\n readonly request: RequestFacts;\n /** A replay of the current Claude-format response (SSE, or JSON for stream:false), read at the\n * hook\'s own pace. claudish drains the original itself, so leaving this unread delays nothing. */\n response: Response;\n }\n export interface RawMiddleware {\n /**\n * Receives clones. They replace the live request only when this call returns (or its promise\n * resolves) within its timeout. A throw, a rejection or a timeout discards every change.\n */\n providerRequest?(ctx: RawProviderRequestContext): void | Promise<void>;\n /**\n * MUST be synchronous. Called on the parser\'s loop, on a clone of the chunk. On a normal return\n * of anything but a thenable, the clone (whatever `ctx.chunk` holds then) is committed: it\n * becomes the object the parser reads, deletions included. On a throw nothing is committed.\n * A declared `async` function is rejected at load. Any other thenable return is an invalid\n * invocation: the clone is discarded even if the hook mutated it before returning, the call is\n * journaled `invalid` (`async_return`) and counts toward the circuit breaker, and a rejection\n * handler is attached, so a rejection is journaled `error` and never becomes an\n * unhandledRejection.\n */\n providerChunk?(ctx: RawProviderChunkContext): void;\n providerStreamEnd?(ctx: RawProviderStreamEndContext): void | Promise<void>;\n /**\n * Return a replacement Response, or nothing to keep the current one. A replacement is read\n * whole and forwarded only when it completes cleanly; on any failure the original is forwarded.\n * The client never sees a partial replacement. A replacement must close within this hook\'s\n * timeout after the later of this call\'s return and the end of the original; the original\'s end\n * never depends on whether `ctx.response` is read.\n */\n response?(ctx: RawResponseContext): Response | void | Promise<Response | void>;\n }\n interface HookBase {\n apiVersion: 1;\n id: string;\n description?: string;\n /** default "fix" for user hooks */\n defaultSeverity?: Severity;\n /** default "normal" */\n order?: HookOrder;\n /** globs on RouteInfo.modelId; default "*"; proxy events only */\n models?: string | ReadonlyArray<string>;\n /** default "all"; proxy events only */\n routes?: RouteScope;\n /** per call; clamped to the event\'s maximum and to the event budget left when the hook\'s turn comes */\n timeoutMs?: number;\n on?: HookHandlers;\n }\n export interface SafeHook extends HookBase {\n unsafe?: never;\n raw?: never;\n }\n export interface UnsafeHook extends HookBase {\n unsafe: true;\n raw: RawMiddleware;\n }\n /**\n * One hook. Module-level state is per process: in `create_session` and team\n * children, proxy events run in the pane child and session events in the MCP\n * server or CLI process. Pass per-turn data from proxy events to `sessionIdle`\n * with `annotateTurn`, never with module variables.\n */\n export type HookDefinition = SafeHook | UnsafeHook;\n /** Identity function: gives editor type-checking and inference. */\n export function defineHook<const H extends HookDefinition>(hook: H): H;\n /** Action constructors (plain data; equivalent to writing the object literal). */\n export const act: {\n injectSystemNote(text: string): InjectSystemNote;\n appendUserText(text: string): AppendUserText;\n replaceMessageText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): ReplaceMessageText;\n removeMessageText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n roles?: ReadonlyArray<"user" | "assistant">;\n }): RemoveMessageText;\n rewriteToolDescription(tool: string, append: string): RewriteToolDescription;\n replaceToolDescription(tool: string, description: string): ReplaceToolDescription;\n replaceToolSchema(tool: string, inputSchema: {\n type: "object";\n [k: string]: unknown;\n }): ReplaceToolSchema;\n removeTool(tool: string): RemoveTool;\n repairToolArgs(args: Record<string, unknown>, reason: string): RepairToolArgs;\n appendText(text: string): AppendText;\n prependText(text: string): PrependText;\n replaceText(find: string, replace: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): ReplaceText;\n removeText(find: string, opts?: {\n regex?: boolean;\n flags?: string;\n }): RemoveText;\n injectUserTurn(text: string): InjectUserTurn;\n annotateTurn(key: string, value: JsonValue): AnnotateTurn;\n warn(message: string): Warn;\n };\n}\n';
|
|
132260
132360
|
|
|
132261
132361
|
// src/hooks/observer/corpus.ts
|
|
132262
132362
|
import { appendFileSync as appendFileSync8, readFileSync as readFileSync55, readdirSync as readdirSync18, statSync as statSync30 } from "fs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claudish",
|
|
3
|
-
"version": "14.29.
|
|
3
|
+
"version": "14.29.2",
|
|
4
4
|
"description": "Run Claude Code with any model - OpenRouter, Ollama, LM Studio & local models",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"ai"
|
|
75
75
|
],
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"@claudish/magmux-darwin-arm64": "14.29.
|
|
78
|
-
"@claudish/magmux-darwin-x64": "14.29.
|
|
79
|
-
"@claudish/magmux-linux-arm64": "14.29.
|
|
80
|
-
"@claudish/magmux-linux-x64": "14.29.
|
|
77
|
+
"@claudish/magmux-darwin-arm64": "14.29.2",
|
|
78
|
+
"@claudish/magmux-darwin-x64": "14.29.2",
|
|
79
|
+
"@claudish/magmux-linux-arm64": "14.29.2",
|
|
80
|
+
"@claudish/magmux-linux-x64": "14.29.2"
|
|
81
81
|
},
|
|
82
82
|
"author": "Jack Rudenko <i@madappgang.com>",
|
|
83
83
|
"license": "MIT",
|