claudish 14.29.0 → 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 +422 -201
- package/package.json +5 -5
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) {
|
|
@@ -91070,7 +91075,8 @@ function emptyScreen(cols, rows) {
|
|
|
91070
91075
|
spans: Array.from({ length: rows }, () => []),
|
|
91071
91076
|
alt: false,
|
|
91072
91077
|
changedAt: 0,
|
|
91073
|
-
aboveBoxChangedAt: 0
|
|
91078
|
+
aboveBoxChangedAt: 0,
|
|
91079
|
+
boxChangedAt: 0
|
|
91074
91080
|
};
|
|
91075
91081
|
}
|
|
91076
91082
|
function isBoxRule(line, cols) {
|
|
@@ -91105,6 +91111,20 @@ function aboveBoxText(s) {
|
|
|
91105
91111
|
return box ? s.lines.slice(0, box.top).join(`
|
|
91106
91112
|
`) : null;
|
|
91107
91113
|
}
|
|
91114
|
+
function boxKey(s) {
|
|
91115
|
+
const box = locateBox(s);
|
|
91116
|
+
if (!box)
|
|
91117
|
+
return null;
|
|
91118
|
+
return JSON.stringify([
|
|
91119
|
+
s.cols,
|
|
91120
|
+
box.top,
|
|
91121
|
+
box.bottom,
|
|
91122
|
+
s.cursor.x,
|
|
91123
|
+
s.cursor.y,
|
|
91124
|
+
s.lines.slice(box.top, box.bottom + 1),
|
|
91125
|
+
s.spans.slice(box.top, box.bottom + 1)
|
|
91126
|
+
]);
|
|
91127
|
+
}
|
|
91108
91128
|
function finish(prev, next, now) {
|
|
91109
91129
|
const visible = prev.seq === 0 || prev.cols !== next.cols || prev.rows !== next.rows || prev.alt !== next.alt || prev.cursor.x !== next.cursor.x || prev.cursor.y !== next.cursor.y || next.lines.some((l, i) => l !== prev.lines[i]) || next.spans.some((r, i) => !sameSpans(r, prev.spans[i]));
|
|
91110
91130
|
if (!visible)
|
|
@@ -91113,12 +91133,17 @@ function finish(prev, next, now) {
|
|
|
91113
91133
|
...next,
|
|
91114
91134
|
seq: prev.seq + 1,
|
|
91115
91135
|
changedAt: now,
|
|
91116
|
-
aboveBoxChangedAt: prev.aboveBoxChangedAt
|
|
91136
|
+
aboveBoxChangedAt: prev.aboveBoxChangedAt,
|
|
91137
|
+
boxChangedAt: prev.boxChangedAt
|
|
91117
91138
|
};
|
|
91118
91139
|
const before = prev.seq === 0 ? null : aboveBoxText(prev);
|
|
91119
91140
|
const after = aboveBoxText(out);
|
|
91120
91141
|
if (before === null || after === null || before !== after)
|
|
91121
91142
|
out.aboveBoxChangedAt = now;
|
|
91143
|
+
const boxBefore = prev.seq === 0 ? null : boxKey(prev);
|
|
91144
|
+
const boxAfter = boxKey(out);
|
|
91145
|
+
if (boxBefore === null || boxAfter === null || boxBefore !== boxAfter)
|
|
91146
|
+
out.boxChangedAt = now;
|
|
91122
91147
|
return out;
|
|
91123
91148
|
}
|
|
91124
91149
|
function applyFrame(s, frame, now = Date.now()) {
|
|
@@ -91162,12 +91187,12 @@ function flatText(lines) {
|
|
|
91162
91187
|
function squash(s) {
|
|
91163
91188
|
return s.replace(/\s+/g, "");
|
|
91164
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
|
+
}
|
|
91165
91193
|
function echoHeadLength(cols) {
|
|
91166
91194
|
return Math.max(1, Math.min(40, cols - 4));
|
|
91167
91195
|
}
|
|
91168
|
-
function echoHead(line, cols) {
|
|
91169
|
-
return line.slice(0, echoHeadLength(cols));
|
|
91170
|
-
}
|
|
91171
91196
|
function visibleText2(line, spans) {
|
|
91172
91197
|
if (!spans?.length)
|
|
91173
91198
|
return line;
|
|
@@ -91180,26 +91205,59 @@ function visibleText2(line, spans) {
|
|
|
91180
91205
|
}
|
|
91181
91206
|
return chars.join("");
|
|
91182
91207
|
}
|
|
91183
|
-
function echoAt(lines, i,
|
|
91208
|
+
function echoAt(lines, i, line, headLength = Number.POSITIVE_INFINITY) {
|
|
91184
91209
|
const first = lines[i] ?? "";
|
|
91185
91210
|
if (!first.startsWith("\u276F "))
|
|
91186
91211
|
return false;
|
|
91187
|
-
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));
|
|
91188
91216
|
let got = squash(first.slice(2));
|
|
91189
|
-
for (let j = i + 1;got.length <
|
|
91217
|
+
for (let j = i + 1;got.length < longest && j < lines.length; j++) {
|
|
91190
91218
|
const row = lines[j] ?? "";
|
|
91191
91219
|
if (!/^ {2}\S/.test(row))
|
|
91192
91220
|
break;
|
|
91193
91221
|
got += squash(row);
|
|
91194
91222
|
}
|
|
91195
|
-
return got.startsWith(
|
|
91223
|
+
return wants.some((w) => got.startsWith(w));
|
|
91196
91224
|
}
|
|
91197
|
-
function hasEcho(lines,
|
|
91225
|
+
function hasEcho(lines, line, headLength = Number.POSITIVE_INFINITY) {
|
|
91198
91226
|
for (let i = 0;i < lines.length; i++)
|
|
91199
|
-
if (echoAt(lines, i,
|
|
91227
|
+
if (echoAt(lines, i, line, headLength))
|
|
91200
91228
|
return true;
|
|
91201
91229
|
return false;
|
|
91202
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
|
+
}
|
|
91203
91261
|
function inputBox(s) {
|
|
91204
91262
|
const top = boxTopRow(s.lines, s.cols);
|
|
91205
91263
|
if (top < 0)
|
|
@@ -91303,11 +91361,11 @@ function isToolHeader(lines, i) {
|
|
|
91303
91361
|
}
|
|
91304
91362
|
return false;
|
|
91305
91363
|
}
|
|
91306
|
-
function screenAnswer(s, echo) {
|
|
91364
|
+
function screenAnswer(s, echo, turnFile = null) {
|
|
91307
91365
|
const lines = s.lines;
|
|
91308
91366
|
const top = boxTopRow(lines, s.cols);
|
|
91309
91367
|
const end = top >= 0 ? top : lines.length;
|
|
91310
|
-
const start =
|
|
91368
|
+
const start = echoRowOf(lines, end, echo, turnFile, echoHeadLength(s.cols)) + 1;
|
|
91311
91369
|
if (start <= 0)
|
|
91312
91370
|
return "";
|
|
91313
91371
|
const out = [];
|
|
@@ -91321,13 +91379,6 @@ function screenAnswer(s, echo) {
|
|
|
91321
91379
|
return out.join(`
|
|
91322
91380
|
`).trim();
|
|
91323
91381
|
}
|
|
91324
|
-
function echoRow(lines, end, head) {
|
|
91325
|
-
const above = lines.slice(0, end);
|
|
91326
|
-
for (let i = end - 1;i >= 0; i--)
|
|
91327
|
-
if (echoAt(above, i, head))
|
|
91328
|
-
return i;
|
|
91329
|
-
return -1;
|
|
91330
|
-
}
|
|
91331
91382
|
function answerRow(lines, i, inProse) {
|
|
91332
91383
|
const l = lines[i] ?? "";
|
|
91333
91384
|
if (BULLET.test(l)) {
|
|
@@ -91531,6 +91582,43 @@ var init_settle_rule = __esm(() => {
|
|
|
91531
91582
|
CORROBORATION_GRACE_MS = SECONDARY_QUIET_MS;
|
|
91532
91583
|
});
|
|
91533
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
|
+
|
|
91534
91622
|
// src/pane/slot-steps.ts
|
|
91535
91623
|
function oneLine6(text) {
|
|
91536
91624
|
if (typeof text !== "string")
|
|
@@ -92006,18 +92094,43 @@ function wholeCopies(text, line) {
|
|
|
92006
92094
|
const core = line.trim();
|
|
92007
92095
|
if (!core)
|
|
92008
92096
|
return got === core ? 1 : 0;
|
|
92009
|
-
|
|
92010
|
-
|
|
92011
|
-
|
|
92012
|
-
|
|
92013
|
-
|
|
92014
|
-
|
|
92015
|
-
|
|
92016
|
-
|
|
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;
|
|
92017
92128
|
}
|
|
92018
92129
|
function matchesWitness(r, w) {
|
|
92019
92130
|
if (w.kind === "human")
|
|
92020
|
-
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;
|
|
92021
92134
|
if (w.kind === "command" && isLocalCommandSystem(r))
|
|
92022
92135
|
return isCommandRecordOf(String(r.content ?? ""), w);
|
|
92023
92136
|
if (!isMainUser(r) || hasToolResult(r))
|
|
@@ -92317,6 +92430,8 @@ function takeDepartedRecord(state, r, offset) {
|
|
|
92317
92430
|
return true;
|
|
92318
92431
|
}
|
|
92319
92432
|
function isOneCopyOf(r, w) {
|
|
92433
|
+
if (w.kind === "turn_file")
|
|
92434
|
+
return false;
|
|
92320
92435
|
if (w.kind === "text")
|
|
92321
92436
|
return isMainUser(r) && !r.isMeta && !hasToolResult(r) && userText2(r).trim() === w.text.trim();
|
|
92322
92437
|
return w.kind === "command" && matchesWitness(r, w);
|
|
@@ -92329,6 +92444,8 @@ function acceptUnlessHeld(state, t, r, offset, departed) {
|
|
|
92329
92444
|
}
|
|
92330
92445
|
function heldMayAccept(state, t, r) {
|
|
92331
92446
|
const w = t.witness;
|
|
92447
|
+
if (w.kind === "turn_file")
|
|
92448
|
+
return matchesWitness(r, w);
|
|
92332
92449
|
const c = state.copy?.witness;
|
|
92333
92450
|
if (w.kind === "command")
|
|
92334
92451
|
return c?.kind === "command" && c.name === w.name && c.line === w.line && matchesWitness(r, w);
|
|
@@ -92341,9 +92458,16 @@ function acceptIfWitness(t, r, offset) {
|
|
|
92341
92458
|
return;
|
|
92342
92459
|
t.acceptedAt = typeof r.timestamp === "string" ? r.timestamp : new Date().toISOString();
|
|
92343
92460
|
t.acceptedOffset = offset;
|
|
92344
|
-
t.witnessCopies =
|
|
92461
|
+
t.witnessCopies = witnessCopiesOf(r, t.witness);
|
|
92345
92462
|
t.lastChatOffset = offset;
|
|
92346
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
|
+
}
|
|
92347
92471
|
function noteMainAssistant(state, r) {
|
|
92348
92472
|
const id = r.type === "assistant" ? r.message?.id : undefined;
|
|
92349
92473
|
if (typeof id !== "string" || !id)
|
|
@@ -92379,8 +92503,7 @@ function applyRecord(state, record, offset) {
|
|
|
92379
92503
|
t.shadow = null;
|
|
92380
92504
|
return state;
|
|
92381
92505
|
}
|
|
92382
|
-
|
|
92383
|
-
t.unwitnessedChat = offset;
|
|
92506
|
+
noteUnwitnessed(t, r, offset);
|
|
92384
92507
|
if (t.shadow)
|
|
92385
92508
|
foldTurnRecord(state, t.shadow, r, offset);
|
|
92386
92509
|
return state;
|
|
@@ -92402,6 +92525,19 @@ function foldTurnRecord(state, t, r, offset) {
|
|
|
92402
92525
|
applyTurnDuration(state, t, r);
|
|
92403
92526
|
applyQueuedNotification(t, r);
|
|
92404
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
|
+
}
|
|
92405
92541
|
function wakesModel(r) {
|
|
92406
92542
|
if (r.type === "assistant")
|
|
92407
92543
|
return true;
|
|
@@ -92475,6 +92611,7 @@ function newTurnState(t) {
|
|
|
92475
92611
|
localOutput: null,
|
|
92476
92612
|
steps: [],
|
|
92477
92613
|
unwitnessedChat: null,
|
|
92614
|
+
foreignPointerAt: null,
|
|
92478
92615
|
witnessCopies: null,
|
|
92479
92616
|
shadow: null
|
|
92480
92617
|
};
|
|
@@ -92769,6 +92906,7 @@ function parseRecord3(line) {
|
|
|
92769
92906
|
}
|
|
92770
92907
|
var LOCAL_COMMAND_RE, INTERRUPT_PREFIX = "[Request interrupted by user", COMMAND_TAG, STDOUT_RE, ANSI_RE, AGENT_FILE_RE, AGENT_META_RE;
|
|
92771
92908
|
var init_transcript_follower = __esm(() => {
|
|
92909
|
+
init_prompt_delivery();
|
|
92772
92910
|
init_slot_steps();
|
|
92773
92911
|
init_subagent_ledger();
|
|
92774
92912
|
LOCAL_COMMAND_RE = /^\s*<(local-command-caveat|command-name|local-command-stdout|local-command-stderr)>/;
|
|
@@ -93678,7 +93816,7 @@ class InteractiveDriver {
|
|
|
93678
93816
|
const turn = {
|
|
93679
93817
|
index: this.lastAcceptedIndex + 1,
|
|
93680
93818
|
offset,
|
|
93681
|
-
witness: { kind: "human" },
|
|
93819
|
+
witness: { kind: "human", notTurnDir: this.o.turnDir },
|
|
93682
93820
|
delivery: null,
|
|
93683
93821
|
hookCaused: false
|
|
93684
93822
|
};
|
|
@@ -93795,9 +93933,8 @@ class InteractiveDriver {
|
|
|
93795
93933
|
this.settledTurn = cur;
|
|
93796
93934
|
const info = {
|
|
93797
93935
|
index: cur.index,
|
|
93798
|
-
answer: localCommand ? t.localCommandOutput ?? "" : t
|
|
93799
|
-
|
|
93800
|
-
`),
|
|
93936
|
+
answer: localCommand ? t.localCommandOutput ?? "" : answerOf(t, null),
|
|
93937
|
+
answerWithheld: !localCommand && answerWithheld(t, null),
|
|
93801
93938
|
stopReason,
|
|
93802
93939
|
apiError: t.apiError !== null,
|
|
93803
93940
|
hookCaused: cur.hookCaused,
|
|
@@ -94001,6 +94138,7 @@ class InteractiveDriver {
|
|
|
94001
94138
|
} catch {}
|
|
94002
94139
|
this.transition("deliver");
|
|
94003
94140
|
const adm = this.admission;
|
|
94141
|
+
const turnFile = plan.mode === "file" ? plan.file : null;
|
|
94004
94142
|
const rt = SEND_READY_WAIT_DEFAULT_MS;
|
|
94005
94143
|
const timeout = sendBudgetMs({ readyTimeoutMs: rt, text: plan.line, keys: 1, submit: true }) + SEND_CLIENT_SLACK_MS;
|
|
94006
94144
|
client.request({ type: "send", pane, text: plan.line, typed: true, enter: true, readyTimeoutMs: rt }, timeout).then(async (r) => {
|
|
@@ -94008,7 +94146,7 @@ class InteractiveDriver {
|
|
|
94008
94146
|
return;
|
|
94009
94147
|
const out = classifySendReply(r);
|
|
94010
94148
|
if (out.kind === "reply_lost" && out.code !== "timeout") {
|
|
94011
|
-
if (await this.landedAfterLostReply(adm, pane, plan.line))
|
|
94149
|
+
if (await this.landedAfterLostReply(adm, pane, plan.line, turnFile))
|
|
94012
94150
|
return;
|
|
94013
94151
|
} else if (out.kind === "not_accepted" && enterMayHaveBeenPressed(out)) {
|
|
94014
94152
|
log(`[hooks] interactive driver: send not confirmed (${out.reason}); awaiting the witness`);
|
|
@@ -94018,8 +94156,7 @@ class InteractiveDriver {
|
|
|
94018
94156
|
this.step(() => this.admitFailed(`send refused: ${r.code} ${r.error}`));
|
|
94019
94157
|
});
|
|
94020
94158
|
}
|
|
94021
|
-
async landedAfterLostReply(adm, pane, line) {
|
|
94022
|
-
const head = line.slice(0, 40);
|
|
94159
|
+
async landedAfterLostReply(adm, pane, line, turnFile) {
|
|
94023
94160
|
for (let attempt = 0;attempt < 2; attempt++) {
|
|
94024
94161
|
const seen = this.screen.seq;
|
|
94025
94162
|
const client = await this.connectedClient(RECONNECT_WAIT_MS);
|
|
@@ -94035,8 +94172,10 @@ class InteractiveDriver {
|
|
|
94035
94172
|
if (r.ok)
|
|
94036
94173
|
return true;
|
|
94037
94174
|
log(`[hooks] interactive driver: Enter after a lost reply: ${r.code} ${r.error}`);
|
|
94175
|
+
if (enterMayHaveLanded(classifySendReply(r)))
|
|
94176
|
+
return true;
|
|
94038
94177
|
}
|
|
94039
|
-
const landed = this.submitted(
|
|
94178
|
+
const landed = this.submitted(line, turnFile);
|
|
94040
94179
|
if (landed)
|
|
94041
94180
|
log("[hooks] interactive driver: send reply lost; the line was submitted");
|
|
94042
94181
|
return landed;
|
|
@@ -94056,9 +94195,9 @@ class InteractiveDriver {
|
|
|
94056
94195
|
}
|
|
94057
94196
|
return false;
|
|
94058
94197
|
}
|
|
94059
|
-
submitted(
|
|
94198
|
+
submitted(line, turnFile) {
|
|
94060
94199
|
const t = this.pollFollower(true)?.current;
|
|
94061
|
-
return (t?.acceptedAt ?? null) !== null || this.screen.lines
|
|
94200
|
+
return (t?.acceptedAt ?? null) !== null || lineSubmittedOnScreen(this.screen.lines, line, turnFile);
|
|
94062
94201
|
}
|
|
94063
94202
|
async connectedClient(ms) {
|
|
94064
94203
|
const end = Date.now() + ms;
|
|
@@ -94104,6 +94243,11 @@ function screenNotIdleReason(screen) {
|
|
|
94104
94243
|
return "no_input_box";
|
|
94105
94244
|
return box.text === "" ? null : "box_not_empty";
|
|
94106
94245
|
}
|
|
94246
|
+
function enterMayHaveLanded(o) {
|
|
94247
|
+
if (o.kind === "reply_lost")
|
|
94248
|
+
return true;
|
|
94249
|
+
return o.kind === "not_accepted" && enterMayHaveBeenPressed(o);
|
|
94250
|
+
}
|
|
94107
94251
|
function enterMayHaveBeenPressed(o) {
|
|
94108
94252
|
return o.reason === "still_in_box" || o.reason === "unconfirmed" || o.maybeSubmitted;
|
|
94109
94253
|
}
|
|
@@ -94286,11 +94430,36 @@ var init_host_routing_env = __esm(() => {
|
|
|
94286
94430
|
});
|
|
94287
94431
|
|
|
94288
94432
|
// src/launcher/magmux-binary.ts
|
|
94289
|
-
import {
|
|
94290
|
-
import {
|
|
94291
|
-
import { dirname as dirname16, join as join44 } from "path";
|
|
94433
|
+
import { constants as constants3, accessSync as accessSync2, existsSync as existsSync30, statSync as statSync16 } from "fs";
|
|
94434
|
+
import { delimiter, dirname as dirname16, join as join44 } from "path";
|
|
94292
94435
|
import { fileURLToPath } from "url";
|
|
94293
|
-
function
|
|
94436
|
+
function lookupOnPath(name, pathValue, fs = NODE_FS) {
|
|
94437
|
+
let failure = null;
|
|
94438
|
+
for (const dir of pathValue.split(delimiter)) {
|
|
94439
|
+
if (dir === "")
|
|
94440
|
+
continue;
|
|
94441
|
+
const at = checkCandidate(join44(dir, name), fs);
|
|
94442
|
+
if (at.kind === "found")
|
|
94443
|
+
return at;
|
|
94444
|
+
if (at.kind === "error")
|
|
94445
|
+
failure ??= at;
|
|
94446
|
+
}
|
|
94447
|
+
return failure ?? { kind: "not-found" };
|
|
94448
|
+
}
|
|
94449
|
+
function checkCandidate(candidate, fs) {
|
|
94450
|
+
try {
|
|
94451
|
+
if (!fs.statSync(candidate).isFile())
|
|
94452
|
+
return { kind: "not-found" };
|
|
94453
|
+
fs.accessSync(candidate, constants3.X_OK);
|
|
94454
|
+
return { kind: "found", path: candidate };
|
|
94455
|
+
} catch (e) {
|
|
94456
|
+
const code = e?.code;
|
|
94457
|
+
if (code && NOT_HERE.has(code))
|
|
94458
|
+
return { kind: "not-found" };
|
|
94459
|
+
return { kind: "error", code: code ?? String(e), path: candidate };
|
|
94460
|
+
}
|
|
94461
|
+
}
|
|
94462
|
+
function findMagmuxCandidates(env = process.env, fs = NODE_FS) {
|
|
94294
94463
|
const thisFile = fileURLToPath(import.meta.url);
|
|
94295
94464
|
const thisDir = dirname16(thisFile);
|
|
94296
94465
|
const pkgRoots = [join44(thisDir, ".."), join44(thisDir, "..", "..")];
|
|
@@ -94321,24 +94490,31 @@ function findMagmuxCandidates() {
|
|
|
94321
94490
|
searchDir = parent;
|
|
94322
94491
|
}
|
|
94323
94492
|
} catch {}
|
|
94324
|
-
|
|
94325
|
-
|
|
94326
|
-
|
|
94327
|
-
|
|
94328
|
-
|
|
94329
|
-
|
|
94493
|
+
const onPath = lookupOnPath("magmux", env.PATH ?? "", fs);
|
|
94494
|
+
if (onPath.kind === "found")
|
|
94495
|
+
add(onPath.path);
|
|
94496
|
+
return {
|
|
94497
|
+
paths: found,
|
|
94498
|
+
lookupError: onPath.kind === "error" ? `${onPath.code} on ${onPath.path}` : null
|
|
94499
|
+
};
|
|
94330
94500
|
}
|
|
94331
|
-
function findMagmuxBinaryOrNull() {
|
|
94332
|
-
return findMagmuxCandidates()[0] ?? null;
|
|
94501
|
+
function findMagmuxBinaryOrNull(env = process.env, fs = NODE_FS) {
|
|
94502
|
+
return findMagmuxCandidates(env, fs).paths[0] ?? null;
|
|
94333
94503
|
}
|
|
94334
|
-
function findMagmuxBinary() {
|
|
94335
|
-
const
|
|
94336
|
-
if (
|
|
94337
|
-
return
|
|
94504
|
+
function findMagmuxBinary(env = process.env, fs = NODE_FS) {
|
|
94505
|
+
const { paths, lookupError } = findMagmuxCandidates(env, fs);
|
|
94506
|
+
if (paths[0])
|
|
94507
|
+
return paths[0];
|
|
94508
|
+
if (lookupError)
|
|
94509
|
+
throw new Error(`magmux lookup failed: ${lookupError}`);
|
|
94338
94510
|
throw new Error(`magmux not found. Install it:
|
|
94339
94511
|
brew install MadAppGang/tap/magmux`);
|
|
94340
94512
|
}
|
|
94341
|
-
var
|
|
94513
|
+
var NODE_FS, NOT_HERE;
|
|
94514
|
+
var init_magmux_binary = __esm(() => {
|
|
94515
|
+
NODE_FS = { statSync: statSync16, accessSync: accessSync2 };
|
|
94516
|
+
NOT_HERE = new Set(["ENOENT", "ENOTDIR", "EACCES"]);
|
|
94517
|
+
});
|
|
94342
94518
|
|
|
94343
94519
|
// src/launcher/magmux-wrapper.ts
|
|
94344
94520
|
import {
|
|
@@ -107373,7 +107549,7 @@ var init_bundled_tagged_cache = __esm(() => {
|
|
|
107373
107549
|
});
|
|
107374
107550
|
|
|
107375
107551
|
// src/services/pricing-cache.ts
|
|
107376
|
-
import { existsSync as existsSync35, readFileSync as readFileSync40, statSync as
|
|
107552
|
+
import { existsSync as existsSync35, readFileSync as readFileSync40, statSync as statSync17 } from "fs";
|
|
107377
107553
|
import { homedir as homedir39 } from "os";
|
|
107378
107554
|
import { join as join49 } from "path";
|
|
107379
107555
|
function prefixMatch(modelName) {
|
|
@@ -107427,7 +107603,7 @@ function loadDiskCache() {
|
|
|
107427
107603
|
try {
|
|
107428
107604
|
if (!existsSync35(CACHE_FILE))
|
|
107429
107605
|
return false;
|
|
107430
|
-
const stat =
|
|
107606
|
+
const stat = statSync17(CACHE_FILE);
|
|
107431
107607
|
const age = Date.now() - stat.mtimeMs;
|
|
107432
107608
|
const isFresh = age < CACHE_TTL_MS5;
|
|
107433
107609
|
const raw = readFileSync40(CACHE_FILE, "utf-8");
|
|
@@ -112816,7 +112992,7 @@ import {
|
|
|
112816
112992
|
mkdirSync as mkdirSync24,
|
|
112817
112993
|
mkdtempSync as mkdtempSync2,
|
|
112818
112994
|
readFileSync as readFileSync42,
|
|
112819
|
-
statSync as
|
|
112995
|
+
statSync as statSync18,
|
|
112820
112996
|
writeFileSync as writeFileSync18
|
|
112821
112997
|
} from "fs";
|
|
112822
112998
|
import { join as join53, resolve as resolve5 } from "path";
|
|
@@ -112965,7 +113141,7 @@ function replaySettingsJson(statusLine) {
|
|
|
112965
113141
|
function readUserStatusLine(configDir) {
|
|
112966
113142
|
try {
|
|
112967
113143
|
const path = join53(configDir, "settings.json");
|
|
112968
|
-
if (
|
|
113144
|
+
if (statSync18(path).size > MAX_USER_SETTINGS_BYTES)
|
|
112969
113145
|
return null;
|
|
112970
113146
|
const v = JSON.parse(readFileSync42(path, "utf8"))?.statusLine;
|
|
112971
113147
|
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
@@ -113113,7 +113289,8 @@ async function assertMagmuxAvailable(binary) {
|
|
|
113113
113289
|
async function probeMagmux(binary) {
|
|
113114
113290
|
if (binary !== undefined)
|
|
113115
113291
|
return probeOneMagmux(binary);
|
|
113116
|
-
|
|
113292
|
+
const found = findMagmuxCandidates();
|
|
113293
|
+
return selectMagmux(found.paths, found.lookupError);
|
|
113117
113294
|
}
|
|
113118
113295
|
function isUsableMagmuxVersion(version) {
|
|
113119
113296
|
return /^0\./.test(version) && versionAtLeast(version, MIN_MAGMUX_VERSION);
|
|
@@ -113128,9 +113305,9 @@ async function probeOneMagmux(found) {
|
|
|
113128
113305
|
throw new MagmuxUnavailableError(`magmux_unavailable: ${found} is version ${version || "unknown"}${version && !/^0\./.test(version) ? " (not a 0.x release)" : ""}; panes need >= ${MIN_MAGMUX_VERSION} (${MAGMUX_NEEDS}); upgrade: brew upgrade MadAppGang/tap/magmux`);
|
|
113129
113306
|
return { binary: found, version };
|
|
113130
113307
|
}
|
|
113131
|
-
async function selectMagmux(candidates) {
|
|
113308
|
+
async function selectMagmux(candidates, lookupError = null) {
|
|
113132
113309
|
if (candidates.length === 0)
|
|
113133
|
-
throw
|
|
113310
|
+
throw noMagmuxFound(lookupError);
|
|
113134
113311
|
const refused = [];
|
|
113135
113312
|
for (const found of candidates) {
|
|
113136
113313
|
let version;
|
|
@@ -113151,7 +113328,13 @@ async function selectMagmux(candidates) {
|
|
|
113151
113328
|
else
|
|
113152
113329
|
refused.push(`${found} reports ${version}`);
|
|
113153
113330
|
}
|
|
113154
|
-
throw new MagmuxUnavailableError(`magmux_unavailable: no usable magmux; panes need a 0.x release >= ${MIN_MAGMUX_VERSION} (${MAGMUX_NEEDS}): ${refused.join(", ")}; upgrade: brew upgrade MadAppGang/tap/magmux`);
|
|
113331
|
+
throw new MagmuxUnavailableError(`magmux_unavailable: no usable magmux; panes need a 0.x release >= ${MIN_MAGMUX_VERSION} (${MAGMUX_NEEDS}): ${refused.join(", ")}${lookupNote(lookupError)}; upgrade: brew upgrade MadAppGang/tap/magmux`);
|
|
113332
|
+
}
|
|
113333
|
+
function lookupNote(lookupError) {
|
|
113334
|
+
return lookupError ? `; magmux lookup failed: ${lookupError}` : "";
|
|
113335
|
+
}
|
|
113336
|
+
function noMagmuxFound(lookupError) {
|
|
113337
|
+
return new MagmuxUnavailableError(lookupError ? `magmux_unavailable: magmux lookup failed: ${lookupError}` : "magmux_unavailable: magmux not found (bundled package or PATH); install it: brew install MadAppGang/tap/magmux");
|
|
113155
113338
|
}
|
|
113156
113339
|
async function readMagmuxVersion(found) {
|
|
113157
113340
|
const out = await runMagmuxVersion(found, MAGMUX_VERSION_TIMEOUT_MS);
|
|
@@ -113980,9 +114163,9 @@ var init_magmux_ui = __esm(() => {
|
|
|
113980
114163
|
});
|
|
113981
114164
|
|
|
113982
114165
|
// src/signal-exit-code.ts
|
|
113983
|
-
import { constants as
|
|
114166
|
+
import { constants as constants4 } from "os";
|
|
113984
114167
|
function signalExitCode(signal) {
|
|
113985
|
-
const signum =
|
|
114168
|
+
const signum = constants4.signals[signal];
|
|
113986
114169
|
return typeof signum === "number" ? 128 + signum : 128;
|
|
113987
114170
|
}
|
|
113988
114171
|
var init_signal_exit_code = () => {};
|
|
@@ -114050,7 +114233,7 @@ import {
|
|
|
114050
114233
|
readFileSync as readFileSync43,
|
|
114051
114234
|
readdirSync as readdirSync9,
|
|
114052
114235
|
rmSync as rmSync12,
|
|
114053
|
-
statSync as
|
|
114236
|
+
statSync as statSync19,
|
|
114054
114237
|
unlinkSync as unlinkSync11,
|
|
114055
114238
|
writeFileSync as writeFileSync19
|
|
114056
114239
|
} from "fs";
|
|
@@ -114418,7 +114601,7 @@ function gitDirOfFile(entry, readFile) {
|
|
|
114418
114601
|
}
|
|
114419
114602
|
function statPathKind(path) {
|
|
114420
114603
|
try {
|
|
114421
|
-
const stat =
|
|
114604
|
+
const stat = statSync19(path);
|
|
114422
114605
|
return stat.isDirectory() ? "dir" : "file";
|
|
114423
114606
|
} catch {
|
|
114424
114607
|
return;
|
|
@@ -114774,7 +114957,7 @@ function cleanupStaleTokenFiles(dir, now = Date.now(), maxAgeMs = STALE_TOKEN_FI
|
|
|
114774
114957
|
scanned++;
|
|
114775
114958
|
const full = join54(dir, name);
|
|
114776
114959
|
try {
|
|
114777
|
-
if (
|
|
114960
|
+
if (statSync19(full).mtimeMs >= cutoff)
|
|
114778
114961
|
continue;
|
|
114779
114962
|
unlinkSync11(full);
|
|
114780
114963
|
removed++;
|
|
@@ -116158,11 +116341,11 @@ var init_team_stats = __esm(() => {
|
|
|
116158
116341
|
});
|
|
116159
116342
|
|
|
116160
116343
|
// src/pane/accounting.ts
|
|
116161
|
-
import { statSync as
|
|
116344
|
+
import { statSync as statSync20 } from "fs";
|
|
116162
116345
|
function readTokenFileCached(path) {
|
|
116163
116346
|
let st;
|
|
116164
116347
|
try {
|
|
116165
|
-
const s =
|
|
116348
|
+
const s = statSync20(path);
|
|
116166
116349
|
st = { mtimeMs: s.mtimeMs, size: s.size };
|
|
116167
116350
|
} catch {
|
|
116168
116351
|
cache2.delete(path);
|
|
@@ -116342,7 +116525,7 @@ var init_endpoints = __esm(() => {
|
|
|
116342
116525
|
});
|
|
116343
116526
|
|
|
116344
116527
|
// src/view/endpoint-watch.ts
|
|
116345
|
-
import { statSync as
|
|
116528
|
+
import { statSync as statSync21, watch } from "fs";
|
|
116346
116529
|
|
|
116347
116530
|
class EndpointWatch {
|
|
116348
116531
|
o;
|
|
@@ -116389,7 +116572,7 @@ class EndpointWatch {
|
|
|
116389
116572
|
}
|
|
116390
116573
|
dirIno() {
|
|
116391
116574
|
try {
|
|
116392
|
-
return
|
|
116575
|
+
return statSync21(endpointsDirOf(this.o.root)).ino;
|
|
116393
116576
|
} catch {
|
|
116394
116577
|
return null;
|
|
116395
116578
|
}
|
|
@@ -116680,7 +116863,7 @@ import {
|
|
|
116680
116863
|
readdirSync as readdirSync11,
|
|
116681
116864
|
realpathSync as realpathSync7,
|
|
116682
116865
|
rmSync as rmSync14,
|
|
116683
|
-
statSync as
|
|
116866
|
+
statSync as statSync22,
|
|
116684
116867
|
writeFileSync as writeFileSync21
|
|
116685
116868
|
} from "fs";
|
|
116686
116869
|
import { basename as basename7, dirname as dirname22, join as join57, resolve as resolve7, sep } from "path";
|
|
@@ -116916,7 +117099,7 @@ function teamRunRowFromDisk(path, status) {
|
|
|
116916
117099
|
}
|
|
116917
117100
|
function statusMtimeMs(path) {
|
|
116918
117101
|
try {
|
|
116919
|
-
return
|
|
117102
|
+
return statSync22(join57(path, "status.json")).mtimeMs;
|
|
116920
117103
|
} catch {
|
|
116921
117104
|
return null;
|
|
116922
117105
|
}
|
|
@@ -117158,7 +117341,7 @@ function inBandErrorOf(input) {
|
|
|
117158
117341
|
const proven = marker !== null && proxyProvesInBandError(marker.code, input.proxyInBandError, input.turnStartedAt);
|
|
117159
117342
|
return proven ? marker : null;
|
|
117160
117343
|
}
|
|
117161
|
-
return parseInBandApiError(input.answer
|
|
117344
|
+
return parseInBandApiError(input.answer);
|
|
117162
117345
|
}
|
|
117163
117346
|
function classifyTurnSignals(input) {
|
|
117164
117347
|
const { stopReason, promptRead } = input;
|
|
@@ -117249,7 +117432,7 @@ function readWrittenFile(path, root) {
|
|
|
117249
117432
|
if (real !== realRoot && !real.startsWith(realRoot + sep))
|
|
117250
117433
|
return { skip: "outside the working directory" };
|
|
117251
117434
|
try {
|
|
117252
|
-
const st =
|
|
117435
|
+
const st = statSync22(real);
|
|
117253
117436
|
if (!st.isFile())
|
|
117254
117437
|
return { skip: "not a regular file" };
|
|
117255
117438
|
if (st.size > MAX_FILE_ANSWER_BYTES)
|
|
@@ -118360,7 +118543,7 @@ var init_team_orchestrator = __esm(() => {
|
|
|
118360
118543
|
});
|
|
118361
118544
|
|
|
118362
118545
|
// src/mcp-session/inherited-settings.ts
|
|
118363
|
-
import { existsSync as existsSync41, readFileSync as readFileSync46, statSync as
|
|
118546
|
+
import { existsSync as existsSync41, readFileSync as readFileSync46, statSync as statSync23 } from "fs";
|
|
118364
118547
|
import { join as join58, resolve as resolve8 } from "path";
|
|
118365
118548
|
function isPlainObject7(value) {
|
|
118366
118549
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -118448,7 +118631,7 @@ function resolveSetupFrom(arg, workDir, serverCwd) {
|
|
|
118448
118631
|
let setupFrom = serverCwd;
|
|
118449
118632
|
if (typeof arg === "string") {
|
|
118450
118633
|
setupFrom = resolve8(arg);
|
|
118451
|
-
if (!
|
|
118634
|
+
if (!statSync23(setupFrom, { throwIfNoEntry: false })?.isDirectory()) {
|
|
118452
118635
|
throw new Error(`invalid_args: setup_from ${setupFrom} is not an existing directory`);
|
|
118453
118636
|
}
|
|
118454
118637
|
} else if (arg !== undefined) {
|
|
@@ -118582,7 +118765,7 @@ import {
|
|
|
118582
118765
|
readSync as readSync7,
|
|
118583
118766
|
renameSync as renameSync10,
|
|
118584
118767
|
rmSync as rmSync15,
|
|
118585
|
-
statSync as
|
|
118768
|
+
statSync as statSync24,
|
|
118586
118769
|
writeFileSync as writeFileSync22
|
|
118587
118770
|
} from "fs";
|
|
118588
118771
|
import { join as join60, resolve as resolve9, sep as sep2 } from "path";
|
|
@@ -118692,7 +118875,7 @@ function anomalyKey(a) {
|
|
|
118692
118875
|
function readTailText(path, maxBytes) {
|
|
118693
118876
|
let fd = null;
|
|
118694
118877
|
try {
|
|
118695
|
-
const size =
|
|
118878
|
+
const size = statSync24(path).size;
|
|
118696
118879
|
if (size === 0)
|
|
118697
118880
|
return { text: "", truncated: false };
|
|
118698
118881
|
const start = Math.max(0, size - maxBytes);
|
|
@@ -118723,7 +118906,7 @@ function readTailLines2(path, maxBytes) {
|
|
|
118723
118906
|
}
|
|
118724
118907
|
function fileSize2(path) {
|
|
118725
118908
|
try {
|
|
118726
|
-
return
|
|
118909
|
+
return statSync24(path).size;
|
|
118727
118910
|
} catch {
|
|
118728
118911
|
return 0;
|
|
118729
118912
|
}
|
|
@@ -119557,7 +119740,7 @@ class SessionManager {
|
|
|
119557
119740
|
if (sessionDir === null)
|
|
119558
119741
|
return null;
|
|
119559
119742
|
try {
|
|
119560
|
-
if (!
|
|
119743
|
+
if (!statSync24(sessionDir).isDirectory())
|
|
119561
119744
|
return null;
|
|
119562
119745
|
} catch {
|
|
119563
119746
|
return null;
|
|
@@ -119697,7 +119880,7 @@ class SessionManager {
|
|
|
119697
119880
|
return null;
|
|
119698
119881
|
let dirMtimeMs;
|
|
119699
119882
|
try {
|
|
119700
|
-
const stat =
|
|
119883
|
+
const stat = statSync24(sessionDir);
|
|
119701
119884
|
if (!stat.isDirectory())
|
|
119702
119885
|
return null;
|
|
119703
119886
|
dirMtimeMs = stat.mtimeMs;
|
|
@@ -120059,7 +120242,7 @@ var init_session_manager = __esm(() => {
|
|
|
120059
120242
|
});
|
|
120060
120243
|
|
|
120061
120244
|
// src/view/history.ts
|
|
120062
|
-
import { closeSync as closeSync17, openSync as openSync17, readSync as readSync8, readdirSync as readdirSync12, statSync as
|
|
120245
|
+
import { closeSync as closeSync17, openSync as openSync17, readSync as readSync8, readdirSync as readdirSync12, statSync as statSync25 } from "fs";
|
|
120063
120246
|
import { join as join61 } from "path";
|
|
120064
120247
|
function finishedDetail(promptSummary) {
|
|
120065
120248
|
return {
|
|
@@ -120102,7 +120285,7 @@ function runDirs(sessionsDir) {
|
|
|
120102
120285
|
const dated = [];
|
|
120103
120286
|
for (const name of names) {
|
|
120104
120287
|
try {
|
|
120105
|
-
const st =
|
|
120288
|
+
const st = statSync25(join61(sessionsDir, name));
|
|
120106
120289
|
if (st.isDirectory())
|
|
120107
120290
|
dated.push({ name, mtimeMs: st.mtimeMs });
|
|
120108
120291
|
} catch {}
|
|
@@ -120763,8 +120946,8 @@ var init_feed_relay = __esm(() => {
|
|
|
120763
120946
|
|
|
120764
120947
|
// src/pane/pane-registry.ts
|
|
120765
120948
|
import {
|
|
120766
|
-
constants as
|
|
120767
|
-
accessSync as
|
|
120949
|
+
constants as constants5,
|
|
120950
|
+
accessSync as accessSync3,
|
|
120768
120951
|
existsSync as existsSync43,
|
|
120769
120952
|
lstatSync as lstatSync9,
|
|
120770
120953
|
readFileSync as readFileSync49,
|
|
@@ -121142,7 +121325,7 @@ function dialErrno(reported, sockPath) {
|
|
|
121142
121325
|
if (!isSocket)
|
|
121143
121326
|
return "ENOTSOCK";
|
|
121144
121327
|
try {
|
|
121145
|
-
|
|
121328
|
+
accessSync3(sockPath, constants5.W_OK);
|
|
121146
121329
|
} catch {
|
|
121147
121330
|
return "EACCES";
|
|
121148
121331
|
}
|
|
@@ -121657,35 +121840,6 @@ var init_session_registry = __esm(() => {
|
|
|
121657
121840
|
KNOWN_STATUSES = new Set(["idle", "busy", "waiting", "shell"]);
|
|
121658
121841
|
});
|
|
121659
121842
|
|
|
121660
|
-
// src/pane/settled-turn.ts
|
|
121661
|
-
function settledTurnCoreOf(t, decision, ctx) {
|
|
121662
|
-
const d = ctx.delivery;
|
|
121663
|
-
const unverified = d?.mode === "command" && !!t.delivery && t.readCoverage.reads === 0;
|
|
121664
|
-
const local = decision.by === "local_command";
|
|
121665
|
-
const core = {
|
|
121666
|
-
index: t.index,
|
|
121667
|
-
answer: local ? t.localCommandOutput ?? "" : t.assistantText.join(`
|
|
121668
|
-
|
|
121669
|
-
`),
|
|
121670
|
-
...local || !t.lastResponseEnd ? {} : { lastResponseEnd: t.lastResponseEnd },
|
|
121671
|
-
acceptedAt: t.acceptedAt,
|
|
121672
|
-
apiError: t.apiError,
|
|
121673
|
-
stopReason: decision.stopReason,
|
|
121674
|
-
captureSource: "transcript",
|
|
121675
|
-
settledBy: decision.by,
|
|
121676
|
-
shape: ctx.shape,
|
|
121677
|
-
delivery: {
|
|
121678
|
-
mode: d && d.mode !== "refused" ? d.mode : "typed",
|
|
121679
|
-
linesTotal: t.delivery ? t.delivery.lines : null,
|
|
121680
|
-
linesRead: t.delivery ? t.readCoverage.linesReturned : null,
|
|
121681
|
-
complete: t.delivery && !unverified ? t.readCoverage.complete : null,
|
|
121682
|
-
preambleBytes: t.preambleBytes
|
|
121683
|
-
},
|
|
121684
|
-
writtenFiles: local ? [] : t.writtenFiles
|
|
121685
|
-
};
|
|
121686
|
-
return { core, unverified };
|
|
121687
|
-
}
|
|
121688
|
-
|
|
121689
121843
|
// src/pane/slot-state.ts
|
|
121690
121844
|
function nextPhase(from, ev) {
|
|
121691
121845
|
const row = TRANSITIONS2[from];
|
|
@@ -121820,7 +121974,7 @@ var init_view_socket = __esm(() => {
|
|
|
121820
121974
|
});
|
|
121821
121975
|
|
|
121822
121976
|
// src/pane/pane-session.ts
|
|
121823
|
-
import { readFileSync as readFileSync51, realpathSync as realpathSync9, rmSync as rmSync18, statSync as
|
|
121977
|
+
import { readFileSync as readFileSync51, realpathSync as realpathSync9, rmSync as rmSync18, statSync as statSync26, writeFileSync as writeFileSync25 } from "fs";
|
|
121824
121978
|
import { join as join66 } from "path";
|
|
121825
121979
|
function clearKeyCount(line, attempts, cols) {
|
|
121826
121980
|
const cells = 2 * Math.max(1, attempts) * Bun.stringWidth(line);
|
|
@@ -121922,6 +122076,12 @@ class PaneSessionImpl {
|
|
|
121922
122076
|
trustedGen = 0;
|
|
121923
122077
|
trustEpoch = 0;
|
|
121924
122078
|
lastFrameGen = 0;
|
|
122079
|
+
trustedFramesFrom = 0;
|
|
122080
|
+
lastInputAt = 0;
|
|
122081
|
+
inputsInFlight = 0;
|
|
122082
|
+
inputSeq = 0;
|
|
122083
|
+
lostInputs = new Map;
|
|
122084
|
+
answeredInputs = new WeakMap;
|
|
121925
122085
|
gateInFlight = false;
|
|
121926
122086
|
gateTimer = null;
|
|
121927
122087
|
gateDeadSince = 0;
|
|
@@ -122121,10 +122281,14 @@ class PaneSessionImpl {
|
|
|
122121
122281
|
const bound = await this.awaitBoundPane(client, reconnect, magmuxVersion);
|
|
122122
122282
|
if (!bound)
|
|
122123
122283
|
return;
|
|
122284
|
+
this.noteTrusted(gen);
|
|
122285
|
+
this.onGateList(client, bound);
|
|
122286
|
+
}
|
|
122287
|
+
noteTrusted(gen) {
|
|
122124
122288
|
this.trustedGen = gen;
|
|
122125
122289
|
this.trustEpoch++;
|
|
122290
|
+
this.trustedFramesFrom = this.lastFrameGen === gen ? Date.now() : null;
|
|
122126
122291
|
this.gateTrusted = true;
|
|
122127
|
-
this.onGateList(client, bound);
|
|
122128
122292
|
}
|
|
122129
122293
|
async awaitBoundPane(client, reconnect, magmuxVersion) {
|
|
122130
122294
|
let list = await client.request({ type: "list" });
|
|
@@ -122284,6 +122448,8 @@ class PaneSessionImpl {
|
|
|
122284
122448
|
if (f.pane !== undefined && f.pane !== 0)
|
|
122285
122449
|
return;
|
|
122286
122450
|
this.lastFrameGen = gen;
|
|
122451
|
+
if (this.trustedFramesFrom === null && gen === this.trustedGen && this.gateTrusted)
|
|
122452
|
+
this.trustedFramesFrom = Date.now();
|
|
122287
122453
|
const seq = this.screen.seq;
|
|
122288
122454
|
this.screen = applyFrame(this.screen, f);
|
|
122289
122455
|
if (this.screen.seq !== seq && !this.inResizeQuiet(this.screen.changedAt))
|
|
@@ -122784,20 +122950,15 @@ ${gate}`
|
|
|
122784
122950
|
this.abandonedIndex = null;
|
|
122785
122951
|
if (plan.mode === "refused" || plan.mode === "control") {
|
|
122786
122952
|
this.anomaly(`delivery_refused:${plan.mode === "refused" ? plan.reason : "control"}`);
|
|
122787
|
-
this.
|
|
122788
|
-
if (item.kind === "hook") {
|
|
122789
|
-
this.hookAdmissionFailed(item);
|
|
122790
|
-
return;
|
|
122791
|
-
}
|
|
122792
|
-
this.fire(initial ? "admit_deadline" : "admit_abandoned", {
|
|
122793
|
-
detail: plan.mode === "refused" ? plan.reason : undefined
|
|
122794
|
-
});
|
|
122953
|
+
this.failAdmissionUntyped(item, initial, plan.mode === "refused" ? plan.reason : undefined);
|
|
122795
122954
|
return;
|
|
122796
122955
|
}
|
|
122797
122956
|
try {
|
|
122798
122957
|
writeTurnFile(plan);
|
|
122799
122958
|
} catch (e) {
|
|
122800
122959
|
this.anomaly(`turn_file_failed:${e instanceof Error ? e.message : String(e)}`);
|
|
122960
|
+
this.failAdmissionUntyped(item, initial, "turn_file_failed");
|
|
122961
|
+
return;
|
|
122801
122962
|
}
|
|
122802
122963
|
const delivery = (plan.mode === "file" || plan.mode === "command") && plan.file && plan.fileContent !== undefined ? { file: plan.file, text: plan.fileContent } : null;
|
|
122803
122964
|
this.follower.openTurn({ index, offset, witness: plan.witness, delivery });
|
|
@@ -122813,6 +122974,14 @@ ${gate}`
|
|
|
122813
122974
|
this.admission = adm;
|
|
122814
122975
|
this.runAdmission(adm);
|
|
122815
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
|
+
}
|
|
122816
122985
|
admitting(adm) {
|
|
122817
122986
|
return this.admission === adm && this.phase === "ADMITTING";
|
|
122818
122987
|
}
|
|
@@ -122870,8 +123039,10 @@ ${gate}`
|
|
|
122870
123039
|
const step = adm.step;
|
|
122871
123040
|
const shape = sendShape(step, adm.line);
|
|
122872
123041
|
const rt = readyTimeoutFor(step, adm.line, adm.deadline - Date.now());
|
|
122873
|
-
if (rt === null)
|
|
123042
|
+
if (rt === null) {
|
|
123043
|
+
this.anomaly(`send_no_room:${step}`);
|
|
122874
123044
|
return false;
|
|
123045
|
+
}
|
|
122875
123046
|
const timeout = sendBudgetMs({ ...shape.budget, readyTimeoutMs: rt }) + SEND_CLIENT_SLACK_MS2;
|
|
122876
123047
|
this.follower.holdTurn(false);
|
|
122877
123048
|
const sentAt = Date.now();
|
|
@@ -122879,7 +123050,7 @@ ${gate}`
|
|
|
122879
123050
|
adm.attempts++;
|
|
122880
123051
|
let reply;
|
|
122881
123052
|
try {
|
|
122882
|
-
reply = await
|
|
123053
|
+
reply = await this.writeInput(c, { ...shape.msg, readyTimeoutMs: rt }, timeout);
|
|
122883
123054
|
} finally {
|
|
122884
123055
|
adm.inFlight = false;
|
|
122885
123056
|
}
|
|
@@ -123100,26 +123271,32 @@ ${gate}`
|
|
|
123100
123271
|
}
|
|
123101
123272
|
async waitDrawn(o) {
|
|
123102
123273
|
let epoch = this.trustEpoch;
|
|
123274
|
+
let epochSeenAt = 0;
|
|
123103
123275
|
let last;
|
|
123104
|
-
|
|
123276
|
+
const waitStartedAt = Date.now();
|
|
123277
|
+
let changedAt = waitStartedAt;
|
|
123105
123278
|
let wholeShown = false;
|
|
123106
123279
|
let ended = null;
|
|
123280
|
+
const floor = () => this.inputReplyLost() ? waitStartedAt : 0;
|
|
123107
123281
|
const settle = () => {
|
|
123108
123282
|
const at = Date.now();
|
|
123109
123283
|
if (this.trustEpoch !== epoch) {
|
|
123110
123284
|
epoch = this.trustEpoch;
|
|
123285
|
+
epochSeenAt = at;
|
|
123111
123286
|
last = undefined;
|
|
123112
123287
|
wholeShown = false;
|
|
123113
123288
|
}
|
|
123114
123289
|
const now = this.drawnBox(o.against);
|
|
123115
123290
|
if (now === undefined || last === undefined || !sameDrawnBox(now, last)) {
|
|
123116
123291
|
last = now;
|
|
123117
|
-
changedAt = at;
|
|
123292
|
+
changedAt = now === undefined ? at : Math.max(this.boxUnchangedSince(at), epochSeenAt, floor());
|
|
123118
123293
|
if (now !== undefined)
|
|
123119
123294
|
o.onRead?.(now);
|
|
123120
123295
|
if (now?.match === "line")
|
|
123121
123296
|
wholeShown = true;
|
|
123122
123297
|
}
|
|
123298
|
+
if (now !== undefined)
|
|
123299
|
+
changedAt = Math.max(changedAt, this.boxUnchangedSince(at), epochSeenAt, floor());
|
|
123123
123300
|
ended = drawEnded(now, wholeShown && o.earlier || o.emptyEnds?.() === true, at - changedAt, o.partOnly ?? null);
|
|
123124
123301
|
if (ended === "settled" && o.shownEnds?.() === false)
|
|
123125
123302
|
ended = null;
|
|
@@ -123171,7 +123348,7 @@ ${gate}`
|
|
|
123171
123348
|
this.acceptAdmission(adm);
|
|
123172
123349
|
return;
|
|
123173
123350
|
}
|
|
123174
|
-
if (copy === adm.line && this.unreadCopy === copy) {
|
|
123351
|
+
if (copy === adm.line && this.unreadCopy === copy && this.unreadCopyWitness?.kind !== "turn_file") {
|
|
123175
123352
|
adm.leftoverOf = copy;
|
|
123176
123353
|
this.unreadCopyReadWhole = true;
|
|
123177
123354
|
await this.awaitCopyRecord(adm);
|
|
@@ -123183,8 +123360,9 @@ ${gate}`
|
|
|
123183
123360
|
this.forgetCopy();
|
|
123184
123361
|
}
|
|
123185
123362
|
departCopy() {
|
|
123186
|
-
|
|
123187
|
-
|
|
123363
|
+
const w = this.unreadCopyWitness;
|
|
123364
|
+
if (w && w.kind !== "turn_file")
|
|
123365
|
+
this.follower.refuseDeparted(w, this.unreadCopyAfter);
|
|
123188
123366
|
this.forgetCopy();
|
|
123189
123367
|
}
|
|
123190
123368
|
async awaitCopyRecord(adm) {
|
|
@@ -123398,7 +123576,7 @@ ${screenTailOf(this.screen)}` });
|
|
|
123398
123576
|
const shape = sendShape("submit", line);
|
|
123399
123577
|
this.rememberCopy(line, { kind: "command", name: line.slice(1), line }, mark);
|
|
123400
123578
|
const gen = this.unreadCopyGen;
|
|
123401
|
-
const r = await
|
|
123579
|
+
const r = await this.writeInput(c, { ...shape.msg, readyTimeoutMs: rt }, sendBudgetMs({ ...shape.budget, readyTimeoutMs: rt }) + SEND_CLIENT_SLACK_MS2);
|
|
123402
123580
|
const out = classifySendReply(r);
|
|
123403
123581
|
const s = this.noteLastSend(out, 1);
|
|
123404
123582
|
const own = this.unreadCopy !== null && this.unreadCopyGen === gen;
|
|
@@ -123463,11 +123641,47 @@ ${screenTailOf(this.screen)}` });
|
|
|
123463
123641
|
keysWithheld() {
|
|
123464
123642
|
return this.unreadCopy !== null && !this.unreadCopyReadWhole;
|
|
123465
123643
|
}
|
|
123644
|
+
async writeInput(c, msg, ms) {
|
|
123645
|
+
const seq = ++this.inputSeq;
|
|
123646
|
+
this.inputsInFlight++;
|
|
123647
|
+
let reply;
|
|
123648
|
+
try {
|
|
123649
|
+
reply = await c.request(msg, ms);
|
|
123650
|
+
return reply;
|
|
123651
|
+
} finally {
|
|
123652
|
+
this.inputsInFlight--;
|
|
123653
|
+
this.lastInputAt = Date.now();
|
|
123654
|
+
if (reply)
|
|
123655
|
+
this.noteInputReply(c, seq, reply);
|
|
123656
|
+
}
|
|
123657
|
+
}
|
|
123658
|
+
noteInputReply(c, seq, r) {
|
|
123659
|
+
if (!r.ok && LOST_REPLY_CODES.has(r.code)) {
|
|
123660
|
+
if ((this.answeredInputs.get(c) ?? 0) > seq)
|
|
123661
|
+
return;
|
|
123662
|
+
this.lostInputs.set(c, Math.max(this.lostInputs.get(c) ?? 0, seq));
|
|
123663
|
+
return;
|
|
123664
|
+
}
|
|
123665
|
+
if (!r.ok && UNANSWERED_CODES.has(r.code))
|
|
123666
|
+
return;
|
|
123667
|
+
this.answeredInputs.set(c, Math.max(this.answeredInputs.get(c) ?? 0, seq));
|
|
123668
|
+
const lost = this.lostInputs.get(c);
|
|
123669
|
+
if (lost !== undefined && lost < seq)
|
|
123670
|
+
this.lostInputs.delete(c);
|
|
123671
|
+
}
|
|
123672
|
+
inputReplyLost() {
|
|
123673
|
+
return this.lostInputs.size > 0;
|
|
123674
|
+
}
|
|
123675
|
+
boxUnchangedSince(at) {
|
|
123676
|
+
if (this.inputsInFlight > 0 || this.trustedFramesFrom === null)
|
|
123677
|
+
return at;
|
|
123678
|
+
return Math.min(at, Math.max(this.screen.boxChangedAt, this.trustedFramesFrom, this.lastInputAt));
|
|
123679
|
+
}
|
|
123466
123680
|
async keys(ks) {
|
|
123467
123681
|
const c = this.client;
|
|
123468
123682
|
if (!c)
|
|
123469
123683
|
return false;
|
|
123470
|
-
const r = await
|
|
123684
|
+
const r = await this.writeInput(c, { type: "send", pane: 0, keys: ks, enter: false, noGate: true }, 1e4);
|
|
123471
123685
|
return r.ok;
|
|
123472
123686
|
}
|
|
123473
123687
|
nextFrame(ms) {
|
|
@@ -123590,6 +123804,8 @@ ${screenTailOf(this.screen)}` });
|
|
|
123590
123804
|
return;
|
|
123591
123805
|
}
|
|
123592
123806
|
if (adm.readWhole && adm.submittedUnproven !== null) {
|
|
123807
|
+
if ("witness" in adm.plan && adm.plan.witness.kind === "turn_file")
|
|
123808
|
+
return;
|
|
123593
123809
|
this.rememberCopy(adm.line, "witness" in adm.plan ? adm.plan.witness : { kind: "text", text: adm.line }, adm.mark);
|
|
123594
123810
|
this.unreadCopyReadWhole = true;
|
|
123595
123811
|
return;
|
|
@@ -123716,6 +123932,7 @@ ${screenTailOf(this.screen)}`
|
|
|
123716
123932
|
this.returnToLiveBottom(SCROLL_REPLY_MS);
|
|
123717
123933
|
this.screenTurn = {
|
|
123718
123934
|
echo: d && d.mode !== "refused" ? d.line : "",
|
|
123935
|
+
turnFile: d && d.mode === "file" ? d.file : null,
|
|
123719
123936
|
acceptedAt: at,
|
|
123720
123937
|
errorLogSize: this.turnErrorLogSize
|
|
123721
123938
|
};
|
|
@@ -123984,6 +124201,7 @@ ${screenTailOf(this.screen)}`
|
|
|
123984
124201
|
p = Promise.resolve(binding.settle({
|
|
123985
124202
|
index: turn.index,
|
|
123986
124203
|
answer: turn.answer,
|
|
124204
|
+
answerWithheld: turn.delivery.complete === false,
|
|
123987
124205
|
stopReason: turn.stopReason,
|
|
123988
124206
|
apiError: turn.apiError !== null,
|
|
123989
124207
|
hookCaused: turn.hookCaused,
|
|
@@ -124214,7 +124432,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124214
124432
|
return;
|
|
124215
124433
|
if (!this.client)
|
|
124216
124434
|
return;
|
|
124217
|
-
const answer = screenAnswer(this.screen, st.echo);
|
|
124435
|
+
const answer = screenAnswer(this.screen, st.echo, st.turnFile);
|
|
124218
124436
|
const apiError = this.screenApiError(st, answer);
|
|
124219
124437
|
this.activity = "thinking";
|
|
124220
124438
|
if (!this.screenViewLive() || !this.screenSettleReady(view, answer, apiError))
|
|
@@ -124267,10 +124485,10 @@ ${screenTailOf(this.screen)}`
|
|
|
124267
124485
|
return false;
|
|
124268
124486
|
const notes = [];
|
|
124269
124487
|
let core = this.settledTurnOf(turn, decision, (key) => notes.push(key));
|
|
124270
|
-
if (!core.answer && !core.apiError) {
|
|
124488
|
+
if (!core.answer && !core.apiError && core.delivery.complete !== false) {
|
|
124271
124489
|
if (!this.client || !this.screenViewLive())
|
|
124272
124490
|
return false;
|
|
124273
|
-
const answer = screenAnswer(this.screen, st.echo);
|
|
124491
|
+
const answer = screenAnswer(this.screen, st.echo, st.turnFile);
|
|
124274
124492
|
core = {
|
|
124275
124493
|
...core,
|
|
124276
124494
|
answer,
|
|
@@ -124297,7 +124515,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124297
124515
|
if (!p)
|
|
124298
124516
|
return 0;
|
|
124299
124517
|
try {
|
|
124300
|
-
return
|
|
124518
|
+
return statSync26(p).size;
|
|
124301
124519
|
} catch {
|
|
124302
124520
|
return 0;
|
|
124303
124521
|
}
|
|
@@ -124407,9 +124625,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124407
124625
|
tokensIn: hasTranscript ? view.usage.tokensIn : null,
|
|
124408
124626
|
tokensOut: hasTranscript ? view.usage.tokensOut : null,
|
|
124409
124627
|
toolCalls: view.toolCalls,
|
|
124410
|
-
liveAnswerBytes: cur ? Buffer.byteLength(
|
|
124411
|
-
|
|
124412
|
-
`)) : 0,
|
|
124628
|
+
liveAnswerBytes: cur ? Buffer.byteLength(this.liveAnswerOf(cur)) : 0,
|
|
124413
124629
|
exitCode: this.exitCode,
|
|
124414
124630
|
captureSource: this.lastCaptureSource,
|
|
124415
124631
|
turnSource: this.turnSource,
|
|
@@ -124621,7 +124837,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124621
124837
|
this.scrollPos = plan.next;
|
|
124622
124838
|
const seq0 = this.screen.seq;
|
|
124623
124839
|
this.extendResizeQuiet();
|
|
124624
|
-
const r = await
|
|
124840
|
+
const r = await this.writeInput(c, { type: "send", pane: 0, text: plan.bytes, enter: false, noGate: true }, SCROLL_REPLY_MS);
|
|
124625
124841
|
if (!r.ok) {
|
|
124626
124842
|
this.scrollPos = UNKNOWN_POSITION;
|
|
124627
124843
|
if (r.code === "client_lost" || r.code === "client_timeout")
|
|
@@ -124664,7 +124880,7 @@ ${screenTailOf(this.screen)}`
|
|
|
124664
124880
|
this.extendResizeQuiet();
|
|
124665
124881
|
this.scrollEndsInFlight++;
|
|
124666
124882
|
try {
|
|
124667
|
-
const r = await
|
|
124883
|
+
const r = await this.writeInput(c, { type: "send", pane: 0, text: CTRL_END, enter: false, noGate: true }, Math.min(SCROLL_REPLY_MS, ms));
|
|
124668
124884
|
if (r.ok) {
|
|
124669
124885
|
this.scrollEndConfirmedAt = Date.now();
|
|
124670
124886
|
} else {
|
|
@@ -124680,18 +124896,17 @@ ${screenTailOf(this.screen)}`
|
|
|
124680
124896
|
if (done !== undefined)
|
|
124681
124897
|
return done;
|
|
124682
124898
|
const cur = this.follower.view().current;
|
|
124683
|
-
return cur && cur.index === index ?
|
|
124684
|
-
|
|
124685
|
-
|
|
124899
|
+
return cur && cur.index === index ? this.liveAnswerOf(cur) : "";
|
|
124900
|
+
}
|
|
124901
|
+
liveAnswerOf(cur) {
|
|
124902
|
+
return answerOf(cur, this.currentDelivery?.mode ?? null);
|
|
124686
124903
|
}
|
|
124687
124904
|
chainText() {
|
|
124688
124905
|
const parts = this.chain.map((c) => c.answer);
|
|
124689
124906
|
const lastIndex = this.chain[this.chain.length - 1]?.index ?? 0;
|
|
124690
124907
|
const cur = this.follower.view().current;
|
|
124691
124908
|
if (cur && cur.index > lastIndex)
|
|
124692
|
-
parts.push(
|
|
124693
|
-
|
|
124694
|
-
`));
|
|
124909
|
+
parts.push(this.liveAnswerOf(cur));
|
|
124695
124910
|
return parts.filter((a) => a !== "").join(`
|
|
124696
124911
|
|
|
124697
124912
|
`);
|
|
@@ -125147,7 +125362,7 @@ async function startPaneSession(o) {
|
|
|
125147
125362
|
await session.start({ magmuxBinary: magmux.binary, env: p.magmuxEnv, cwd: p.cwd });
|
|
125148
125363
|
return session;
|
|
125149
125364
|
}
|
|
125150
|
-
var BOOT_TIMEOUT_MS = 90000, ADMIT_TIMEOUT_MS = 30000, UNPROVEN_RECORD_WAIT_MS = 120000, DEGRADED_ENTRY_MS = 1e4, SCREEN_SETTLE_QUIET_MS = 3000, PANEL_SETTLE_MS = 500, SEND_CLIENT_SLACK_MS2 = 2000, MIN_READY_TIMEOUT_MS = 1000, ENTER_MIN_READY_TIMEOUT_MS = 250, BUSY_RETRY_MS = 250, CLEAR_WAIT_MS = 1000, DRAW_SETTLE_MS = 2000, BOOT_STATIC_MS = 5000, TICK_MS2 = 250, WATCH_FPS2 = 4, POLL_BACKSTOP_MS = 1000, TURN_END_MISSING_FACTOR = 3, RESIZE_REPLY_MS = 1e4, RESIZE_SCREEN_MS = 1000, SCROLL_REPLY_MS = 5000, SCROLL_SCREEN_MS = 1000, GATE_POLL_MS = 250, GATE_REPLY_MS = 1000, GATE_STALE_MS2 = 1000, GATE_GRACE_MS, GATE_DEAD_BACKSTOP_MS = 1000, EXIT_CODE_QUERY_MS = 2000, EXIT_CODE_RETRY_MS = 50, GATE_KINDLESS_REASONS, RUNTIME_DIALOG_KINDS, REGISTRY_READ_MS = 250, REGISTRY_DISAGREE_MS = 2000, REGISTRY_GATE_BOOT_DISAGREE_MS = 5000, REGISTRY_MISSING_MS = 5000, MAX_ANOMALY_KEYS = 64, KEPT_ANSWERS = 4, DEFAULT_MAX_CONSECUTIVE2 = 3, EVENT_REASON, VERDICT_EVENT, EARLIER_COPY_SEEN, PaneStartError;
|
|
125365
|
+
var BOOT_TIMEOUT_MS = 90000, ADMIT_TIMEOUT_MS = 30000, UNPROVEN_RECORD_WAIT_MS = 120000, DEGRADED_ENTRY_MS = 1e4, SCREEN_SETTLE_QUIET_MS = 3000, PANEL_SETTLE_MS = 500, SEND_CLIENT_SLACK_MS2 = 2000, LOST_REPLY_CODES, UNANSWERED_CODES, MIN_READY_TIMEOUT_MS = 1000, ENTER_MIN_READY_TIMEOUT_MS = 250, BUSY_RETRY_MS = 250, CLEAR_WAIT_MS = 1000, DRAW_SETTLE_MS = 2000, BOOT_STATIC_MS = 5000, TICK_MS2 = 250, WATCH_FPS2 = 4, POLL_BACKSTOP_MS = 1000, TURN_END_MISSING_FACTOR = 3, RESIZE_REPLY_MS = 1e4, RESIZE_SCREEN_MS = 1000, SCROLL_REPLY_MS = 5000, SCROLL_SCREEN_MS = 1000, GATE_POLL_MS = 250, GATE_REPLY_MS = 1000, GATE_STALE_MS2 = 1000, GATE_GRACE_MS, GATE_DEAD_BACKSTOP_MS = 1000, EXIT_CODE_QUERY_MS = 2000, EXIT_CODE_RETRY_MS = 50, GATE_KINDLESS_REASONS, RUNTIME_DIALOG_KINDS, REGISTRY_READ_MS = 250, REGISTRY_DISAGREE_MS = 2000, REGISTRY_GATE_BOOT_DISAGREE_MS = 5000, REGISTRY_MISSING_MS = 5000, MAX_ANOMALY_KEYS = 64, KEPT_ANSWERS = 4, DEFAULT_MAX_CONSECUTIVE2 = 3, EVENT_REASON, VERDICT_EVENT, EARLIER_COPY_SEEN, PaneStartError;
|
|
125151
125366
|
var init_pane_session = __esm(() => {
|
|
125152
125367
|
init_claude_code_facts();
|
|
125153
125368
|
init_queue();
|
|
@@ -125173,6 +125388,12 @@ var init_pane_session = __esm(() => {
|
|
|
125173
125388
|
init_slot_state();
|
|
125174
125389
|
init_transcript_follower();
|
|
125175
125390
|
init_view_socket();
|
|
125391
|
+
LOST_REPLY_CODES = new Set(["client_timeout", "client_lost", "timeout"]);
|
|
125392
|
+
UNANSWERED_CODES = new Set([
|
|
125393
|
+
"client_closed",
|
|
125394
|
+
"no_client",
|
|
125395
|
+
"bad_request"
|
|
125396
|
+
]);
|
|
125176
125397
|
GATE_GRACE_MS = SECONDARY_QUIET_MS;
|
|
125177
125398
|
GATE_KINDLESS_REASONS = new Set([
|
|
125178
125399
|
"starting",
|
|
@@ -126102,7 +126323,7 @@ var init_transcript_lines = __esm(() => {
|
|
|
126102
126323
|
CronCreate: (i) => str5(i.cron),
|
|
126103
126324
|
ScheduleWakeup: (i) => str5(i.reason)
|
|
126104
126325
|
};
|
|
126105
|
-
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$/;
|
|
126106
126327
|
COMMAND_NAME_RE = /<command-name>([\s\S]*?)<\/command-name>/;
|
|
126107
126328
|
COMMAND_ARGS_RE = /<command-args>([\s\S]*?)<\/command-args>/;
|
|
126108
126329
|
CAVEAT_RE = /^\s*<local-command-caveat>/;
|
|
@@ -126245,7 +126466,7 @@ var init_transcript_redaction = __esm(() => {
|
|
|
126245
126466
|
|
|
126246
126467
|
// src/pane/transcript-page.ts
|
|
126247
126468
|
import {
|
|
126248
|
-
constants as
|
|
126469
|
+
constants as constants6,
|
|
126249
126470
|
closeSync as closeSync18,
|
|
126250
126471
|
fstatSync as fstatSync5,
|
|
126251
126472
|
lstatSync as lstatSync10,
|
|
@@ -126254,7 +126475,7 @@ import {
|
|
|
126254
126475
|
readdirSync as readdirSync15,
|
|
126255
126476
|
readlinkSync,
|
|
126256
126477
|
realpathSync as realpathSync10,
|
|
126257
|
-
statSync as
|
|
126478
|
+
statSync as statSync27
|
|
126258
126479
|
} from "fs";
|
|
126259
126480
|
import { basename as basename10, dirname as dirname26, join as join68, sep as sep3 } from "path";
|
|
126260
126481
|
function isUuid(v) {
|
|
@@ -126408,7 +126629,7 @@ function locateTranscriptByUuid(projectsRoot, uuid) {
|
|
|
126408
126629
|
for (const d of dirs) {
|
|
126409
126630
|
const p = join68(projectsRoot, d, `${uuid}.jsonl`);
|
|
126410
126631
|
try {
|
|
126411
|
-
if (!
|
|
126632
|
+
if (!statSync27(p).isFile())
|
|
126412
126633
|
continue;
|
|
126413
126634
|
} catch {
|
|
126414
126635
|
continue;
|
|
@@ -126436,7 +126657,7 @@ function writerLiveness(pid) {
|
|
|
126436
126657
|
}
|
|
126437
126658
|
function fileAgeMs(path, now = Date.now()) {
|
|
126438
126659
|
try {
|
|
126439
|
-
return now -
|
|
126660
|
+
return now - statSync27(path).mtimeMs;
|
|
126440
126661
|
} catch {
|
|
126441
126662
|
return null;
|
|
126442
126663
|
}
|
|
@@ -126611,7 +126832,7 @@ var init_transcript_page = __esm(() => {
|
|
|
126611
126832
|
maxEntryBytes: 32 * 1024 * 1024
|
|
126612
126833
|
};
|
|
126613
126834
|
READ_CHUNK = 1024 * 1024;
|
|
126614
|
-
OPEN_FLAGS =
|
|
126835
|
+
OPEN_FLAGS = constants6.O_RDONLY | (constants6.O_NOFOLLOW ?? 0) | (constants6.O_NONBLOCK ?? 0);
|
|
126615
126836
|
loggedRejections = new Set;
|
|
126616
126837
|
HEAD_CWD_MAX_BYTES = 256 * 1024;
|
|
126617
126838
|
});
|
|
@@ -126641,7 +126862,7 @@ var init_pane = __esm(() => {
|
|
|
126641
126862
|
});
|
|
126642
126863
|
|
|
126643
126864
|
// src/view/kernel-lock.ts
|
|
126644
|
-
import { constants as
|
|
126865
|
+
import { constants as constants7, closeSync as closeSync19, fstatSync as fstatSync6, openSync as openSync19, statSync as statSync28, unlinkSync as unlinkSync13 } from "fs";
|
|
126645
126866
|
function bindFlock() {
|
|
126646
126867
|
const library = process.platform === "darwin" ? "libSystem.B.dylib" : process.platform === "linux" ? "libc.so.6" : null;
|
|
126647
126868
|
if (!library)
|
|
@@ -126694,7 +126915,7 @@ function tryAcquire(path) {
|
|
|
126694
126915
|
if (!lib)
|
|
126695
126916
|
throw new KernelLockUnavailable("flock is not available in this process");
|
|
126696
126917
|
for (let attempt = 0;attempt < 5; attempt++) {
|
|
126697
|
-
const fd = openSync19(path,
|
|
126918
|
+
const fd = openSync19(path, constants7.O_RDWR | constants7.O_CREAT | O_CLOEXEC, 384);
|
|
126698
126919
|
if (lib.flock(fd, LOCK_EX | LOCK_NB) !== 0) {
|
|
126699
126920
|
const errno = lib.errno();
|
|
126700
126921
|
closeSync19(fd);
|
|
@@ -126704,7 +126925,7 @@ function tryAcquire(path) {
|
|
|
126704
126925
|
}
|
|
126705
126926
|
let same = false;
|
|
126706
126927
|
try {
|
|
126707
|
-
same = fstatSync6(fd).ino ===
|
|
126928
|
+
same = fstatSync6(fd).ino === statSync28(path).ino;
|
|
126708
126929
|
} catch {
|
|
126709
126930
|
same = false;
|
|
126710
126931
|
}
|
|
@@ -127065,7 +127286,7 @@ var init_replay_registry = __esm(() => {
|
|
|
127065
127286
|
|
|
127066
127287
|
// src/mcp-session/replay-manager.ts
|
|
127067
127288
|
import { randomBytes as randomBytes19, randomUUID as randomUUID10 } from "crypto";
|
|
127068
|
-
import { constants as
|
|
127289
|
+
import { constants as constants8, accessSync as accessSync4, closeSync as closeSync20, existsSync as existsSync44, realpathSync as realpathSync11, statSync as statSync29 } from "fs";
|
|
127069
127290
|
import { dirname as dirname27, resolve as resolve11 } from "path";
|
|
127070
127291
|
function unavailable2(reason, message) {
|
|
127071
127292
|
return new ContractErrorException("replay_unavailable", message, reason);
|
|
@@ -127079,7 +127300,7 @@ function elsewhere(endpoint, replayId) {
|
|
|
127079
127300
|
function replayCwd(own) {
|
|
127080
127301
|
if (own) {
|
|
127081
127302
|
try {
|
|
127082
|
-
if (
|
|
127303
|
+
if (statSync29(own).isDirectory())
|
|
127083
127304
|
return realpathSync11(own);
|
|
127084
127305
|
} catch {}
|
|
127085
127306
|
}
|
|
@@ -127089,9 +127310,9 @@ async function replayClaudeBinary(env) {
|
|
|
127089
127310
|
const named = env.CLAUDE_PATH ? resolve11(env.CLAUDE_PATH) : "";
|
|
127090
127311
|
if (named) {
|
|
127091
127312
|
try {
|
|
127092
|
-
if (!
|
|
127313
|
+
if (!statSync29(named).isFile())
|
|
127093
127314
|
throw new Error("not a file");
|
|
127094
|
-
|
|
127315
|
+
accessSync4(named, constants8.X_OK);
|
|
127095
127316
|
} catch {
|
|
127096
127317
|
throw new Error(`CLAUDE_PATH ${named} is not an executable file`);
|
|
127097
127318
|
}
|
|
@@ -127107,7 +127328,7 @@ function callerOf(opener) {
|
|
|
127107
127328
|
}
|
|
127108
127329
|
function isRecordGone(path) {
|
|
127109
127330
|
try {
|
|
127110
|
-
|
|
127331
|
+
statSync29(path);
|
|
127111
127332
|
return false;
|
|
127112
127333
|
} catch (e) {
|
|
127113
127334
|
return e.code === "ENOENT";
|
|
@@ -132135,10 +132356,10 @@ var init_serve_command = __esm(() => {
|
|
|
132135
132356
|
});
|
|
132136
132357
|
|
|
132137
132358
|
// src/hooks/ambient-dts.generated.ts
|
|
132138
|
-
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';
|
|
132139
132360
|
|
|
132140
132361
|
// src/hooks/observer/corpus.ts
|
|
132141
|
-
import { appendFileSync as appendFileSync8, readFileSync as readFileSync55, readdirSync as readdirSync18, statSync as
|
|
132362
|
+
import { appendFileSync as appendFileSync8, readFileSync as readFileSync55, readdirSync as readdirSync18, statSync as statSync30 } from "fs";
|
|
132142
132363
|
import { homedir as homedir43 } from "os";
|
|
132143
132364
|
import { join as join72 } from "path";
|
|
132144
132365
|
function directoryOf2(filePath) {
|
|
@@ -132221,7 +132442,7 @@ function listTranscripts(root) {
|
|
|
132221
132442
|
for (const project of projects) {
|
|
132222
132443
|
const dir = join72(root, project);
|
|
132223
132444
|
try {
|
|
132224
|
-
if (!
|
|
132445
|
+
if (!statSync30(dir).isDirectory())
|
|
132225
132446
|
continue;
|
|
132226
132447
|
for (const f of readdirSync18(dir)) {
|
|
132227
132448
|
if (f.endsWith(".jsonl"))
|
|
@@ -134635,7 +134856,7 @@ var init_view_cli = __esm(() => {
|
|
|
134635
134856
|
|
|
134636
134857
|
// src/herdr/herdr-cli.ts
|
|
134637
134858
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
134638
|
-
import { copyFileSync as copyFileSync3, existsSync as existsSync49, mkdirSync as mkdirSync30, readdirSync as readdirSync19, renameSync as renameSync14, statSync as
|
|
134859
|
+
import { copyFileSync as copyFileSync3, existsSync as existsSync49, mkdirSync as mkdirSync30, readdirSync as readdirSync19, renameSync as renameSync14, statSync as statSync31 } from "fs";
|
|
134639
134860
|
import { homedir as homedir45 } from "os";
|
|
134640
134861
|
import { dirname as dirname29, join as join76, resolve as resolve14 } from "path";
|
|
134641
134862
|
function spawnHerdrApp(args) {
|
|
@@ -134701,11 +134922,11 @@ function isModFile(name) {
|
|
|
134701
134922
|
function installAppMod(source, appHome) {
|
|
134702
134923
|
if (!existsSync49(join76(source, "main.js")) || !existsSync49(join76(source, "mod.json")))
|
|
134703
134924
|
throw new Error(`${source} holds no built mod (main.js and mod.json); run \`bun run build\``);
|
|
134704
|
-
if (!existsSync49(appHome) || !
|
|
134925
|
+
if (!existsSync49(appHome) || !statSync31(appHome).isDirectory())
|
|
134705
134926
|
throw new Error(`${appHome} does not exist: start Herdr.app once so it creates its home, then run this again`);
|
|
134706
134927
|
const dest = join76(appHome, "mods", APP_MOD_NAME);
|
|
134707
134928
|
mkdirSync30(dest, { recursive: true });
|
|
134708
|
-
const files = readdirSync19(source).filter((f) => isModFile(f) &&
|
|
134929
|
+
const files = readdirSync19(source).filter((f) => isModFile(f) && statSync31(join76(source, f)).isFile());
|
|
134709
134930
|
files.sort((a, b) => a === "mod.json" ? -1 : b === "mod.json" ? 1 : a.localeCompare(b));
|
|
134710
134931
|
for (const f of files) {
|
|
134711
134932
|
const hidden = join76(dest, `.${f}.installing`);
|
|
@@ -137668,7 +137889,7 @@ var init_quota_command = __esm(() => {
|
|
|
137668
137889
|
});
|
|
137669
137890
|
|
|
137670
137891
|
// src/update-command.ts
|
|
137671
|
-
import { execSync
|
|
137892
|
+
import { execSync } from "child_process";
|
|
137672
137893
|
function refreshAnsi2() {
|
|
137673
137894
|
({ RESET, BOLD: BOLD2, GREEN, YELLOW, CYAN, RED: RED2, MAGENTA, DIM } = cliAnsi());
|
|
137674
137895
|
}
|
|
@@ -137699,7 +137920,7 @@ function getUpdateCommand(method) {
|
|
|
137699
137920
|
}
|
|
137700
137921
|
async function executeUpdate(command) {
|
|
137701
137922
|
try {
|
|
137702
|
-
|
|
137923
|
+
execSync(command, {
|
|
137703
137924
|
stdio: "inherit",
|
|
137704
137925
|
shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
|
|
137705
137926
|
});
|
|
@@ -137836,7 +138057,7 @@ ${BOLD2}Unable to detect installation method.${RESET}`);
|
|
|
137836
138057
|
}
|
|
137837
138058
|
function fetchLatestVersionViaNpm() {
|
|
137838
138059
|
try {
|
|
137839
|
-
const output =
|
|
138060
|
+
const output = execSync("npm view claudish version", {
|
|
137840
138061
|
encoding: "utf-8",
|
|
137841
138062
|
timeout: 20000,
|
|
137842
138063
|
stdio: ["ignore", "pipe", "ignore"]
|
|
@@ -146469,7 +146690,7 @@ var init_advisor_startup = __esm(() => {
|
|
|
146469
146690
|
});
|
|
146470
146691
|
|
|
146471
146692
|
// src/session/conversation.ts
|
|
146472
|
-
import { closeSync as closeSync21, openSync as openSync20, readSync as readSync10, statSync as
|
|
146693
|
+
import { closeSync as closeSync21, openSync as openSync20, readSync as readSync10, statSync as statSync32 } from "fs";
|
|
146473
146694
|
import { StringDecoder } from "string_decoder";
|
|
146474
146695
|
function looksLikeTurn(line) {
|
|
146475
146696
|
const assistant = line.includes('"type":"assistant"');
|
|
@@ -146524,7 +146745,7 @@ function readConversation(file, opts = {}) {
|
|
|
146524
146745
|
};
|
|
146525
146746
|
let fd = null;
|
|
146526
146747
|
try {
|
|
146527
|
-
const size =
|
|
146748
|
+
const size = statSync32(file).size;
|
|
146528
146749
|
fd = openSync20(file, "r");
|
|
146529
146750
|
const buf = Buffer.allocUnsafe(chunkBytes);
|
|
146530
146751
|
const decoder = new StringDecoder("utf-8");
|
|
@@ -148170,7 +148391,7 @@ import {
|
|
|
148170
148391
|
realpathSync as realpathSync12,
|
|
148171
148392
|
renameSync as renameSync15,
|
|
148172
148393
|
rmSync as rmSync22,
|
|
148173
|
-
statSync as
|
|
148394
|
+
statSync as statSync33,
|
|
148174
148395
|
unlinkSync as unlinkSync16,
|
|
148175
148396
|
writeSync as writeSync8
|
|
148176
148397
|
} from "fs";
|
|
@@ -148729,7 +148950,7 @@ var init_model_setting_restore = __esm(() => {
|
|
|
148729
148950
|
realRestoreFs = {
|
|
148730
148951
|
realpath: (path) => realpathSync12.native(path),
|
|
148731
148952
|
readFile: (path) => readFileSync59(path),
|
|
148732
|
-
stat: (path) => toFileStat(
|
|
148953
|
+
stat: (path) => toFileStat(statSync33(path)),
|
|
148733
148954
|
writeNew: (path, data, mode) => {
|
|
148734
148955
|
const fd = openSync21(path, "wx", mode);
|
|
148735
148956
|
try {
|