chainlesschain 0.166.162 → 0.166.164
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 +27 -3
- package/package.json +1 -1
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/data/changelog.json +26 -0
- package/src/harness/prompt-compressor.js +10 -1
- package/src/lib/__tests__/provider-stream.test.js +16 -0
- package/src/lib/chat-core.js +10 -3
- package/src/lib/coding-task-guidance.js +1 -0
- package/src/lib/context-memory-kernel/live-compaction.js +100 -19
- package/src/lib/provider-stream.js +7 -3
- package/src/lib/read-file-loop-guard.js +9 -1
- package/src/lib/secret-store.js +30 -5
- package/src/lib/settings-loader.cjs +9 -2
- package/src/lib/stream-retry.js +20 -0
- package/src/lib/text-file-search.js +7 -2
- package/src/repl/agent-repl.js +387 -241
- package/src/repl/permission-prompt.js +62 -5
- package/src/repl/terminal-window.js +355 -0
- package/src/runtime/agent-core.js +7 -1
- package/src/runtime/coding-agent-contract-shared.cjs +4 -2
- package/src/runtime/headless-stream.js +54 -17
- package/src/runtime/provider-stream-state.js +3 -1
package/README.md
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
# chainlesschain CLI
|
|
2
2
|
|
|
3
|
-
## CLI 0.166.
|
|
3
|
+
## CLI 0.166.164 candidate
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The candidate adds a fullscreen Agent composer, live slash commands, a `/model` picker and automatic routine tool approvals for new interactive sessions. The planned pairing is Open VSX **0.37.199** and JetBrains **0.4.214**. The current public install command is below.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Public CLI 0.166.163
|
|
8
|
+
|
|
9
|
+
CLI **0.166.163** is available on npm from source `b06b3bfe0f1bf91d40617f3a0c83d918795d4fe6`. GitHub Actions published it through OIDC after CLI CI and Strict Sandbox passed on Linux, Windows, and macOS, then verified the public archive and signed provenance. Install `npm i -g chainlesschain@0.166.163 --registry https://registry.npmjs.org`, restart the CLI and IDE hosts, and run `cc --version` and `cc doctor`. [npm publication](https://github.com/longfa/chainlesschain/actions/runs/45535193598)
|
|
10
|
+
|
|
11
|
+
This release improves file-search diagnostics, retries a timed-out Windows credential read once, and asks coding agents to verify workspace changes before reporting delivery. File reads recover when the requested page reaches the model. Canonical compaction can shorten a local handoff while retaining file read positions. Chat Completions stream errors fail the turn, and interrupting a turn closes its pending approvals.
|
|
12
|
+
|
|
13
|
+
Open VSX **0.37.198** is public and recommends CLI `0.166.163`. JetBrains **0.4.213** pairs with the same CLI and its publication workflow is in progress. [Open VSX](https://open-vsx.org/extension/chainlesschain/chainlesschain-ide) · [JetBrains workflow](https://github.com/longfa/chainlesschain/actions/runs/45537935036)
|
|
14
|
+
|
|
15
|
+
The release limits are `NOT_PAID_READY` for paid readiness, `NOT_ADMITTED` for native admission, and `HOLD` for automatic promotion.
|
|
16
|
+
|
|
17
|
+
## Public CLI 0.166.162 and IDE pairing
|
|
18
|
+
|
|
19
|
+
CLI **0.166.162** is public on npm from exact source `03cb502b0e0e3facfbce79ef336fec7861a5554c`. GitHub Actions verified the public archive and signed provenance after CLI CI, Strict Sandbox, and the child package checks passed. Install `npm i -g chainlesschain@0.166.162 --registry https://registry.npmjs.org`, restart the CLI and IDE hosts, then run `cc --version` and `cc doctor`. [OIDC publication](https://github.com/longfa/chainlesschain/actions/runs/45306343051)
|
|
20
|
+
|
|
21
|
+
This release preserves approved plan permissions across resumes, reports headless persistence failures in JSON, and records Git installation outcomes. Open VSX **0.37.197** and JetBrains **0.4.212** are publicly downloadable and recommend this CLI version. [Upgrade guide](https://docs.chainlesschain.com/chainlesschain/cli-ide-update-2026-11-24-162.html)
|
|
22
|
+
|
|
23
|
+
Release limits are `NOT_PAID_READY` for paid readiness, `NOT_ADMITTED` for native admission, and `HOLD` for automatic promotion. This pairing covers the CLI and IDE extensions.
|
|
8
24
|
|
|
9
25
|
## Public CLI 0.166.161 and IDE pairing
|
|
10
26
|
|
|
@@ -319,6 +335,14 @@ Exact source `dfa158e36171e347a40e23356c2ed7bd04e0c061` passed complete Linux, W
|
|
|
319
335
|
|
|
320
336
|
The current [Agent reference](https://docs.chainlesschain.com/chainlesschain/cli-agent.html) covers optional delivery review and Goal recovery. [IDE configuration](https://docs.chainlesschain.com/chainlesschain/ide-plugin.html) documents conversation model overrides and unreadable configuration. [MCP Tool Search](https://docs.chainlesschain.com/chainlesschain/cli-tool-search.html), [Skills](https://docs.chainlesschain.com/chainlesschain/cli-skill.html), and [Memory](https://docs.chainlesschain.com/chainlesschain/cli-memory.html) describe discovery, defaults and query limits. Published behavior follows its frozen release source. Post-release main d9f2511b95 adds explicit review forwarding to evaluation drivers; its campaign is PREPARED_NOT_DISPATCHED and adds no independent acceptance.
|
|
321
337
|
|
|
338
|
+
### Interactive Agent in this checkout
|
|
339
|
+
|
|
340
|
+
Run `cc agent` in a terminal to open the conversation window with a fixed input area. Type `/` to filter commands, use the arrow keys to select one, and press Enter to run it or Tab to complete its name. During a turn, Enter queues follow-up messages. Press Up in an empty input area to retrieve the latest queued message for editing. `/status`, `/cost`, `/help` and `/btw <question>` respond while the turn runs. Esc or `/interrupt` interrupts the active model turn. Use Alt+Enter for a newline, Page Up and Page Down for earlier output, and `/tui default` for terminal scrollback.
|
|
341
|
+
|
|
342
|
+
New interactive CLI, VS Code and JetBrains Agent sessions use automatic routine tool approvals. Managed permission settings, explicit permission rules, and approved plan restrictions still apply. Choose `/permissions strict` in the CLI or `/normal` in either IDE to require normal approvals.
|
|
343
|
+
|
|
344
|
+
Use `/model` to pick a model for the current provider. Type to filter the list, use the arrow keys to select, and press Enter to apply. You can also enter an exact ID with `/model <model-id>`. A selection made during a turn applies to the next turn.
|
|
345
|
+
|
|
322
346
|
## CLI 0.166.127 — optional self-evolution (2026-10-27)
|
|
323
347
|
|
|
324
348
|
完整中文说明见[CLI 与 IDE 自进化开关配置](../../docs/cli/SELF_EVOLUTION_CONFIGURATION.md),包括默认行为、配置优先级、界面入口与生效时机。
|
package/package.json
CHANGED
package/src/data/changelog.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"source": "CHANGELOG.md",
|
|
3
3
|
"releases": [
|
|
4
|
+
{
|
|
5
|
+
"productVersion": null,
|
|
6
|
+
"cliVersion": "0.166.164",
|
|
7
|
+
"cliVersions": ["0.166.164"],
|
|
8
|
+
"date": "2026-11-26",
|
|
9
|
+
"title": "",
|
|
10
|
+
"sections": [
|
|
11
|
+
{
|
|
12
|
+
"heading": "Added - cc CLI 0.166.164 and IDE pairing (candidate, 2026-11-26)",
|
|
13
|
+
"body": "- Open interactive Agent sessions in a terminal window with a fixed composer, searchable slash commands, and queued follow-ups.\n- Switch models with a searchable `/model` picker or an exact model ID. Selections made during a turn apply to the next turn.\n- Use automatic routine tool approvals in new CLI, VS Code and JetBrains interactive sessions while honoring managed permission policies, explicit rules, and approved plans.\n- Pair CLI 0.166.164 with Open VSX 0.37.199 and JetBrains 0.4.214."
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"productVersion": null,
|
|
19
|
+
"cliVersion": "0.166.163",
|
|
20
|
+
"cliVersions": ["0.166.163"],
|
|
21
|
+
"date": "2026-11-24",
|
|
22
|
+
"title": "",
|
|
23
|
+
"sections": [
|
|
24
|
+
{
|
|
25
|
+
"heading": "Fixed - cc CLI 0.166.163 and IDE pairing (candidate, 2026-11-24)",
|
|
26
|
+
"body": "- Require a nonempty file search pattern and direct coding sessions to paginated reads when inspecting a file without a search term.\n- Preserve OS credential command failures and retry a timed-out Windows DPAPI read once.\n- Ask coding sessions to verify workspace changes against tool receipts before reporting delivery.\n- Let canonical compaction retain a handoff that fits the available conversation budget while enforcing the total context limit.\n- Use a bounded local handoff when a deterministic compaction summary exceeds the context budget, and retain file read positions.\n- Reset the failed file-read delivery streak when the model receives a requested source page.\n- Retire pending approvals on interruption and accept decisions only during their originating turn.\n- Report Chat Completions stream errors in the agent, chat, and token-stream commands and stop the failed response.\n- Pair with Open VSX 0.37.198 and JetBrains 0.4.213 after the exact-source release gates pass."
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
4
30
|
{
|
|
5
31
|
"productVersion": null,
|
|
6
32
|
"cliVersion": "0.166.162",
|
|
@@ -52,6 +52,11 @@ const SUMMARY_CALL_ID_MAX_CHARS = 128;
|
|
|
52
52
|
export const SUMMARY_INPUT_DEFAULT_MAX_CHARS = 24000;
|
|
53
53
|
export const SUMMARY_INPUT_HARD_MAX_CHARS = 32000;
|
|
54
54
|
const SUMMARY_INPUT_MIN_CHARS = 1024;
|
|
55
|
+
const localCompactionResults = new WeakSet();
|
|
56
|
+
|
|
57
|
+
export function isLocalCompactionResult(result) {
|
|
58
|
+
return localCompactionResults.has(result);
|
|
59
|
+
}
|
|
55
60
|
|
|
56
61
|
function isCompactionArtifact(message) {
|
|
57
62
|
const kind = getDurableSystemMessageProvenance(message)?.kind;
|
|
@@ -560,7 +565,11 @@ export class PromptCompressor {
|
|
|
560
565
|
stats.abVariant = abVariant.variant;
|
|
561
566
|
}
|
|
562
567
|
|
|
563
|
-
|
|
568
|
+
const outcome = { messages: result, stats };
|
|
569
|
+
if (summaryStats === null || summaryStats.summaryMode === "none") {
|
|
570
|
+
localCompactionResults.add(outcome);
|
|
571
|
+
}
|
|
572
|
+
return outcome;
|
|
564
573
|
}
|
|
565
574
|
|
|
566
575
|
shouldAutoCompact(messages) {
|
|
@@ -135,6 +135,22 @@ describe("openAIStream", () => {
|
|
|
135
135
|
expect(await collect(openAIStream(args))).toEqual(["x"]);
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
+
it("treats an explicit provider error as terminal without requiring a completion marker", async () => {
|
|
139
|
+
vi.stubGlobal(
|
|
140
|
+
"fetch",
|
|
141
|
+
mockFetch([
|
|
142
|
+
'data: {"choices":[{"delta":{"content":"partial"}}]}\n',
|
|
143
|
+
'data: {"error":{"message":"upstream connection reset"}}\n',
|
|
144
|
+
'data: {"choices":[{"delta":{"content":"late"}}]}\n',
|
|
145
|
+
]),
|
|
146
|
+
);
|
|
147
|
+
const stream = openAIStream(args);
|
|
148
|
+
expect(await stream.next()).toEqual({ done: false, value: "partial" });
|
|
149
|
+
await expect(stream.next()).rejects.toMatchObject({
|
|
150
|
+
code: "CC_CHAT_COMPLETIONS_STREAM_FAILED",
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
138
154
|
it("throws on a non-ok response", async () => {
|
|
139
155
|
vi.stubGlobal(
|
|
140
156
|
"fetch",
|
package/src/lib/chat-core.js
CHANGED
|
@@ -24,6 +24,9 @@ import {
|
|
|
24
24
|
} from "./provider-protocol.js";
|
|
25
25
|
import { appendTokenUsage } from "../harness/jsonl-session-store.js";
|
|
26
26
|
import {
|
|
27
|
+
CHAT_COMPLETIONS_STREAM_FAILED,
|
|
28
|
+
cancelProviderStreamReader,
|
|
29
|
+
createChatCompletionsStreamError,
|
|
27
30
|
isRetryableStreamError,
|
|
28
31
|
STREAM_RETRY_BASE_MS,
|
|
29
32
|
resolveStreamRetryMax,
|
|
@@ -332,8 +335,7 @@ export async function streamOpenAI(
|
|
|
332
335
|
}
|
|
333
336
|
try {
|
|
334
337
|
const json = JSON.parse(data);
|
|
335
|
-
if (
|
|
336
|
-
throw new Error("OpenAI stream returned an error");
|
|
338
|
+
if (json?.error) throw createChatCompletionsStreamError();
|
|
337
339
|
const content = json.choices?.[0]?.delta?.content;
|
|
338
340
|
if (content) {
|
|
339
341
|
fullResponse += content;
|
|
@@ -353,6 +355,7 @@ export async function streamOpenAI(
|
|
|
353
355
|
} catch (error) {
|
|
354
356
|
if (
|
|
355
357
|
options.requireCompletion ||
|
|
358
|
+
error?.code === CHAT_COMPLETIONS_STREAM_FAILED ||
|
|
356
359
|
error?.isOutputBackpressureFailure === true
|
|
357
360
|
)
|
|
358
361
|
throw error;
|
|
@@ -362,8 +365,12 @@ export async function streamOpenAI(
|
|
|
362
365
|
}
|
|
363
366
|
}
|
|
364
367
|
} catch (e) {
|
|
368
|
+
if (e?.code === CHAT_COMPLETIONS_STREAM_FAILED)
|
|
369
|
+
cancelProviderStreamReader(reader);
|
|
365
370
|
throw attachStreamRetryMetadata(
|
|
366
|
-
guard.stalled() &&
|
|
371
|
+
guard.stalled() &&
|
|
372
|
+
!isFormalBudgetError(e) &&
|
|
373
|
+
e?.code !== CHAT_COMPLETIONS_STREAM_FAILED
|
|
367
374
|
? new Error(
|
|
368
375
|
`API stream stalled (no data in ${STREAM_STALL_MS / 1000}s)`,
|
|
369
376
|
)
|
|
@@ -4,6 +4,7 @@ export const CODING_TASK_QUALITY_GUIDANCE = `Coding task quality:
|
|
|
4
4
|
- Keep progress explanations to one or two sentences. Resolve uncertainty with targeted reads, reuse unchanged source already inspected, and put code directly in write/edit arguments.
|
|
5
5
|
- Omitted or undelivered source has not been inspected. For an incomplete source excerpt, select a complete enclosing statement or container; a larger range or whole file within the tool limits may be necessary. Do not keep halving the same omitted page. For oversized output, select bounded fields or sections. If safe source remains unavailable, report that limitation without claiming completion.
|
|
6
6
|
- Resolve each relative import from the destination file's directory. Read back completed files and fix newDiagnostics. A successful write proves persistence, not test execution or acceptance.
|
|
7
|
+
- Report a file as created, changed, moved, or removed only after a tool confirms the action and you verify the resulting workspace state. Report any missing requested change as incomplete.
|
|
7
8
|
- Map every acceptance requirement to a fixture, real production call path and observable assertion. Positive and negative controls must reach the same boundary with unrelated prerequisites valid. Avoid mocks that bypass it; identify which assertion would fail without that boundary.
|
|
8
9
|
- Derive case allocation from the user's requirements. A test-count cap does not waive coverage: merge redundant cases to cover gaps within the cap, authorized scope and remaining budget. Report unresolved gaps as incomplete.
|
|
9
10
|
- Keep test fixtures and assertions within the runner's memory and time limits. For large binary payloads, assert lengths and use Buffer.equals or a digest for content checks; avoid deep matchers that enumerate every byte or print the entire payload on failure. Check boundary rejection before allocating a large body when the contract permits it.
|
|
@@ -9,8 +9,14 @@ import {
|
|
|
9
9
|
canonicalDigest,
|
|
10
10
|
InMemorySessionContextPort,
|
|
11
11
|
getCompactionPlanRejection,
|
|
12
|
+
planContext,
|
|
12
13
|
} from "@chainlesschain/context-memory-kernel";
|
|
13
14
|
import { sessionExists } from "../../harness/jsonl-session-store.js";
|
|
15
|
+
import { isLocalCompactionResult } from "../../harness/prompt-compressor.js";
|
|
16
|
+
import {
|
|
17
|
+
buildExtractiveHandoff,
|
|
18
|
+
formatStructuredHandoff,
|
|
19
|
+
} from "../../harness/structured-handoff.js";
|
|
14
20
|
import {
|
|
15
21
|
contextItemsToMessages,
|
|
16
22
|
createSummaryContextItem,
|
|
@@ -19,6 +25,7 @@ import {
|
|
|
19
25
|
import { JsonlSessionContextPort } from "./jsonl-session-context-port.js";
|
|
20
26
|
import { createCliContextMemoryRuntime } from "./runtime.js";
|
|
21
27
|
import { imageTransportEstimate } from "../image-token-estimate.js";
|
|
28
|
+
import { fileReadProgressBody } from "../read-file-page.js";
|
|
22
29
|
import { projectRuntimeTokenUsage } from "../runtime-usage-ledger.js";
|
|
23
30
|
import { isCompactionHostBase } from "../compaction-host-provenance.js";
|
|
24
31
|
import {
|
|
@@ -186,6 +193,11 @@ function kernelBudget(compressor, ephemeralTokens = 0, messages = []) {
|
|
|
186
193
|
// Live host policy/retry text still consumes the provider window even
|
|
187
194
|
// though it is deliberately absent from the durable authority partition.
|
|
188
195
|
safetyMarginTokens: ephemeralTokens,
|
|
196
|
+
// Like provider planning, let conversation use the available input budget.
|
|
197
|
+
// The kernel still applies the global limit and reserves recovery capacity.
|
|
198
|
+
partitionCeilings: {
|
|
199
|
+
conversation: Math.max(0, inputBudget - ephemeralTokens),
|
|
200
|
+
},
|
|
189
201
|
recoveryReserveTokens: Math.min(
|
|
190
202
|
256,
|
|
191
203
|
Math.max(1, Math.floor(inputBudget * 0.05)),
|
|
@@ -193,6 +205,44 @@ function kernelBudget(compressor, ephemeralTokens = 0, messages = []) {
|
|
|
193
205
|
};
|
|
194
206
|
}
|
|
195
207
|
|
|
208
|
+
function boundLocalHandoff(
|
|
209
|
+
item,
|
|
210
|
+
{ items, planRequest, summaryOptions, droppedMessages, compressedMessages },
|
|
211
|
+
) {
|
|
212
|
+
const droppedIds = new Set(
|
|
213
|
+
summaryOptions.parents.map(({ itemId }) => itemId),
|
|
214
|
+
);
|
|
215
|
+
const retained = items.filter(({ itemId }) => !droppedIds.has(itemId));
|
|
216
|
+
if (retained.length + droppedIds.size !== items.length) return item;
|
|
217
|
+
|
|
218
|
+
// Run the same planner as settlement so an already admissible handoff
|
|
219
|
+
// keeps its full contents. This preview has no write or provider effects.
|
|
220
|
+
const plan = planContext({ ...planRequest, items: [...retained, item] });
|
|
221
|
+
const omission = plan.dropped.find(({ itemId }) => itemId === item.itemId);
|
|
222
|
+
if (
|
|
223
|
+
!omission ||
|
|
224
|
+
!["input_budget", "partition_ceiling"].includes(omission.reason)
|
|
225
|
+
) {
|
|
226
|
+
return item;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const handoff = formatStructuredHandoff(
|
|
230
|
+
buildExtractiveHandoff(droppedMessages, {
|
|
231
|
+
maxContentChars: Math.min(4000, plan.selectableBudget * 2),
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
const bounded = createSummaryContextItem({
|
|
235
|
+
...summaryOptions,
|
|
236
|
+
messages: [
|
|
237
|
+
{ role: "assistant", content: `[Conversation Summary]\n${handoff}` },
|
|
238
|
+
...compressedMessages.filter(
|
|
239
|
+
(message) => fileReadProgressBody(message) !== null,
|
|
240
|
+
),
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
return bounded.tokenEstimate < item.tokenEstimate ? bounded : item;
|
|
244
|
+
}
|
|
245
|
+
|
|
196
246
|
function usageReceipt(stats, provider, model) {
|
|
197
247
|
if (stats?.summaryUsageUnknown === true) {
|
|
198
248
|
const error = new Error(
|
|
@@ -431,6 +481,22 @@ export async function compactLiveMessagesCanonical(
|
|
|
431
481
|
const provider = options.provider || "provider.local";
|
|
432
482
|
const model = options.model || "default";
|
|
433
483
|
const memoryRevision = await runtime.memoryPort.getRevision();
|
|
484
|
+
const compactionPolicy = {
|
|
485
|
+
...kernelBudget(
|
|
486
|
+
compressor,
|
|
487
|
+
messagesToContextItems(
|
|
488
|
+
ephemeralMessages.map(({ message }) => message),
|
|
489
|
+
{ sessionId, allowExternalization: false },
|
|
490
|
+
).reduce((total, item) => total + item.tokenEstimate, 0),
|
|
491
|
+
messages,
|
|
492
|
+
),
|
|
493
|
+
sink: provider,
|
|
494
|
+
scopeAdmissions: [{ scope: "session", scopeId: sessionId }],
|
|
495
|
+
policyVersion: "cli-context-policy-v1",
|
|
496
|
+
modelProfile: model,
|
|
497
|
+
memoryRevision,
|
|
498
|
+
now: operationNow,
|
|
499
|
+
};
|
|
434
500
|
let settledOutputItems = null;
|
|
435
501
|
{
|
|
436
502
|
const appendCompaction = runtime.sessionPort.appendCompaction.bind(
|
|
@@ -495,21 +561,8 @@ export async function compactLiveMessagesCanonical(
|
|
|
495
561
|
receipt = await runtime.kernel.compactContext({
|
|
496
562
|
operationId,
|
|
497
563
|
sessionId,
|
|
498
|
-
...
|
|
499
|
-
compressor,
|
|
500
|
-
messagesToContextItems(
|
|
501
|
-
ephemeralMessages.map(({ message }) => message),
|
|
502
|
-
{ sessionId, allowExternalization: false },
|
|
503
|
-
).reduce((total, item) => total + item.tokenEstimate, 0),
|
|
504
|
-
messages,
|
|
505
|
-
),
|
|
506
|
-
sink: provider,
|
|
507
|
-
scopeAdmissions: [{ scope: "session", scopeId: sessionId }],
|
|
508
|
-
policyVersion: "cli-context-policy-v1",
|
|
509
|
-
modelProfile: model,
|
|
510
|
-
memoryRevision,
|
|
564
|
+
...compactionPolicy,
|
|
511
565
|
allowFallback: false,
|
|
512
|
-
now: operationNow,
|
|
513
566
|
metadata: {
|
|
514
567
|
inputMessageCount: messages.length,
|
|
515
568
|
originalTokens: estimatedTokens(messages),
|
|
@@ -530,15 +583,43 @@ export async function compactLiveMessagesCanonical(
|
|
|
530
583
|
const reduced =
|
|
531
584
|
Number(summaryStats.saved || 0) > 0 ||
|
|
532
585
|
result.messages.length < droppedMessages.length;
|
|
533
|
-
const
|
|
586
|
+
const summaryOptions = {
|
|
587
|
+
parents: droppedItems,
|
|
588
|
+
operationId: context.operationId,
|
|
589
|
+
now: operationNow,
|
|
590
|
+
allowExternalization: persistentSession,
|
|
591
|
+
};
|
|
592
|
+
let item = reduced
|
|
534
593
|
? createSummaryContextItem({
|
|
594
|
+
...summaryOptions,
|
|
535
595
|
messages: result.messages,
|
|
536
|
-
parents: droppedItems,
|
|
537
|
-
operationId: context.operationId,
|
|
538
|
-
now: operationNow,
|
|
539
|
-
allowExternalization: persistentSession,
|
|
540
596
|
})
|
|
541
597
|
: null;
|
|
598
|
+
if (
|
|
599
|
+
item &&
|
|
600
|
+
summaryReceipt.outcome === "not_metered" &&
|
|
601
|
+
isLocalCompactionResult(result)
|
|
602
|
+
) {
|
|
603
|
+
const bounded = boundLocalHandoff(item, {
|
|
604
|
+
items: initialItems,
|
|
605
|
+
planRequest: {
|
|
606
|
+
...compactionPolicy,
|
|
607
|
+
sessionHead: context.inputHead,
|
|
608
|
+
},
|
|
609
|
+
summaryOptions,
|
|
610
|
+
droppedMessages,
|
|
611
|
+
compressedMessages: result.messages,
|
|
612
|
+
});
|
|
613
|
+
if (bounded !== item) {
|
|
614
|
+
item = bounded;
|
|
615
|
+
summaryStats = {
|
|
616
|
+
...summaryStats,
|
|
617
|
+
summaryMode: "extractive-fallback",
|
|
618
|
+
degraded: true,
|
|
619
|
+
degradedReason: "local_handoff_over_budget",
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
}
|
|
542
623
|
return {
|
|
543
624
|
items: item ? [item] : [],
|
|
544
625
|
usageReceipt: summaryReceipt,
|
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
import { resolveProviderDefinition } from "./llm-providers.js";
|
|
12
12
|
import { normalizeOllamaBaseUrl } from "./ollama-base-url.js";
|
|
13
13
|
import { ollamaProviderFetch } from "./ollama-provider-fetch.js";
|
|
14
|
+
import {
|
|
15
|
+
CHAT_COMPLETIONS_STREAM_FAILED,
|
|
16
|
+
createChatCompletionsStreamError,
|
|
17
|
+
} from "./stream-retry.js";
|
|
14
18
|
import {
|
|
15
19
|
assertCustomProviderConnection,
|
|
16
20
|
geminiGenerateContentUrl,
|
|
@@ -139,12 +143,12 @@ export async function* openAIStream({
|
|
|
139
143
|
}
|
|
140
144
|
try {
|
|
141
145
|
const obj = JSON.parse(payload);
|
|
142
|
-
if (
|
|
143
|
-
throw new Error("OpenAI stream returned an error");
|
|
146
|
+
if (obj?.error) throw createChatCompletionsStreamError();
|
|
144
147
|
const delta = obj?.choices?.[0]?.delta?.content;
|
|
145
148
|
if (delta) yield delta;
|
|
146
149
|
} catch (error) {
|
|
147
|
-
if (requireCompletion
|
|
150
|
+
if (requireCompletion || error?.code === CHAT_COMPLETIONS_STREAM_FAILED)
|
|
151
|
+
throw error;
|
|
148
152
|
/* skip */
|
|
149
153
|
}
|
|
150
154
|
}
|
|
@@ -103,8 +103,11 @@ export class ReadFileLoopGuard {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
for (const entry of this.progress.values()) {
|
|
106
|
+
let delivered = false;
|
|
107
|
+
let undelivered = 0;
|
|
106
108
|
for (const pending of entry.pendingPages) {
|
|
107
109
|
if (this.isPageVisible(pending.page)) {
|
|
110
|
+
delivered = true;
|
|
108
111
|
entry.confirmedSpans = mergeSpan(
|
|
109
112
|
entry.confirmedSpans,
|
|
110
113
|
pending.page.readSpan,
|
|
@@ -117,11 +120,16 @@ export class ReadFileLoopGuard {
|
|
|
117
120
|
};
|
|
118
121
|
}
|
|
119
122
|
} else {
|
|
120
|
-
|
|
123
|
+
undelivered++;
|
|
121
124
|
if (pending.reread) entry.rereads.delete(pending.reread);
|
|
122
125
|
if (pending.restoring) entry.contextRestoreOffered = false;
|
|
123
126
|
}
|
|
124
127
|
}
|
|
128
|
+
// Reset the streak only when a pending read is visible to the provider.
|
|
129
|
+
// An older page in the prompt cannot reset a failed new read.
|
|
130
|
+
entry.undeliveredReads = delivered
|
|
131
|
+
? 0
|
|
132
|
+
: entry.undeliveredReads + undelivered;
|
|
125
133
|
entry.pendingPages = [];
|
|
126
134
|
// Execution reserves ranges synchronously for parallel reads. Only
|
|
127
135
|
// source actually selected for the provider becomes historical coverage.
|
package/src/lib/secret-store.js
CHANGED
|
@@ -56,6 +56,21 @@ function defaultRunner(file, args, input = undefined) {
|
|
|
56
56
|
timeout: 15000,
|
|
57
57
|
...(input !== undefined ? { input } : {}),
|
|
58
58
|
});
|
|
59
|
+
if (result.error || result.signal) {
|
|
60
|
+
const reason = result.error?.code ?? result.signal;
|
|
61
|
+
const code =
|
|
62
|
+
typeof reason === "string" && /^[A-Z][A-Z0-9_]{0,39}$/u.test(reason)
|
|
63
|
+
? reason
|
|
64
|
+
: "SECRET_STORE_COMMAND_FAILED";
|
|
65
|
+
const message =
|
|
66
|
+
code === "ETIMEDOUT"
|
|
67
|
+
? "secret store command timed out"
|
|
68
|
+
: "secret store command failed";
|
|
69
|
+
const error = new Error(`${message} (${code})`);
|
|
70
|
+
error.code = code;
|
|
71
|
+
error.exitCode = result.status;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
59
74
|
if (result.status !== 0) {
|
|
60
75
|
const error = new Error(
|
|
61
76
|
String(result.stderr || "secret store command failed").trim(),
|
|
@@ -202,11 +217,21 @@ function createDpapiBackend({
|
|
|
202
217
|
key = normalizeSecretIdentifier(key, "secret key");
|
|
203
218
|
const encoded = load()[key];
|
|
204
219
|
if (!encoded) return null;
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
220
|
+
const unprotect = () =>
|
|
221
|
+
runner(
|
|
222
|
+
"powershell.exe",
|
|
223
|
+
["-NoProfile", "-NonInteractive", "-Command", DPAPI_UNPROTECT_SCRIPT],
|
|
224
|
+
encoded,
|
|
225
|
+
).trim();
|
|
226
|
+
let plain;
|
|
227
|
+
try {
|
|
228
|
+
plain = unprotect();
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (error?.code !== "ETIMEDOUT") throw error;
|
|
231
|
+
// A cold PowerShell start can time out. DPAPI unprotect only reads the
|
|
232
|
+
// encrypted value, so one retry is safe before reporting a failure.
|
|
233
|
+
plain = unprotect();
|
|
234
|
+
}
|
|
210
235
|
return Buffer.from(plain, "base64").toString("utf8");
|
|
211
236
|
},
|
|
212
237
|
delete(key) {
|
|
@@ -238,11 +238,17 @@ function applyManagedPermissionPolicy(baseRules, managed, sources = {}) {
|
|
|
238
238
|
return rules;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
function defaultInteractivePermissionMode(managed) {
|
|
242
|
+
return managed?.disableBypassPermissionsMode === true ||
|
|
243
|
+
managed?.disableBypassPermissionsMode === "disable"
|
|
244
|
+
? "default"
|
|
245
|
+
: "bypassPermissions";
|
|
246
|
+
}
|
|
247
|
+
|
|
241
248
|
function assertManagedPermissionMode(mode, managed) {
|
|
242
249
|
if (
|
|
243
250
|
mode === "bypassPermissions" &&
|
|
244
|
-
(managed
|
|
245
|
-
managed?.disableBypassPermissionsMode === "disable")
|
|
251
|
+
defaultInteractivePermissionMode(managed) === "default"
|
|
246
252
|
) {
|
|
247
253
|
throw new Error(
|
|
248
254
|
'permission mode "bypassPermissions" is disabled by managed settings',
|
|
@@ -752,6 +758,7 @@ module.exports = {
|
|
|
752
758
|
loadManagedSettings,
|
|
753
759
|
applyManagedPermissionPolicy,
|
|
754
760
|
assertManagedPermissionMode,
|
|
761
|
+
defaultInteractivePermissionMode,
|
|
755
762
|
parseEnvList,
|
|
756
763
|
mergeSandboxSettings,
|
|
757
764
|
ruleSource,
|
package/src/lib/stream-retry.js
CHANGED
|
@@ -24,6 +24,26 @@ import { isFormalBudgetError } from "./formal-budget-errors.js";
|
|
|
24
24
|
export const STREAM_RETRY_MAX = 2;
|
|
25
25
|
export const STREAM_RETRY_BASE_MS = 400;
|
|
26
26
|
export const STREAM_RETRY_MAX_DELAY_MS = 60_000;
|
|
27
|
+
export const CHAT_COMPLETIONS_STREAM_FAILED =
|
|
28
|
+
"CC_CHAT_COMPLETIONS_STREAM_FAILED";
|
|
29
|
+
|
|
30
|
+
export function createChatCompletionsStreamError() {
|
|
31
|
+
return Object.assign(
|
|
32
|
+
new Error("OpenAI-compatible stream returned a provider error"),
|
|
33
|
+
{
|
|
34
|
+
code: CHAT_COMPLETIONS_STREAM_FAILED,
|
|
35
|
+
noReplay: true,
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function cancelProviderStreamReader(reader) {
|
|
41
|
+
try {
|
|
42
|
+
void Promise.resolve(reader.cancel?.()).catch(() => {});
|
|
43
|
+
} catch {
|
|
44
|
+
// Preserve the provider error even if the transport cannot be cancelled.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
27
47
|
|
|
28
48
|
function isFailureStatus(status) {
|
|
29
49
|
return Number.isInteger(status) && status >= 400 && status <= 599;
|
|
@@ -12,9 +12,14 @@ export function searchTextFile(file, options = {}) {
|
|
|
12
12
|
timeout = 5000,
|
|
13
13
|
encoding = "utf8",
|
|
14
14
|
} = options;
|
|
15
|
+
if (typeof pattern !== "string" || !pattern) {
|
|
16
|
+
return Promise.resolve({
|
|
17
|
+
error: "A nonempty pattern is required for text search",
|
|
18
|
+
code: "ERR_TEXT_SEARCH_OPTIONS",
|
|
19
|
+
hint: "Supply the text you want to find as pattern. To inspect a known file without a search term, use read_file with path, offset, and limit.",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
15
22
|
if (
|
|
16
|
-
typeof pattern !== "string" ||
|
|
17
|
-
!pattern ||
|
|
18
23
|
pattern.length > 2048 ||
|
|
19
24
|
!Number.isSafeInteger(offset) ||
|
|
20
25
|
offset < 0 ||
|