@alexwkleung/reika 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/README.zh-CN.md +15 -0
- package/dist/agent/compaction.js +82 -27
- package/dist/agent/loop.js +84 -20
- package/dist/agent/prefillcost.js +16 -0
- package/dist/agent/prompt.js +5 -2
- package/dist/cli.js +5 -11
- package/dist/context/bootstrap.js +1 -1
- package/dist/debug.js +15 -0
- package/dist/{headless.js → headless/headless.js} +185 -48
- package/dist/{headlessargs.js → headless/headlessargs.js} +12 -2
- package/dist/headless/headlessprompt.js +132 -0
- package/dist/mcp/client.js +97 -5
- package/dist/mcp/manager.js +15 -2
- package/dist/provider/client.js +13 -0
- package/dist/session.js +12 -1
- package/dist/{skills.js → skills/skills.js} +93 -13
- package/dist/store/sessions.js +40 -3
- package/dist/store/transcript.js +38 -1
- package/dist/tools/_carriers.js +119 -0
- package/dist/tools/_danger.js +305 -82
- package/dist/tools/_readonly.js +13 -12
- package/dist/tools/_sandbox.js +13 -5
- package/dist/ui/App.js +288 -83
- package/dist/ui/Approval.js +80 -33
- package/dist/ui/Confirm.js +1 -27
- package/dist/ui/DiffView.js +24 -14
- package/dist/ui/Question.js +152 -19
- package/dist/ui/ResumeSelect.js +13 -6
- package/dist/ui/Scrollback.js +44 -8
- package/dist/ui/Status.js +35 -10
- package/dist/ui/commands.js +1 -1
- package/dist/ui/dialogspecs.js +38 -0
- package/dist/ui/layout.js +149 -6
- package/dist/ui/markdown.js +6 -5
- package/dist/ui/pr.js +15 -9
- package/dist/ui/reactbuild.js +15 -0
- package/dist/ui/summary.js +3 -2
- package/dist/ui/termtext.js +5 -1
- package/dist/ui/theme.js +5 -0
- package/dist/ui/tui.js +9 -0
- package/package.json +1 -1
- /package/dist/{skillmatch.js → skills/skillmatch.js} +0 -0
package/README.md
CHANGED
|
@@ -143,6 +143,21 @@ The same pages are on the website, [reikacode.com](https://reikacode.com).
|
|
|
143
143
|
|
|
144
144
|
Claude Code, Codex, Crush, OpenCode, Pi, Aider, DeepSeek Harness, Qwen Code, Kimi Code CLI, Gemini CLI, Junie, DS4, and Ante.
|
|
145
145
|
|
|
146
|
+
## Citation
|
|
147
|
+
|
|
148
|
+
If you use Reika in your work, you can cite it as:
|
|
149
|
+
|
|
150
|
+
```bibtex
|
|
151
|
+
@software{reika2026,
|
|
152
|
+
author = {Leung, Alex},
|
|
153
|
+
title = {Reika},
|
|
154
|
+
year = {2026},
|
|
155
|
+
url = {https://github.com/alexwkleung/reika}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
GitHub's "Cite this repository" button gives the same entry in other formats, from [CITATION.cff](CITATION.cff).
|
|
160
|
+
|
|
146
161
|
## License
|
|
147
162
|
|
|
148
163
|
Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
package/README.zh-CN.md
CHANGED
|
@@ -142,6 +142,21 @@ cd your-project && reika
|
|
|
142
142
|
|
|
143
143
|
Claude Code、Codex、Crush、OpenCode、Pi、Aider、DeepSeek Harness、Qwen Code、Kimi Code CLI、Gemini CLI、Junie、DS4 和 Ante。
|
|
144
144
|
|
|
145
|
+
## 引用
|
|
146
|
+
|
|
147
|
+
如果你在工作中使用了 Reika,可以这样引用:
|
|
148
|
+
|
|
149
|
+
```bibtex
|
|
150
|
+
@software{reika2026,
|
|
151
|
+
author = {Leung, Alex},
|
|
152
|
+
title = {Reika},
|
|
153
|
+
year = {2026},
|
|
154
|
+
url = {https://github.com/alexwkleung/reika}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
GitHub 的 "Cite this repository" 按钮会根据 [CITATION.cff](CITATION.cff) 给出其他格式的同一条目。
|
|
159
|
+
|
|
145
160
|
## 许可
|
|
146
161
|
|
|
147
162
|
Apache License 2.0。见 [LICENSE](LICENSE) 和 [NOTICE](NOTICE)。
|
package/dist/agent/compaction.js
CHANGED
|
@@ -183,7 +183,7 @@ function ageLowFraction() {
|
|
|
183
183
|
// not tokens, deliberately — it is compared against `payload.length`, and the threshold's token
|
|
184
184
|
// units are a different scale.
|
|
185
185
|
const SMALL_PAYLOAD_CHARS = 2000;
|
|
186
|
-
export function batchAgePayloads(history, estimate, // calibrated request-token estimate;
|
|
186
|
+
export function batchAgePayloads(history, estimate, // calibrated request-token estimate; read at each probe of the stop point
|
|
187
187
|
contextWindow, minGen = DEFAULT_MIN_GEN_TOKENS,
|
|
188
188
|
// Whether marking reasoning can still move the estimate this sweep is chasing. False once the
|
|
189
189
|
// endpoint has demanded every reasoning byte back (latches.ts): serialization then keeps
|
|
@@ -239,50 +239,105 @@ shedReasoning = true) {
|
|
|
239
239
|
// the tail IS that message and this loop never reaches it. Promoting the tail into `content` is
|
|
240
240
|
// what makes it visible to the chat template; this is what keeps that promotion from becoming a
|
|
241
241
|
// standing window cost only a fold could clear.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
const marks = shedOrder(history, protect, specIdx, shedReasoning);
|
|
243
|
+
let applied = 0;
|
|
244
|
+
const applyTo = (k) => {
|
|
245
|
+
while (applied < k)
|
|
246
|
+
marks[applied++].apply();
|
|
247
|
+
while (applied > k)
|
|
248
|
+
marks[--applied].undo();
|
|
249
|
+
};
|
|
250
|
+
// #894: the marks fall in a fixed order and the estimate only decides where to stop, so the stop
|
|
251
|
+
// is searched for rather than walked to. Re-estimating at every index cost a full serialization
|
|
252
|
+
// per message — about 1,400 of them, ~5s with the UI frozen, when a resumed session shed whole.
|
|
253
|
+
// Search finds the first stop only while marking never grows the request, which holds unless a
|
|
254
|
+
// fit-to-window cap gives freed room back to another live payload.
|
|
255
|
+
applyTo(marks.length);
|
|
256
|
+
const floor = estimate();
|
|
257
|
+
if (floor > target) {
|
|
258
|
+
out.short = Math.max(0, Math.round(floor - target));
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
let lo = 0;
|
|
262
|
+
let hi = marks.length;
|
|
263
|
+
while (hi - lo > 1) {
|
|
264
|
+
const mid = (lo + hi) >>> 1;
|
|
265
|
+
applyTo(mid);
|
|
266
|
+
if (estimate() <= target)
|
|
267
|
+
hi = mid;
|
|
268
|
+
else
|
|
269
|
+
lo = mid;
|
|
246
270
|
}
|
|
271
|
+
applyTo(hi);
|
|
272
|
+
}
|
|
273
|
+
for (let i = 0; i < applied; i++) {
|
|
274
|
+
out.marked++;
|
|
275
|
+
if (marks[i].kind === 'bulk')
|
|
276
|
+
out.bulk++;
|
|
277
|
+
else if (marks[i].kind === 'crumb')
|
|
278
|
+
out.crumbs++;
|
|
279
|
+
}
|
|
280
|
+
out.kept = survivingCrumbs();
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
// The marks batchAgePayloads would make if it never reached its watermark, in the order it makes
|
|
284
|
+
// them: spent continuation tails, then reasoning and bulk payloads oldest-first, then crumbs.
|
|
285
|
+
function shedOrder(history, protect, specIdx, shedReasoning) {
|
|
286
|
+
const marks = [];
|
|
287
|
+
for (let i = 0; i < protect; i++) {
|
|
247
288
|
const m = history[i];
|
|
248
289
|
if (m.role === 'assistant' && m.continuationTail && m.content !== CONTINUATION_SHED_NOTE) {
|
|
249
|
-
|
|
250
|
-
|
|
290
|
+
const content = m.content;
|
|
291
|
+
marks.push({
|
|
292
|
+
kind: 'tail',
|
|
293
|
+
apply: () => (m.content = CONTINUATION_SHED_NOTE),
|
|
294
|
+
undo: () => (m.content = content),
|
|
295
|
+
});
|
|
251
296
|
}
|
|
252
297
|
}
|
|
253
298
|
for (const takeCrumbs of [false, true]) {
|
|
254
299
|
for (let i = 0; i < protect; i++) {
|
|
255
|
-
if (estimate() <= target) {
|
|
256
|
-
out.kept = survivingCrumbs();
|
|
257
|
-
return out;
|
|
258
|
-
}
|
|
259
300
|
if (i === specIdx)
|
|
260
301
|
continue;
|
|
261
302
|
const m = history[i];
|
|
262
|
-
if (m.role === 'assistant' && m.reasoning && !m.reasoningAged) {
|
|
303
|
+
if (!takeCrumbs && m.role === 'assistant' && m.reasoning && !m.reasoningAged) {
|
|
263
304
|
if (!shedReasoning)
|
|
264
305
|
continue;
|
|
265
|
-
|
|
266
|
-
|
|
306
|
+
const had = 'reasoningAged' in m;
|
|
307
|
+
const was = m.reasoningAged;
|
|
308
|
+
marks.push({
|
|
309
|
+
kind: 'reasoning',
|
|
310
|
+
apply: () => (m.reasoningAged = true),
|
|
311
|
+
undo: () => (had ? (m.reasoningAged = was) : delete m.reasoningAged),
|
|
312
|
+
});
|
|
267
313
|
}
|
|
268
314
|
else if (m.role === 'tool' && m.payload && !m.aged) {
|
|
269
|
-
|
|
315
|
+
const small = m.payload.length < SMALL_PAYLOAD_CHARS;
|
|
316
|
+
if (small !== takeCrumbs)
|
|
270
317
|
continue;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
318
|
+
const hadAged = 'aged' in m;
|
|
319
|
+
const wasAged = m.aged;
|
|
320
|
+
const hadRendered = 'rendered' in m;
|
|
321
|
+
const rendered = m.rendered;
|
|
322
|
+
marks.push({
|
|
323
|
+
kind: takeCrumbs ? 'crumb' : 'bulk',
|
|
324
|
+
apply: () => {
|
|
325
|
+
m.aged = true;
|
|
326
|
+
delete m.rendered;
|
|
327
|
+
},
|
|
328
|
+
undo: () => {
|
|
329
|
+
if (hadAged)
|
|
330
|
+
m.aged = wasAged;
|
|
331
|
+
else
|
|
332
|
+
delete m.aged;
|
|
333
|
+
if (hadRendered)
|
|
334
|
+
m.rendered = rendered;
|
|
335
|
+
},
|
|
336
|
+
});
|
|
278
337
|
}
|
|
279
338
|
}
|
|
280
339
|
}
|
|
281
|
-
|
|
282
|
-
// Ran out of candidates while still over: everything sheddable outside the protected tail is
|
|
283
|
-
// aged, and what remains is the active round plus whatever the floors hold.
|
|
284
|
-
out.short = Math.max(0, Math.round(estimate() - target));
|
|
285
|
-
return out;
|
|
340
|
+
return marks;
|
|
286
341
|
}
|
|
287
342
|
// Index of the assistant message that issued the trailing tool block's calls (or the final
|
|
288
343
|
// assistant message when the history ends without tool results) — everything from there on is the
|
package/dist/agent/loop.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute, relative } from 'node:path';
|
|
1
2
|
import { buildSystemPrompt } from './prompt.js';
|
|
2
3
|
import { callModel } from '../provider/client.js';
|
|
3
4
|
import { latchesFor } from '../provider/latches.js';
|
|
@@ -10,7 +11,7 @@ import { droppedPayloadCount, findFreshToolBlockStart, hasDroppedPayloads, lastU
|
|
|
10
11
|
import { ReadTrace } from './readtrace.js';
|
|
11
12
|
import { traceBashRead, traceReadPath } from './bashread.js';
|
|
12
13
|
import { PrefixTrace } from './prefixtrace.js';
|
|
13
|
-
import { PrefillRate, formatPrefillCost, reprocessedTokens, sampleTokens } from './prefillcost.js';
|
|
14
|
+
import { PrefillRate, formatMeasuredPrefill, formatPrefillCost, reprocessedTokens, sampleTokens, } from './prefillcost.js';
|
|
14
15
|
import { DecodeRate, decodeSample, formatRate } from './decoderate.js';
|
|
15
16
|
import { GenReserve, resolveGenReserve, withGenReserve } from './genreserve.js';
|
|
16
17
|
import { selfRepeatRatio, repeatedSelfShingles, ReasoningTrace, liveSpinSignal, verbatimAbortThreshold, } from './reasoningtrace.js';
|
|
@@ -378,6 +379,13 @@ const DROPPED_LEDGER = process.env.REIKA_DROPPED_LEDGER !== '0';
|
|
|
378
379
|
// runs as-is), suspended while inspection tools are withdrawn (the directed read would be refused).
|
|
379
380
|
// The `would-land=` field on the bounce debug line is the measurement. See agent/readfirst.ts.
|
|
380
381
|
const READ_FIRST = process.env.REIKA_READ_FIRST !== '0';
|
|
382
|
+
// EXPERIMENT (#867): keep the offered tool list unchanged while inspection is withdrawn, enforcing
|
|
383
|
+
// the pause at dispatch and through the ledger only. The template renders the tools ahead of the
|
|
384
|
+
// system prompt, so dropping them makes the withdrawal round and the lift round each a full
|
|
385
|
+
// re-prefill (`cause=tools-changed`). On by default since 2026-10-29 (`=0` is the baseline arm): on
|
|
386
|
+
// T2 with lfm2.5 it cut engine prefill per round by a third and refused calls per pause went down,
|
|
387
|
+
// not up — a model that still sees read/grep did not keep reaching for them.
|
|
388
|
+
const WITHDRAW_KEEP_TOOLS = process.env.REIKA_WITHDRAW_KEEP_TOOLS !== '0';
|
|
381
389
|
// EXPERIMENT (plan mode): the force-write turn is a *transformation*, not another exploration
|
|
382
390
|
// round. Asking the exploring model to "stop and write prose" fights its action prior and lets
|
|
383
391
|
// the plan it already has decay across turns; but the plan is reliably in its reasoning. So at
|
|
@@ -966,6 +974,22 @@ export function buildEditRecoveryLedger(failure) {
|
|
|
966
974
|
'here after all, say so and stop instead of retrying.',
|
|
967
975
|
].join('\n');
|
|
968
976
|
}
|
|
977
|
+
// The edit-recovery dead-end's report. A `diverged` failure names the line that differs: the
|
|
978
|
+
// target is there, so "the plan may reference code that doesn't exist" would send the user hunting
|
|
979
|
+
// for a problem the file does not have.
|
|
980
|
+
export function buildEditRecoveryStopMessage(failure) {
|
|
981
|
+
const file = failure ? `\`${failure.path}\`` : 'the file';
|
|
982
|
+
if (failure?.kind === 'diverged') {
|
|
983
|
+
return (`My edit to ${file} didn't apply: line ${failure.divergentLine} differs from the text I ` +
|
|
984
|
+
`expected (expected \`${failure.expected}\`, the file has \`${failure.actual}\`). I've ` +
|
|
985
|
+
`stopped instead of looping. Ask me to continue and I'll re-read that part of the file and ` +
|
|
986
|
+
`retry the edit from its current text.`);
|
|
987
|
+
}
|
|
988
|
+
return (`I kept trying to edit ${file} but the text I expected isn't in the file, so the change can't ` +
|
|
989
|
+
`be applied as planned — the plan may reference code that doesn't exist there. I've stopped ` +
|
|
990
|
+
`instead of looping. Please confirm the change belongs in that file, or point me at the right ` +
|
|
991
|
+
`location.`);
|
|
992
|
+
}
|
|
969
993
|
// Payload attached to an `absent` edit failure when the file's bytes are not in the model's context
|
|
970
994
|
// (see the call site). Rides the tool result rather than the system suffix: unlike the diverged
|
|
971
995
|
// recovery ledger — which must survive several rounds to reach a period-2 loop — this is consumed by
|
|
@@ -1177,6 +1201,8 @@ export async function runTurn(opts) {
|
|
|
1177
1201
|
// line off) gets exactly ONE round with the divergence lifted into the system suffix before the
|
|
1178
1202
|
// dead-end stop — the same "each tier gets one round" discipline as the rumination ladder. Set when
|
|
1179
1203
|
// that round fires so a still-looping turn falls through to the stop instead of grounding forever.
|
|
1204
|
+
// Per failure, not per turn: a landed edit clears it, so a later failure on other code gets its own
|
|
1205
|
+
// round (a turn-wide guard stopped a second, unrelated failure on its first attempt).
|
|
1180
1206
|
let editRecoveryGroundingTried = false;
|
|
1181
1207
|
// One-shot guard for the Tier 2 logit-recovery round (REIKA_LOGIT_RECOVERY): the rumination
|
|
1182
1208
|
// dead-end gets exactly ONE biased round before the terminal stop. Set when it fires so a
|
|
@@ -1288,6 +1314,24 @@ export async function runTurn(opts) {
|
|
|
1288
1314
|
latches: latchesFor(opts.config),
|
|
1289
1315
|
trailingNote: roundSuffix,
|
|
1290
1316
|
});
|
|
1317
|
+
// A stream cut short never reaches its final usage chunk, but a hosted API has still billed it
|
|
1318
|
+
// (#906), so a cut round is counted from what streamed. A cut before any output counts nothing:
|
|
1319
|
+
// no decode happened. Goes to onUsage only, never onto the response: calibration, the decode rate
|
|
1320
|
+
// and the reserve read `response.usage`, and a learned value must not be fitted to our own guess.
|
|
1321
|
+
const reportUsage = (response, cut, promptEstimate) => {
|
|
1322
|
+
if (response.usage) {
|
|
1323
|
+
opts.onUsage?.(response.usage);
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const output = (response.reasoning ?? '') + (response.content ?? '');
|
|
1327
|
+
if (!cut || !output)
|
|
1328
|
+
return;
|
|
1329
|
+
opts.onUsage?.({
|
|
1330
|
+
promptTokens: Math.round(promptEstimate() * calibration),
|
|
1331
|
+
completionTokens: Math.round(estimateTokens(output) * Math.max(calibration, COMPACTION_CALIBRATION_FLOOR)),
|
|
1332
|
+
estimated: true,
|
|
1333
|
+
});
|
|
1334
|
+
};
|
|
1291
1335
|
// Run a typecheck while pulsing the UI indicator around it (and clearing on any exit). The
|
|
1292
1336
|
// pulse is human-only; the CheckOutcome flows to the gate logic, never to the model.
|
|
1293
1337
|
const typecheck = async () => {
|
|
@@ -1607,11 +1651,7 @@ export async function runTurn(opts) {
|
|
|
1607
1651
|
debugLog(`[reika:debug] round=${i} edit-recovery-stuck file=${file ?? '?'}\n`);
|
|
1608
1652
|
const stuck = {
|
|
1609
1653
|
role: 'assistant',
|
|
1610
|
-
content:
|
|
1611
|
-
`isn't in the file, so the change can't be applied as planned — the plan may reference ` +
|
|
1612
|
-
`code that doesn't exist there. I've stopped instead of looping. Please confirm the ` +
|
|
1613
|
-
`change belongs in that file, or point me at the right location.` +
|
|
1614
|
-
(await reportTypecheckAtStop()),
|
|
1654
|
+
content: buildEditRecoveryStopMessage(lastEditFailure) + (await reportTypecheckAtStop()),
|
|
1615
1655
|
durationMs: Date.now() - turnStart,
|
|
1616
1656
|
...(fetchedUrls.size > 0 ? { sources: [...fetchedUrls] } : {}),
|
|
1617
1657
|
};
|
|
@@ -1740,14 +1780,14 @@ export async function runTurn(opts) {
|
|
|
1740
1780
|
}
|
|
1741
1781
|
}
|
|
1742
1782
|
// Empty tool lists are already a supported path (chat mode with no search provider). On a loop
|
|
1743
|
-
// break
|
|
1744
|
-
//
|
|
1783
|
+
// break the dispatch layer refuses inspection calls; with REIKA_WITHDRAW_KEEP_TOOLS=0 the
|
|
1784
|
+
// inspection tools are also dropped from the offered set (the pre-#867 behaviour).
|
|
1745
1785
|
// The subagent's report round keeps the list and forbids calls with `tool_choice` instead
|
|
1746
1786
|
// (#426): the template renders the tool list into the system turn, so withholding it would
|
|
1747
1787
|
// re-prefill the subagent's whole context on its last round.
|
|
1748
1788
|
const callTools = planForceWrite
|
|
1749
1789
|
? []
|
|
1750
|
-
: withdrawInspection
|
|
1790
|
+
: withdrawInspection && !WITHDRAW_KEEP_TOOLS
|
|
1751
1791
|
? opts.tools.filter(t => !INSPECTION_TOOLS.has(t.name))
|
|
1752
1792
|
: opts.tools;
|
|
1753
1793
|
const planTransformBudget = window ? planTransformBudgetChars(window) : Number.MAX_SAFE_INTEGER;
|
|
@@ -1853,6 +1893,17 @@ export async function runTurn(opts) {
|
|
|
1853
1893
|
// REIKA_COMPACTION_REPORT=0 is the ledger-only baseline arm; /compact honors it too, and then
|
|
1854
1894
|
// folds without a note exactly as an automatic fold would.
|
|
1855
1895
|
const reportEnabled = compactionReportEnabled();
|
|
1896
|
+
// The note is written from the unfolded history, which a resumed session (folds are not
|
|
1897
|
+
// restored) or a /model switch to a smaller window can leave over the window: the engine
|
|
1898
|
+
// refuses the request and its retries, or one that truncates spends a whole window of prefill
|
|
1899
|
+
// on the backstop's 256 tokens. Last in the gate, so only a fold that is really due logs it.
|
|
1900
|
+
const noteFitsWindow = (contextWindow) => {
|
|
1901
|
+
const promptTokens = Math.round(rawEstimate() * compactCalibration);
|
|
1902
|
+
if (promptTokens < contextWindow)
|
|
1903
|
+
return true;
|
|
1904
|
+
debugLog(`[reika:debug] round=${i} compaction-report skipped prompt=${promptTokens} window=${contextWindow}\n`);
|
|
1905
|
+
return false;
|
|
1906
|
+
};
|
|
1856
1907
|
const autoReport = !manualRound &&
|
|
1857
1908
|
reportEnabled &&
|
|
1858
1909
|
!!window &&
|
|
@@ -1869,7 +1920,8 @@ export async function runTurn(opts) {
|
|
|
1869
1920
|
? foldAfterShed(opts.history, h => rawEstimate(h) * compactCalibration, window, compactCalibration, minGen(), !latchesFor(opts.config).reasoningRoundtrip,
|
|
1870
1921
|
// The manual trigger's only question is "would the fold remove anything" (#481).
|
|
1871
1922
|
!manualRound)
|
|
1872
|
-
: wouldFold(opts.history, window, compactCalibration, minGen()))
|
|
1923
|
+
: wouldFold(opts.history, window, compactCalibration, minGen())) &&
|
|
1924
|
+
noteFitsWindow(window)) {
|
|
1873
1925
|
const n = shrink.folds + 1;
|
|
1874
1926
|
const directive = buildCompactionReportDirective(n);
|
|
1875
1927
|
// Notice first, so the barred note block that follows reads as a deliberate side
|
|
@@ -1991,9 +2043,9 @@ export async function runTurn(opts) {
|
|
|
1991
2043
|
return plain;
|
|
1992
2044
|
}
|
|
1993
2045
|
};
|
|
2046
|
+
const notePrompt = () => rawEstimate(opts.history, noteTools);
|
|
1994
2047
|
const rep = await report(directive);
|
|
1995
|
-
|
|
1996
|
-
opts.onUsage?.(rep.usage);
|
|
2048
|
+
reportUsage(rep, !!opts.signal?.aborted, notePrompt);
|
|
1997
2049
|
// callModel returns what streamed before a ctrl-c rather than throwing, so an aborted note
|
|
1998
2050
|
// is a cut-off fragment — never a note, and not a reason to fold.
|
|
1999
2051
|
if (opts.signal?.aborted) {
|
|
@@ -2010,8 +2062,7 @@ export async function runTurn(opts) {
|
|
|
2010
2062
|
debugLog(`[reika:debug] round=${i} compaction-report n=${n} no-note ${describe(rep)}; retrying\n`);
|
|
2011
2063
|
opts.onReasoningReset?.();
|
|
2012
2064
|
retry = await report(`${directive}\n\n${COMPACTION_REPORT_RETRY}`, refusedCallTurn(rep));
|
|
2013
|
-
|
|
2014
|
-
opts.onUsage?.(retry.usage);
|
|
2065
|
+
reportUsage(retry, !!opts.signal?.aborted, notePrompt);
|
|
2015
2066
|
if (opts.signal?.aborted) {
|
|
2016
2067
|
commitNoteRoundAbort();
|
|
2017
2068
|
return;
|
|
@@ -2043,10 +2094,11 @@ export async function runTurn(opts) {
|
|
|
2043
2094
|
debugLog(`[reika:debug] round=${i} compaction-report failed err=${String(err)}\n`);
|
|
2044
2095
|
}
|
|
2045
2096
|
finally {
|
|
2046
|
-
opts.onCompactionNote?.(false);
|
|
2047
2097
|
// The live region held the note; if the reply was empty no assistant commit cleared it,
|
|
2048
|
-
// so the UI is told explicitly before the round's real reply streams.
|
|
2098
|
+
// so the UI is told explicitly before the round's real reply streams. Ahead of the note
|
|
2099
|
+
// flag, so the UI still knows the stream it is ending was a note's.
|
|
2049
2100
|
opts.onReasoningReset?.();
|
|
2101
|
+
opts.onCompactionNote?.(false);
|
|
2050
2102
|
}
|
|
2051
2103
|
}
|
|
2052
2104
|
// Prefix-stable shrink event: payloads stay live (byte-frozen) across rounds, so shed them in
|
|
@@ -2312,8 +2364,7 @@ export async function runTurn(opts) {
|
|
|
2312
2364
|
opts.onReasoningStatus?.(false);
|
|
2313
2365
|
debugLog(`[reika:debug] reasoning-spin off round=${i} (block ended while flagged)\n`);
|
|
2314
2366
|
}
|
|
2315
|
-
|
|
2316
|
-
opts.onUsage?.(response.usage);
|
|
2367
|
+
reportUsage(response, callAbort.signal.aborted, () => sentEstimate);
|
|
2317
2368
|
// Recalibrate from what the provider actually counted vs. what we estimated for the
|
|
2318
2369
|
// request we just sent. Clamped to a sane band to ignore one-off outliers.
|
|
2319
2370
|
if (response.usage?.promptTokens && sentEstimate > 0) {
|
|
@@ -2381,6 +2432,7 @@ export async function runTurn(opts) {
|
|
|
2381
2432
|
`completion=${completion} finishReason=${response.finishReason ?? '?'} ` +
|
|
2382
2433
|
`decode=${formatRate(sample?.rate)} smoothed=${formatRate(decodeThroughput.get())} ` +
|
|
2383
2434
|
`src=${sample?.source ?? '?'} reserve=${reserve.tokens} reserveSrc=${reserve.source} ` +
|
|
2435
|
+
`${formatMeasuredPrefill(response.usage, response.enginePrompt, roundReprocessTokens)} ` +
|
|
2384
2436
|
// Process uptime, not turn time: on a fanless machine the rates sag with sustained load
|
|
2385
2437
|
// and recover across idle gaps, so separating that from context growth needs wall clock.
|
|
2386
2438
|
`t=${process.uptime().toFixed(0)}s\n`);
|
|
@@ -3246,6 +3298,7 @@ export async function runTurn(opts) {
|
|
|
3246
3298
|
if (summary.startsWith('Edited ') || summary.startsWith('Wrote ')) {
|
|
3247
3299
|
lastEditFailed = false;
|
|
3248
3300
|
lastEditFailure = undefined;
|
|
3301
|
+
editRecoveryGroundingTried = false;
|
|
3249
3302
|
// Read-first (#72): a successful edit/write grounds its path, but by different routes. An
|
|
3250
3303
|
// edit grounds only through the post-edit echo it hands back (tools/edit.ts refreshedFile),
|
|
3251
3304
|
// which is size-capped and absent on a large file — so it keys on the message index and
|
|
@@ -3427,6 +3480,17 @@ function commitAborted(opts, partial, partialReasoning, turnStart, fetchedUrls)
|
|
|
3427
3480
|
opts.history.push(m);
|
|
3428
3481
|
opts.onMessage(m);
|
|
3429
3482
|
}
|
|
3483
|
+
// The files a stop message names, as inline code and project-relative: an edit's `path` arg is
|
|
3484
|
+
// often absolute, and a bare `/Users/…/src/a.ts, …` list read as prose and wrapped mid-path.
|
|
3485
|
+
function stopFileList(files, cwd, max) {
|
|
3486
|
+
return [...files]
|
|
3487
|
+
.slice(0, max)
|
|
3488
|
+
.map(f => {
|
|
3489
|
+
const rel = isAbsolute(f) ? relative(cwd, f) : f;
|
|
3490
|
+
return `\`${rel && !rel.startsWith('..') && !isAbsolute(rel) ? rel : f}\``;
|
|
3491
|
+
})
|
|
3492
|
+
.join(', ');
|
|
3493
|
+
}
|
|
3430
3494
|
// Honest terminal stop when reasoning keeps spiraling even through recovery (the force-write looped,
|
|
3431
3495
|
// or the recovery budget is spent). Better than committing spiral garbage as a "plan" or running to
|
|
3432
3496
|
// the token wall. Names the files examined so the user has a handle on what was done. Deliberately
|
|
@@ -3446,7 +3510,7 @@ reason = 'loop') {
|
|
|
3446
3510
|
files.add(tc.args.path);
|
|
3447
3511
|
}
|
|
3448
3512
|
}
|
|
3449
|
-
const examined = files.size > 0 ? ` Files I examined: ${
|
|
3513
|
+
const examined = files.size > 0 ? ` Files I examined: ${stopFileList(files, opts.bundle.cwd, 12)}.` : '';
|
|
3450
3514
|
const m = {
|
|
3451
3515
|
role: 'assistant',
|
|
3452
3516
|
content: reason === 'length'
|
|
@@ -3486,7 +3550,7 @@ function commitAgentLoopStop(opts, turnStart, fetchedUrls, edited, typecheckAdde
|
|
|
3486
3550
|
}
|
|
3487
3551
|
}
|
|
3488
3552
|
}
|
|
3489
|
-
const fileList = files.size > 0 ? ` to ${
|
|
3553
|
+
const fileList = files.size > 0 ? ` to ${stopFileList(files, opts.bundle.cwd, 8)}` : '';
|
|
3490
3554
|
const content = edited
|
|
3491
3555
|
? `I made changes${fileList} but then kept repeating the same checks without making progress, so ` +
|
|
3492
3556
|
`I've stopped to avoid looping. The edits are saved — review them and ask me to continue if ` +
|
|
@@ -77,3 +77,19 @@ export function formatPrefillCost(tokens, rate, bounded = false) {
|
|
|
77
77
|
function formatSeconds(s) {
|
|
78
78
|
return s >= 10 ? `${Math.round(s)}s` : `${s.toFixed(1)}s`;
|
|
79
79
|
}
|
|
80
|
+
// The `round=` line's measured half (#868): what the provider and the engine reported about this
|
|
81
|
+
// request's prefill, beside the estimate the `prefix-cache` line printed before the call. `cached=?`
|
|
82
|
+
// rather than `0` when the provider reports no cache accounting — zero would claim a cold cache. The
|
|
83
|
+
// engine fields appear only when llama.cpp sent them, and `prompt_n` carries the estimate it should
|
|
84
|
+
// be read against (`reprocessEst=`), since that line was written before the count existed.
|
|
85
|
+
export function formatMeasuredPrefill(usage, engine, reprocessEstimate) {
|
|
86
|
+
const parts = [`cached=${usage?.cachedTokens ?? '?'}`];
|
|
87
|
+
if (engine?.promptN != null) {
|
|
88
|
+
parts.push(`prompt_n=${engine.promptN}`, `reprocessEst=${reprocessEstimate}`);
|
|
89
|
+
}
|
|
90
|
+
if (engine?.promptMs != null)
|
|
91
|
+
parts.push(`prompt_ms=${Math.round(engine.promptMs)}`);
|
|
92
|
+
if (engine?.cacheN != null)
|
|
93
|
+
parts.push(`cache_n=${engine.cacheN}`);
|
|
94
|
+
return parts.join(' ');
|
|
95
|
+
}
|
package/dist/agent/prompt.js
CHANGED
|
@@ -325,7 +325,9 @@ function buildAgentPrompt(opts) {
|
|
|
325
325
|
// "only if asked" because on a small model a named path is an attractor for unrelated exploration.
|
|
326
326
|
// Deliberately omitted: `~/.config/reika/.env` (API keys — naming it invites a `cat` that lands
|
|
327
327
|
// them in context and the saved transcript), the chrome profile, and the binary (`reika -p` from
|
|
328
|
-
// bash is a nested agent outside the subagent cap).
|
|
328
|
+
// bash is a nested agent outside the subagent cap). Both history paths are spelled out in full: named
|
|
329
|
+
// as `history/` alone, a model listed the root's /save files and never found projects/, where most
|
|
330
|
+
// sessions are.
|
|
329
331
|
// `REIKA_SELF_AWARE=0` is the baseline arm: the prompt without the line, byte-for-byte.
|
|
330
332
|
function selfLineParts() {
|
|
331
333
|
return process.env.REIKA_SELF_AWARE === '0' ? [] : [reikaSelfLine()];
|
|
@@ -334,7 +336,8 @@ export function reikaSelfLine(docsDir = DOCS_DIR) {
|
|
|
334
336
|
const where = [
|
|
335
337
|
...(docsDir ? [`its reference docs are in ${docsDir}`] : []),
|
|
336
338
|
'user skills in ~/.config/reika/skills/ (project skills in .reika/skills/)',
|
|
337
|
-
'saved sessions in ~/.config/reika/history/',
|
|
339
|
+
'auto-saved sessions in ~/.config/reika/history/projects/ (one subdirectory per project)',
|
|
340
|
+
'/save transcripts in ~/.config/reika/history/',
|
|
338
341
|
];
|
|
339
342
|
return `You are running inside reika ${VERSION}. Only if the user asks about reika itself: ${where.join(', ')}.`;
|
|
340
343
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
2
|
import { sweepDebugLogs } from './debug.js';
|
|
4
3
|
import { sweepStaleSpills } from './tools/_spill.js';
|
|
5
|
-
import { USAGE, parseHeadlessArgs } from './headlessargs.js';
|
|
4
|
+
import { USAGE, parseHeadlessArgs } from './headless/headlessargs.js';
|
|
5
|
+
import { loadWithProductionReact } from './ui/reactbuild.js';
|
|
6
6
|
import { VERSION } from './version.js';
|
|
7
7
|
// Lowercase like the command: ps/top/Activity Monitor otherwise list every session as `node`, and
|
|
8
8
|
// pgrep/pkill match case-sensitively.
|
|
@@ -36,7 +36,7 @@ if (headless?.help) {
|
|
|
36
36
|
process.exit(0);
|
|
37
37
|
}
|
|
38
38
|
if (headless) {
|
|
39
|
-
const { runHeadless } = await import('./headless.js');
|
|
39
|
+
const { runHeadless } = await import('./headless/headless.js');
|
|
40
40
|
const code = await runHeadless(headless, {
|
|
41
41
|
stdout: text => process.stdout.write(text),
|
|
42
42
|
stderr: text => process.stderr.write(text),
|
|
@@ -59,12 +59,6 @@ if (headless) {
|
|
|
59
59
|
process.exit(code);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
import('./ui/App.js'),
|
|
65
|
-
import('./ui/syncframe.js'),
|
|
66
|
-
]);
|
|
67
|
-
// Frames go out as one synchronized write each (#345) so a swapped-out process can't leave the
|
|
68
|
-
// terminal painting a half-erased screen between Ink's writes.
|
|
69
|
-
render(_jsx(App, {}), { exitOnCtrlC: false, stdout: createSyncedStdout(process.stdout) });
|
|
62
|
+
const { startTui } = await loadWithProductionReact(() => import('./ui/tui.js'));
|
|
63
|
+
startTui();
|
|
70
64
|
}
|
|
@@ -7,7 +7,7 @@ import { formatBundleSize } from './bundlesize.js';
|
|
|
7
7
|
import { DEFAULT_BUDGET, packRepoMap, rankRepoMap } from './repomap.js';
|
|
8
8
|
import { buildFileIndex } from './files.js';
|
|
9
9
|
import { loadGitignore } from './gitignore.js';
|
|
10
|
-
import { loadSkills } from '../skills.js';
|
|
10
|
+
import { loadSkills } from '../skills/skills.js';
|
|
11
11
|
export async function bootstrap(cwd, repoMapBudget = DEFAULT_BUDGET) {
|
|
12
12
|
const ig = await loadGitignore(cwd);
|
|
13
13
|
const [projectSummary, instructions, repoMapRanked, fileIndex, skills] = await Promise.all([
|
package/dist/debug.js
CHANGED
|
@@ -180,3 +180,18 @@ export function formatExperimentFlags() {
|
|
|
180
180
|
});
|
|
181
181
|
return `[reika:debug] flags version=${VERSION} ${flags.join(' ') || '(none set)'}`;
|
|
182
182
|
}
|
|
183
|
+
// Which model and server a log's rounds ran against (#868): once per session and on every switch,
|
|
184
|
+
// so saved logs can be split by model. The host only — a base URL's path, query and userinfo stay
|
|
185
|
+
// out, as the flags line keeps values out. A model id that is a filesystem path (llama.cpp names a
|
|
186
|
+
// model by the file it loaded) is cut to its basename, so a home path cannot land in the log.
|
|
187
|
+
export function formatEndpointLine(profile, model, baseURL) {
|
|
188
|
+
let host = '?';
|
|
189
|
+
try {
|
|
190
|
+
host = new URL(baseURL).hostname || '?';
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// An unparseable base URL is logged as unknown rather than verbatim.
|
|
194
|
+
}
|
|
195
|
+
const id = /^([/~\\]|[A-Za-z]:[/\\])/.test(model) ? (model.split(/[/\\]/).pop() ?? '?') : model;
|
|
196
|
+
return `[reika:debug] endpoint profile=${profile} model=${id || '?'} host=${host}`;
|
|
197
|
+
}
|