minicode-ai 0.26.0 → 0.28.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/cli/args.ts +120 -16
- package/cli/commands/acp.ts +38 -28
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +11 -12
- package/cli/commands/exec.ts +35 -73
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +96 -46
- package/cli/context-command-run.ts +171 -0
- package/cli/context-command.ts +87 -0
- package/cli/index.ts +96 -98
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +246 -123
- package/cli/tui.ts +311 -109
- package/docs/TERMINAL_CONTRACT.md +254 -69
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/config.md +16 -0
- package/docs/environment.md +3 -3
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +3 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +119 -66
- package/src/app/tool-layer.ts +12 -17
- package/src/config.ts +64 -104
- package/src/constants.ts +23 -9
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +109 -0
- package/src/policy/context.ts +78 -37
- package/src/policy/executor.ts +17 -7
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/guards.ts +41 -2
- package/src/providers/provision.ts +6 -60
- package/src/providers/responses.ts +1 -0
- package/src/repo/repomap.ts +180 -23
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +25 -58
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +20 -37
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +59 -23
- package/src/ui/i18n/id.ts +88 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +88 -62
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +154 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +28 -19
package/src/app/session.ts
CHANGED
|
@@ -51,26 +51,47 @@ import { DEFAULT_SESSION_MAX_STEPS, nextStepLimit } from "../policy/step-escalat
|
|
|
51
51
|
import { getCachedTokenizer, loadTokenizer } from "../policy/tokenizer-registry.ts"
|
|
52
52
|
import { contractForTool } from "../policy/tool-contract.ts"
|
|
53
53
|
import { maxTurnsExceededError } from "../policy/usage.ts"
|
|
54
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
createWorkModePermissionHandler,
|
|
56
|
+
normalizeWorkMode,
|
|
57
|
+
type WorkMode,
|
|
58
|
+
} from "../policy/work-mode.ts"
|
|
55
59
|
import type { ApprovalEventHook } from "../presentation/events.ts"
|
|
56
60
|
|
|
57
|
-
// Kebijakan kompaksi lebih agresif: ringkas lebih DINI
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
// Kebijakan kompaksi lebih agresif: ringkas lebih DINI daripada default kernel
|
|
62
|
+
// (75%/90%), supaya konteks jarang menyentuh dinding. Untuk jendela model
|
|
63
|
+
// nyata (>= 16k), selaraskan ambang medium/high dengan `contextBudgetFor` agar
|
|
64
|
+
// kompaksi berjalan SEBELUM `limit - outputReserve` (mis. 60% pada 32k tanpa
|
|
65
|
+
// maxOutputTokens) memicu overflow guard di dynamicProvider; jendela sintetis
|
|
66
|
+
// kecil (< 16k di test) mempertahankan rasio 65%/85%.
|
|
67
|
+
export function createAggressiveBudgetPolicy(
|
|
68
|
+
getMaxOutputTokens?: () => number | undefined,
|
|
69
|
+
): BudgetPolicy {
|
|
70
|
+
return {
|
|
71
|
+
evaluate({ usedTokens, limitTokens }) {
|
|
72
|
+
const limit = Math.max(1, limitTokens)
|
|
73
|
+
if (usedTokens >= limit) return "critical"
|
|
74
|
+
if (limit >= 16_000) {
|
|
75
|
+
const b = contextBudgetFor(limit, getMaxOutputTokens?.())
|
|
76
|
+
const highAt = Math.min(Math.floor(limit * 0.85), b.blockingLimit)
|
|
77
|
+
const mediumAt = Math.min(Math.floor(limit * 0.65), b.compactTrigger)
|
|
78
|
+
if (usedTokens >= highAt) return "high"
|
|
79
|
+
if (usedTokens >= mediumAt) return "medium"
|
|
80
|
+
return "low"
|
|
81
|
+
}
|
|
82
|
+
const ratio = usedTokens / limit
|
|
83
|
+
if (ratio >= 0.85) return "high"
|
|
84
|
+
if (ratio >= 0.65) return "medium"
|
|
85
|
+
return "low"
|
|
86
|
+
},
|
|
87
|
+
shouldCompact(pressure) {
|
|
88
|
+
return pressure !== "low"
|
|
89
|
+
},
|
|
90
|
+
}
|
|
72
91
|
}
|
|
73
92
|
|
|
93
|
+
export const aggressiveBudgetPolicy: BudgetPolicy = createAggressiveBudgetPolicy()
|
|
94
|
+
|
|
74
95
|
// P2 cap wrapper: limit retryAfter to 30s without mutating original error.
|
|
75
96
|
//
|
|
76
97
|
// [T-009 OBSERVATION.md] Anggaran pemulihan TIDAK lagi dinyatakan sebagai "berapa
|
|
@@ -239,19 +260,12 @@ export type WorkModeControl = {
|
|
|
239
260
|
export function workModeHint(workMode: WorkMode): string {
|
|
240
261
|
if (workMode === "DISCUSS") {
|
|
241
262
|
return (
|
|
242
|
-
"\n\nDISCUSS MODE: You are in read-only investigation and
|
|
263
|
+
"\n\nDISCUSS MODE: You are in read-only investigation, discussion, and planning mode. " +
|
|
243
264
|
"Do NOT modify files, run bash, or use write/edit tools. " +
|
|
244
|
-
"Read, search, and reason — investigate the question,
|
|
265
|
+
"Read, search, and reason — investigate the question thoroughly, discuss findings, options, and trade-offs with the user, and produce a concrete implementation plan. " +
|
|
245
266
|
"Do not implement or execute any change."
|
|
246
267
|
)
|
|
247
268
|
}
|
|
248
|
-
if (workMode === "PLAN") {
|
|
249
|
-
return (
|
|
250
|
-
"\n\nPLAN MODE: You are in planning mode. " +
|
|
251
|
-
"Do NOT modify files, run bash, or use write/edit tools. " +
|
|
252
|
-
"Only read, search, and reason — investigate thoroughly, then produce a concrete implementation plan."
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
269
|
return ""
|
|
256
270
|
}
|
|
257
271
|
|
|
@@ -283,6 +297,8 @@ export async function createMinicodeSession(
|
|
|
283
297
|
* EXECUTE memasang ceiling tipis di atas handler PM (lihat work-mode.ts);
|
|
284
298
|
* belum ada permukaan CLI/TUI — wiring itu slice integrasi berikutnya. */
|
|
285
299
|
workMode?: WorkMode
|
|
300
|
+
/** Izinkan callback `ask` non-TTY (mis. broker persetujuan daemon) untuk tool gated. */
|
|
301
|
+
allowNonTtyAsk?: boolean
|
|
286
302
|
/** Teruskan flag --allow-local-config ke permission handler (allowlist
|
|
287
303
|
* lokal). Default deny — lihat loadAllowlist. */
|
|
288
304
|
allowLocalConfig?: boolean
|
|
@@ -304,6 +320,10 @@ export async function createMinicodeSession(
|
|
|
304
320
|
noProgress?: NoProgressOptions | false
|
|
305
321
|
/** Hook opsional agar composition root dapat mereset riwayat osilasi saat verify hijau. */
|
|
306
322
|
onNoProgress?: (detector: NoProgressDetector) => void
|
|
323
|
+
/** Mengembalikan `true` jika batas jendela model dipin eksplisit oleh user
|
|
324
|
+
* (`--context-window` atau `origin: "user"`), sehingga guard estimasi
|
|
325
|
+
* lokal tidak boleh menaikkan jendela tanpa bukti error dari provider. */
|
|
326
|
+
isExplicitContextWindow?: (model?: string) => boolean
|
|
307
327
|
/**
|
|
308
328
|
* Dipanggil saat jendela konteks dinaikkan otomatis setelah overflow
|
|
309
329
|
* terverifikasi. Composition root memakainya untuk memberi tahu user
|
|
@@ -388,7 +408,7 @@ export async function createMinicodeSession(
|
|
|
388
408
|
// Fail-closed lebih awal (sebelum provider/system prompt): WorkMode non-
|
|
389
409
|
// EXECUTE di atas handler terinjeksi belum punya komposisi yang terbukti
|
|
390
410
|
// aman — jangan pernah membungkus atau melewati policy yang diinjeksi 6S.
|
|
391
|
-
const resolvedWorkMode: WorkMode = opts.workMode ?? "EXECUTE"
|
|
411
|
+
const resolvedWorkMode: WorkMode = normalizeWorkMode(opts.workMode ?? "EXECUTE")
|
|
392
412
|
if (opts.permissionHandler !== undefined && resolvedWorkMode !== "EXECUTE") {
|
|
393
413
|
throw new Error(
|
|
394
414
|
`createMinicodeSession: workMode ${resolvedWorkMode} dengan permissionHandler terinjeksi belum didukung (fail-closed S2.1)`,
|
|
@@ -405,6 +425,7 @@ export async function createMinicodeSession(
|
|
|
405
425
|
extra: opts.systemExtra ?? "",
|
|
406
426
|
signal: (opts as unknown as { signal?: AbortSignal }).signal,
|
|
407
427
|
lang: opts.lang,
|
|
428
|
+
allowLocalConfig: opts.allowLocalConfig,
|
|
408
429
|
})
|
|
409
430
|
const {
|
|
410
431
|
concurrency,
|
|
@@ -412,6 +433,7 @@ export async function createMinicodeSession(
|
|
|
412
433
|
permissionMode,
|
|
413
434
|
restrictBash,
|
|
414
435
|
workMode: _workMode,
|
|
436
|
+
allowNonTtyAsk,
|
|
415
437
|
allowLocalConfig,
|
|
416
438
|
systemExtra: _extra,
|
|
417
439
|
getContextModel: _getContextModel,
|
|
@@ -486,7 +508,8 @@ export async function createMinicodeSession(
|
|
|
486
508
|
mode: permissionMode ?? "auto",
|
|
487
509
|
root: defaultCwd,
|
|
488
510
|
ask,
|
|
489
|
-
|
|
511
|
+
allowNonTtyAsk,
|
|
512
|
+
allowLocalConfig: allowLocalConfig === true,
|
|
490
513
|
restrictBash,
|
|
491
514
|
onApprovalEvent,
|
|
492
515
|
authorizedTools,
|
|
@@ -515,8 +538,7 @@ export async function createMinicodeSession(
|
|
|
515
538
|
if (pm === "readonly") return "readonly"
|
|
516
539
|
if (pm === "plan") return "plan"
|
|
517
540
|
const wm = wmCtl.__getWorkMode?.() ?? resolvedWorkMode
|
|
518
|
-
if (wm === "DISCUSS") return "
|
|
519
|
-
if (wm === "PLAN") return "plan"
|
|
541
|
+
if (wm === "DISCUSS") return "plan"
|
|
520
542
|
if (isAllToolsPureRead()) return "explore"
|
|
521
543
|
return "active"
|
|
522
544
|
}
|
|
@@ -559,32 +581,44 @@ export async function createMinicodeSession(
|
|
|
559
581
|
// mengubah salinan MiniCore yang wajib disinkronkan dari repo sumber.
|
|
560
582
|
// Handler ASK yang sah tetap menunggu approval lalu mengembalikan allow/deny.
|
|
561
583
|
if (decision !== "allow") return "deny"
|
|
584
|
+
const recordStaleDeny = (reason: string): "deny" => {
|
|
585
|
+
const id = (call as { id?: string } | null)?.id
|
|
586
|
+
if (id) {
|
|
587
|
+
if (staleDenyReasons.size > 500)
|
|
588
|
+
staleDenyReasons.delete(staleDenyReasons.keys().next().value as string)
|
|
589
|
+
staleDenyReasons.set(id, reason)
|
|
590
|
+
}
|
|
591
|
+
return "deny"
|
|
592
|
+
}
|
|
562
593
|
// Ambil (konsumsi) bukti persetujuan milik call ini — sekali saja.
|
|
563
594
|
// Diambil SEBELUM await supaya tak ada binding tersisa kalau barrier
|
|
564
595
|
// memblokir call (tak ada deny lalu tak ada jejak).
|
|
565
|
-
const binding = approvalBindings.take(call.name, canonicalArgsHash(call.args))
|
|
596
|
+
const binding = approvalBindings.take(call.name, canonicalArgsHash(call.args), call.id)
|
|
597
|
+
// Verifikasi awal SEBELUM preflightIntent menulis record `pending` ke
|
|
598
|
+
// jurnal agar persetujuan basi / pergeseran mode tidak menodai jurnal.
|
|
599
|
+
const preVerdict = verifyApprovalBinding(binding)
|
|
600
|
+
if (authorizedVersion !== authorizationVersion || preVerdict.kind === "stale") {
|
|
601
|
+
return recordStaleDeny(
|
|
602
|
+
authorizedVersion !== authorizationVersion
|
|
603
|
+
? "authorization changed while preparing tool execution; request fresh approval"
|
|
604
|
+
: `approval stale: ${preVerdict.kind === "stale" ? preVerdict.reason : "changed"}`,
|
|
605
|
+
)
|
|
606
|
+
}
|
|
566
607
|
if (detector !== null) {
|
|
567
608
|
await detector.beforeToolEffectCheck(call, effectiveRoot)
|
|
568
609
|
}
|
|
569
610
|
if (beforeToolEffect !== undefined) {
|
|
570
611
|
await beforeToolEffect(call)
|
|
571
612
|
}
|
|
572
|
-
// Verifikasi lapis-2 (batas eksekusi): fail-closed
|
|
573
|
-
//
|
|
613
|
+
// Verifikasi lapis-2 (batas eksekusi): fail-closed bila target atau mode
|
|
614
|
+
// berubah selama await no-progress / intent jurnal berlangsung.
|
|
574
615
|
const verdict = verifyApprovalBinding(binding)
|
|
575
616
|
if (authorizedVersion !== authorizationVersion || verdict.kind === "stale") {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
id,
|
|
582
|
-
authorizedVersion !== authorizationVersion
|
|
583
|
-
? "authorization changed while preparing tool execution; request fresh approval"
|
|
584
|
-
: `approval stale: ${verdict.kind === "stale" ? verdict.reason : "changed"}`,
|
|
585
|
-
)
|
|
586
|
-
}
|
|
587
|
-
return "deny"
|
|
617
|
+
return recordStaleDeny(
|
|
618
|
+
authorizedVersion !== authorizationVersion
|
|
619
|
+
? "authorization changed while preparing tool execution; request fresh approval"
|
|
620
|
+
: `approval stale: ${verdict.kind === "stale" ? verdict.reason : "changed"}`,
|
|
621
|
+
)
|
|
588
622
|
}
|
|
589
623
|
return "allow"
|
|
590
624
|
},
|
|
@@ -630,8 +664,9 @@ export async function createMinicodeSession(
|
|
|
630
664
|
}
|
|
631
665
|
onWorkMode({
|
|
632
666
|
setWorkMode: (m) => {
|
|
633
|
-
|
|
634
|
-
wm.
|
|
667
|
+
const norm = normalizeWorkMode(m)
|
|
668
|
+
if (wm.__getWorkMode() !== norm) authorizationVersion++
|
|
669
|
+
wm.__setWorkMode(norm)
|
|
635
670
|
},
|
|
636
671
|
getWorkMode: () => wm.__getWorkMode(),
|
|
637
672
|
})
|
|
@@ -750,7 +785,15 @@ export async function createMinicodeSession(
|
|
|
750
785
|
* satu eskalasi. Namun ia tetap BOUNDED: satu langkah per kejadian, tak
|
|
751
786
|
* pernah melebihi batas atas, dan hasilnya hanya berlaku untuk sesi ini.
|
|
752
787
|
*/
|
|
753
|
-
const escalateContextWindow = (
|
|
788
|
+
const escalateContextWindow = (
|
|
789
|
+
model: string | undefined,
|
|
790
|
+
observedTokens: number,
|
|
791
|
+
fromClientGuard = false,
|
|
792
|
+
) => {
|
|
793
|
+
// Jika operator mem-pin jendela eksplisit (--context-window / origin user),
|
|
794
|
+
// guard kalibrasi lokal saja tidak boleh menaikkan pin tersebut tanpa
|
|
795
|
+
// bukti error kapasitas dari provider.
|
|
796
|
+
if (fromClientGuard && rest.isExplicitContextWindow?.(model)) return
|
|
754
797
|
const key = escalationKey(model)
|
|
755
798
|
const base = escalatedWindows.get(key) ?? contextWindowBase(model)
|
|
756
799
|
// Bila pengamatan sudah jelas melampaui jendela dasar, naik dari nilai
|
|
@@ -800,7 +843,7 @@ export async function createMinicodeSession(
|
|
|
800
843
|
const system = computeLiveSystem()
|
|
801
844
|
const model = req.model ?? currentContextModel()
|
|
802
845
|
let limit = contextWindowForModel(model)
|
|
803
|
-
|
|
846
|
+
let maxOutputTokens = maxOutputTokensForModel(model)
|
|
804
847
|
const estimatorModel = model?.includes("::") ? model : (currentContextModel() ?? model)
|
|
805
848
|
let calibration = calibrationFor(estimatorModel)
|
|
806
849
|
let estimator = (text: string) => preciseEstimator(estimatorModel, text)
|
|
@@ -855,22 +898,21 @@ export async function createMinicodeSession(
|
|
|
855
898
|
storeMessages: req.messages.length,
|
|
856
899
|
},
|
|
857
900
|
})
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
//
|
|
865
|
-
//
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
// 429/402/auth/jaringan.
|
|
869
|
-
escalateContextWindow(model, actualInput + actualOutput)
|
|
870
|
-
return new ProviderError(
|
|
901
|
+
let clientOverflowErr: ProviderError | undefined
|
|
902
|
+
const overflow = (
|
|
903
|
+
actualInput = inputTokens,
|
|
904
|
+
actualOutput = outputTokens,
|
|
905
|
+
clientGuard = false,
|
|
906
|
+
) => {
|
|
907
|
+
// context_length_exceeded agar kernel menempuh force_compact_and_retry,
|
|
908
|
+
// plus eskalasi adaptif terikat (hanya jalur overflow, bukan 429/402/auth).
|
|
909
|
+
escalateContextWindow(model, actualInput + actualOutput, clientGuard)
|
|
910
|
+
const err = new ProviderError(
|
|
871
911
|
"context_length_exceeded",
|
|
872
912
|
`context window budget reached for the selected model: input ${actualInput} + output ${actualOutput} exceeds ${limit} tokens; reduce the prompt/tools or select a larger context window`,
|
|
873
913
|
)
|
|
914
|
+
if (clientGuard) clientOverflowErr = err
|
|
915
|
+
return err
|
|
874
916
|
}
|
|
875
917
|
const requestController = new AbortController()
|
|
876
918
|
const forwardAbort = () => requestController.abort(signal.reason)
|
|
@@ -878,7 +920,7 @@ export async function createMinicodeSession(
|
|
|
878
920
|
else signal.addEventListener("abort", forwardAbort, { once: true })
|
|
879
921
|
try {
|
|
880
922
|
if (inputTokens + reserve >= limit) {
|
|
881
|
-
const error = overflow(inputTokens, 0)
|
|
923
|
+
const error = overflow(inputTokens, 0, true)
|
|
882
924
|
requestController.abort(error)
|
|
883
925
|
yield contextLimitEvent(inputTokens, 0)
|
|
884
926
|
throw error
|
|
@@ -896,6 +938,7 @@ export async function createMinicodeSession(
|
|
|
896
938
|
// a failed primary provider cannot silently widen the budget.
|
|
897
939
|
const effectiveModel = `${effective.provider}::${effective.effective}`
|
|
898
940
|
const effectiveLimit = contextWindowForModel(effectiveModel)
|
|
941
|
+
maxOutputTokens = maxOutputTokensForModel(effectiveModel) ?? maxOutputTokens
|
|
899
942
|
limit = Math.min(limit, effectiveLimit)
|
|
900
943
|
calibration = calibrationFor(effectiveModel)
|
|
901
944
|
estimator = (text: string) => preciseEstimator(effectiveModel, text)
|
|
@@ -934,7 +977,7 @@ export async function createMinicodeSession(
|
|
|
934
977
|
}
|
|
935
978
|
}
|
|
936
979
|
if (added > 0 && outputTokens + added > outputAllowance) {
|
|
937
|
-
const error = overflow(inputTokens, outputTokens + added)
|
|
980
|
+
const error = overflow(inputTokens, outputTokens + added, true)
|
|
938
981
|
requestController.abort(error)
|
|
939
982
|
yield contextLimitEvent(inputTokens, outputTokens + added)
|
|
940
983
|
throw error
|
|
@@ -943,6 +986,13 @@ export async function createMinicodeSession(
|
|
|
943
986
|
yield event as ProviderEvent
|
|
944
987
|
}
|
|
945
988
|
} catch (error) {
|
|
989
|
+
if (error instanceof ProviderError && error.category === "context_length_exceeded") {
|
|
990
|
+
escalateContextWindow(
|
|
991
|
+
model,
|
|
992
|
+
Math.max(inputTokens + outputTokens, limit),
|
|
993
|
+
error === clientOverflowErr,
|
|
994
|
+
)
|
|
995
|
+
}
|
|
946
996
|
// Generic 400 "invalid_request" dari gateway (tiprouter dll) yang BISA
|
|
947
997
|
// sebenarnya konteks kepanjangan meski teksnya tak menyebut "context".
|
|
948
998
|
// Reklasifikasi sebagai context_length_exceeded supaya kernel menempuh
|
|
@@ -958,7 +1008,7 @@ export async function createMinicodeSession(
|
|
|
958
1008
|
(error.category === "invalid_request" || error.category === "unknown") &&
|
|
959
1009
|
localInputTokens >= contextBudgetFor(limit, maxOutputTokens).reclassifyThreshold
|
|
960
1010
|
) {
|
|
961
|
-
throw overflow(inputTokens, outputTokens)
|
|
1011
|
+
throw overflow(inputTokens, outputTokens, false)
|
|
962
1012
|
}
|
|
963
1013
|
throw error
|
|
964
1014
|
} finally {
|
|
@@ -986,7 +1036,7 @@ export async function createMinicodeSession(
|
|
|
986
1036
|
maxSteps: effectiveMaxSteps,
|
|
987
1037
|
maxStepsForRun: () => effectiveMaxSteps,
|
|
988
1038
|
// Kompaksi lebih agresif (host-side): ringkas mulai 65% jendela, bukan 75%.
|
|
989
|
-
budget:
|
|
1039
|
+
budget: createAggressiveBudgetPolicy(() => maxOutputTokensForModel(currentContextModel())),
|
|
990
1040
|
provider: dynamicProvider,
|
|
991
1041
|
system: computeLiveSystem(),
|
|
992
1042
|
systemForContext: computeLiveSystem,
|
|
@@ -1007,10 +1057,12 @@ export async function createMinicodeSession(
|
|
|
1007
1057
|
lastProviderInputTokens = undefined
|
|
1008
1058
|
})
|
|
1009
1059
|
core.events.on("provider:extension", (e) => {
|
|
1060
|
+
if ((e as { forwardedChild?: unknown }).forwardedChild != null) return
|
|
1010
1061
|
if (e.kind !== "usage") return
|
|
1011
1062
|
const d = e.data as
|
|
1012
1063
|
| {
|
|
1013
1064
|
inputTokens?: number
|
|
1065
|
+
outputTokens?: number
|
|
1014
1066
|
totalTokens?: number
|
|
1015
1067
|
model?: string
|
|
1016
1068
|
provider?: string
|
|
@@ -1040,6 +1092,7 @@ export async function createMinicodeSession(
|
|
|
1040
1092
|
calibrationFor(reportedModel).observeProviderUsage({
|
|
1041
1093
|
localEstimatedTokens,
|
|
1042
1094
|
providerInputTokens: d.inputTokens,
|
|
1095
|
+
providerOutputTokens: d.outputTokens,
|
|
1043
1096
|
providerTotalTokens: d.totalTokens,
|
|
1044
1097
|
})
|
|
1045
1098
|
})
|
|
@@ -1140,7 +1193,7 @@ export async function createMinicodeSession(
|
|
|
1140
1193
|
if (reason === "fixpoint" || reason === "critical") {
|
|
1141
1194
|
const used =
|
|
1142
1195
|
typeof error.details?.fixedTokens === "number" ? error.details.fixedTokens : 0
|
|
1143
|
-
escalateContextWindow(modelForRun, used)
|
|
1196
|
+
escalateContextWindow(modelForRun, used, true)
|
|
1144
1197
|
}
|
|
1145
1198
|
}
|
|
1146
1199
|
// [T-008] Turn mentok batas langkah: naik satu tangga untuk turn
|
package/src/app/tool-layer.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { configureServers as lspConfigure } from "../lsp/client.ts"
|
|
|
4
4
|
import { connectAll as mcpConnectAll } from "../mcp/client.ts"
|
|
5
5
|
import {
|
|
6
6
|
EXPLORE_TOOL_NAMES,
|
|
7
|
-
LOCAL_READONLY_TOOL_NAMES,
|
|
8
7
|
PLAN_EXTRA_TOOL_NAMES,
|
|
9
8
|
READONLY_TOOL_NAMES,
|
|
10
9
|
} from "../policy/tool-contract.ts"
|
|
@@ -19,27 +18,23 @@ const errMsg = (e: unknown) => (e instanceof Error ? e.message : String(e))
|
|
|
19
18
|
|
|
20
19
|
export type ToolScope = "full" | "explore"
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// WorkMode ceiling (P12 S2.2 + P0.2) — lapisan intent di ATAS permission mode.
|
|
21
|
+
// WorkMode ceiling (DISCUSS menyatukan diskusi + perencanaan; EXECUTE = BUILD).
|
|
25
22
|
// Invariant INV-WM1 & #7: WorkMode TIDAK PERNAH memperluas akses; `visible`
|
|
26
23
|
// diselaraskan penuh dengan `callable` di handler:
|
|
27
|
-
// - DISCUSS:
|
|
28
|
-
// `web_fetch` & `web_search` ditolak dan disembunyikan.
|
|
29
|
-
// - PLAN: 18 `READONLY_TOOL_NAMES` (16 lokal + 2 network read ber-approval) +
|
|
24
|
+
// - DISCUSS: 18 `READONLY_TOOL_NAMES` (16 lokal + 2 network read ber-approval) +
|
|
30
25
|
// `PLAN_EXTRA` (kecuali bila `permissionMode` adalah `readonly`/`allowlist`
|
|
31
26
|
// yang ceiling-nya `readonly`).
|
|
32
27
|
// - EXECUTE: tanpa ceiling WorkMode tambahan; mengikuti `permissionMode`.
|
|
33
28
|
export function workModeVisible(
|
|
34
29
|
name: string,
|
|
35
|
-
workMode: "DISCUSS" | "
|
|
30
|
+
workMode: "DISCUSS" | "EXECUTE",
|
|
36
31
|
permissionMode?: string,
|
|
37
32
|
): boolean {
|
|
33
|
+
const wm = workMode === "EXECUTE" ? "EXECUTE" : "DISCUSS"
|
|
38
34
|
if (isMcpToolName(name)) {
|
|
39
|
-
return
|
|
35
|
+
return wm === "EXECUTE" && permissionMode !== "readonly" && permissionMode !== "plan"
|
|
40
36
|
}
|
|
41
|
-
if (
|
|
42
|
-
if (workMode === "PLAN") {
|
|
37
|
+
if (wm === "DISCUSS") {
|
|
43
38
|
if (permissionMode === "readonly" || permissionMode === "allowlist") {
|
|
44
39
|
return READONLY_TOOL_NAMES.has(name)
|
|
45
40
|
}
|
|
@@ -54,7 +49,7 @@ export function workModeVisible(
|
|
|
54
49
|
|
|
55
50
|
export function applyWorkModeFilter<T extends Tool>(
|
|
56
51
|
tools: readonly T[],
|
|
57
|
-
workMode: "DISCUSS" | "
|
|
52
|
+
workMode: "DISCUSS" | "EXECUTE",
|
|
58
53
|
permissionMode?: string,
|
|
59
54
|
): T[] {
|
|
60
55
|
return tools.filter((t) => workModeVisible(t.name, workMode, permissionMode))
|
|
@@ -68,13 +63,13 @@ export async function setupToolLayer(
|
|
|
68
63
|
permissionMode?: string,
|
|
69
64
|
verification?: CanonicalScope,
|
|
70
65
|
jobOwnerSid?: string,
|
|
71
|
-
workMode: "DISCUSS" | "
|
|
66
|
+
workMode: "DISCUSS" | "EXECUTE" = "EXECUTE",
|
|
72
67
|
cwd?: string,
|
|
73
68
|
): Promise<{
|
|
74
69
|
sessionTools: Tool[]
|
|
75
70
|
evidenceMode: ToolEvidenceMode
|
|
76
71
|
/** P12 S2.2 Slice 5 - set WorkMode runtime (visibilitas tool). */
|
|
77
|
-
setWorkMode?: (m: "DISCUSS" | "
|
|
72
|
+
setWorkMode?: (m: "DISCUSS" | "EXECUTE") => void
|
|
78
73
|
/** P0.2 - set PermissionMode runtime agar visibilitas tetap sinkron saat /mode atau Shift+Tab. */
|
|
79
74
|
setPermissionMode?: (pm: string) => void
|
|
80
75
|
}> {
|
|
@@ -124,9 +119,9 @@ export async function setupToolLayer(
|
|
|
124
119
|
// PermissionMode). `parallelExecutor` meresolusi `registry.get(name)` dari
|
|
125
120
|
// `list()` yang sama sehingga `callable === visible` di kedua arah transisi.
|
|
126
121
|
const candidates = sessionTools
|
|
127
|
-
let currentWm: "DISCUSS" | "
|
|
122
|
+
let currentWm: "DISCUSS" | "EXECUTE" = workMode
|
|
128
123
|
let currentPm: string | undefined = permissionMode
|
|
129
|
-
const computeVisible = (wm: "DISCUSS" | "
|
|
124
|
+
const computeVisible = (wm: "DISCUSS" | "EXECUTE", pm?: string): Tool[] => {
|
|
130
125
|
if (scope === "explore") {
|
|
131
126
|
// Scope explore sudah dibatasi ke EXPLORE_TOOL_NAMES; tetap terapkan irisan WorkMode.
|
|
132
127
|
return applyWorkModeFilter(candidates, wm, pm)
|
|
@@ -140,7 +135,7 @@ export async function setupToolLayer(
|
|
|
140
135
|
visible.length = 0
|
|
141
136
|
visible.push(...next)
|
|
142
137
|
}
|
|
143
|
-
const setWorkMode = (wm: "DISCUSS" | "
|
|
138
|
+
const setWorkMode = (wm: "DISCUSS" | "EXECUTE"): void => {
|
|
144
139
|
currentWm = wm
|
|
145
140
|
syncVisible()
|
|
146
141
|
}
|