chainlesschain 0.166.162 → 0.166.163
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 +9 -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 +13 -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/stream-retry.js +20 -0
- package/src/lib/text-file-search.js +7 -2
- package/src/runtime/agent-core.js +7 -1
- package/src/runtime/coding-agent-contract-shared.cjs +4 -2
- package/src/runtime/headless-stream.js +36 -15
- package/src/runtime/provider-stream-state.js +3 -1
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# chainlesschain CLI
|
|
2
2
|
|
|
3
|
-
## CLI 0.166.
|
|
3
|
+
## CLI 0.166.163 candidate
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The candidate improves file-search diagnostics, retries a timed-out Windows credential read once, and asks coding agents to verify workspace changes before reporting delivery. When the model receives a requested source page, the CLI clears the consecutive delivery failures for that file. Canonical compaction retains full handoffs that fit the conversation budget and can use a shorter local handoff with file read positions when needed. Chat Completions provider errors stop the stream and fail the turn. Interrupting a turn closes its pending approvals. The planned pairing is Open VSX **0.37.198** and JetBrains **0.4.213**. The public pairing and install command are below.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Public CLI 0.166.162 and IDE pairing
|
|
8
|
+
|
|
9
|
+
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)
|
|
10
|
+
|
|
11
|
+
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)
|
|
12
|
+
|
|
13
|
+
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
14
|
|
|
9
15
|
## Public CLI 0.166.161 and IDE pairing
|
|
10
16
|
|
package/package.json
CHANGED
package/src/data/changelog.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"source": "CHANGELOG.md",
|
|
3
3
|
"releases": [
|
|
4
|
+
{
|
|
5
|
+
"productVersion": null,
|
|
6
|
+
"cliVersion": "0.166.163",
|
|
7
|
+
"cliVersions": ["0.166.163"],
|
|
8
|
+
"date": "2026-11-24",
|
|
9
|
+
"title": "",
|
|
10
|
+
"sections": [
|
|
11
|
+
{
|
|
12
|
+
"heading": "Fixed - cc CLI 0.166.163 and IDE pairing (candidate, 2026-11-24)",
|
|
13
|
+
"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."
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
4
17
|
{
|
|
5
18
|
"productVersion": null,
|
|
6
19
|
"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) {
|
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 ||
|
|
@@ -220,6 +220,8 @@ import {
|
|
|
220
220
|
import { buildSearchCommand } from "../lib/search-command.js";
|
|
221
221
|
import { discoverCommands } from "../lib/slash-commands.js";
|
|
222
222
|
import {
|
|
223
|
+
CHAT_COMPLETIONS_STREAM_FAILED,
|
|
224
|
+
cancelProviderStreamReader,
|
|
223
225
|
isRetryableStreamError,
|
|
224
226
|
STREAM_RETRY_BASE_MS,
|
|
225
227
|
resolveStreamRetryMax,
|
|
@@ -1266,7 +1268,7 @@ ${CODING_TASK_QUALITY_GUIDANCE}
|
|
|
1266
1268
|
- The git tool accepts ONE Git argument list, without pipes, redirects, &&, semicolons or echo. Use log -n 5 instead of piping to head; inspect the returned exitCode for predicates such as merge-base --is-ancestor (1 means false). Discover remote names with remote -v; do not assume origin exists.
|
|
1267
1269
|
- On Windows, run_shell defaults to cmd unless configured otherwise. Set shell: "powershell" for PowerShell syntax or shell: "pwsh" for PowerShell 7. Parse saved JSON after stripping an initial UTF-8 BOM; a BOM parse error is not a JavaScript syntax defect.
|
|
1268
1270
|
- When asked about files or code, use search_files to locate relevant sections, then read_file with offset/limit. Follow nextRead for large files. Reuse unchanged content already in context instead of repeatedly reading the same page; re-read when the file changes or the earlier content is no longer available.
|
|
1269
|
-
-
|
|
1271
|
+
- To find specific text in a long file, use search_files with path and a nonempty pattern, then read the returned nextRead location. To inspect a file without a search term, use read_file with offset and limit.
|
|
1270
1272
|
- For online discovery without a known URL, use web_search with keywords. Return relevant source links and snippets; use web_fetch only when the source needs closer reading. For a known URL, fetch it directly. Download large pages once, then use snapshotId to search or read local chunks. Never invent URLs or claim a blocked search returned no results.
|
|
1271
1273
|
- Large task documents include a sampled outline with line numbers. Use it to locate relevant unfinished work and inspect those sections instead of scanning the entire document unless the task requires full coverage. File coverage and excerpts survive compaction; reading to EOF is not completing the user's task.
|
|
1272
1274
|
- For task counts or completion status, search the named document for the latest status/summary table first, then read that section. Distinguish historical entries from current status and repository work from external acceptance. Once the relevant entries are verified, answer; do not read every implementation detail just to count tasks.
|
|
@@ -13666,6 +13668,10 @@ async function _chatOpenAIStreaming(
|
|
|
13666
13668
|
}
|
|
13667
13669
|
} catch (err) {
|
|
13668
13670
|
attachStreamRetryMetadata(err, retryMetadata);
|
|
13671
|
+
if (err?.code === CHAT_COMPLETIONS_STREAM_FAILED) {
|
|
13672
|
+
cancelProviderStreamReader(reader);
|
|
13673
|
+
throw err;
|
|
13674
|
+
}
|
|
13669
13675
|
if (!ui.hasVisibleOutput() && !state.text && state.tools.length)
|
|
13670
13676
|
err.noReplay = true;
|
|
13671
13677
|
if (
|
|
@@ -390,13 +390,15 @@ const CODING_AGENT_TOOL_CONTRACTS = Object.freeze([
|
|
|
390
390
|
kind: "filesystem",
|
|
391
391
|
tier: "mvp",
|
|
392
392
|
description:
|
|
393
|
-
"
|
|
393
|
+
"Find files by name or search for matching text. For one text file, supply path and a nonempty pattern to get line/column positions, nearby text, and nextRead arguments. Continue capped results with nextOffset as offset. To inspect a known file without a search term, use read_file with path, offset, and limit. For a directory search, omit path and set content_search:true to search file contents.",
|
|
394
394
|
inputSchema: {
|
|
395
395
|
type: "object",
|
|
396
396
|
properties: {
|
|
397
397
|
pattern: {
|
|
398
398
|
type: "string",
|
|
399
|
-
|
|
399
|
+
minLength: 1,
|
|
400
|
+
description:
|
|
401
|
+
"Nonempty filename pattern or text to match. For a single file, use at most 2048 characters.",
|
|
400
402
|
},
|
|
401
403
|
path: {
|
|
402
404
|
type: "string",
|
|
@@ -2684,6 +2684,7 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
2684
2684
|
// resolution is echoed as `approval_resolved` so UIs can settle their cards.
|
|
2685
2685
|
const interactive = options.interactiveApprovals === true;
|
|
2686
2686
|
const pendingApprovals = new Map();
|
|
2687
|
+
let currentAbort = null;
|
|
2687
2688
|
let approvalSeq = 0;
|
|
2688
2689
|
const approvalTimeoutMs =
|
|
2689
2690
|
Number(process.env.CC_APPROVAL_TIMEOUT_MS) > 0
|
|
@@ -2698,11 +2699,18 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
2698
2699
|
) => {
|
|
2699
2700
|
const p = pendingApprovals.get(id);
|
|
2700
2701
|
if (!p) return;
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2702
|
+
let approve = ["acceptOnce", "acceptForTurn", "acceptForSession"].includes(
|
|
2703
|
+
decision?.kind,
|
|
2704
|
+
);
|
|
2705
|
+
if (
|
|
2706
|
+
approve &&
|
|
2707
|
+
p.turn &&
|
|
2708
|
+
(p.turn !== currentAbort || p.turn.signal.aborted)
|
|
2709
|
+
) {
|
|
2710
|
+
approve = false;
|
|
2711
|
+
decision = { kind: "decline", reason: "Approval turn ended" };
|
|
2712
|
+
via = "turn-ended";
|
|
2713
|
+
}
|
|
2706
2714
|
// Approval binding (authority §"权限来源与跨 Agent 授权边界"): an *approve*
|
|
2707
2715
|
// verdict that carries a binding which does NOT match the one the request
|
|
2708
2716
|
// advertised is stale / mis-routed / argument-tampered — reject it (deny,
|
|
@@ -2766,7 +2774,8 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
2766
2774
|
});
|
|
2767
2775
|
p.resolve(!invalidReason && approve);
|
|
2768
2776
|
};
|
|
2769
|
-
const interactiveConfirm = (ctx = {}) => {
|
|
2777
|
+
const interactiveConfirm = (ctx = {}, turn = currentAbort) => {
|
|
2778
|
+
if (turn && (turn !== currentAbort || turn.signal.aborted)) return false;
|
|
2770
2779
|
const requiredPermission = approvalPermissionForContext(ctx, { cwd });
|
|
2771
2780
|
if (approvalGrantLedger.allows(requiredPermission)) return true;
|
|
2772
2781
|
return new Promise((resolve) => {
|
|
@@ -2796,6 +2805,7 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
2796
2805
|
timer,
|
|
2797
2806
|
binding,
|
|
2798
2807
|
requiredPermission,
|
|
2808
|
+
turn,
|
|
2799
2809
|
});
|
|
2800
2810
|
emit({
|
|
2801
2811
|
type: "approval_request",
|
|
@@ -4075,10 +4085,6 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
4075
4085
|
classifyAllShell,
|
|
4076
4086
|
enabledToolNames,
|
|
4077
4087
|
disabledTools,
|
|
4078
|
-
// --interactive-approvals: settings/hook `ask` (and, with an IDE bridge,
|
|
4079
|
-
// edit reviews via openDiff) route to the structured approval round-trip
|
|
4080
|
-
// instead of failing closed. Absent in CI/pipes → unchanged fail-closed.
|
|
4081
|
-
permissionConfirm: interactive ? interactiveConfirm : undefined,
|
|
4082
4088
|
// ask_user_question round-trip (opt-in via CC_INTERACTIVE_QUESTIONS): give
|
|
4083
4089
|
// the tool handler an askUser that emits question_request + blocks on stdin.
|
|
4084
4090
|
// Absent → agent-core returns user_not_reachable (graceful proceed).
|
|
@@ -4337,7 +4343,6 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
4337
4343
|
const queue = [];
|
|
4338
4344
|
let wakeQueue = null;
|
|
4339
4345
|
let inputDone = false;
|
|
4340
|
-
let currentAbort = null;
|
|
4341
4346
|
let inputBacklogFailure = false;
|
|
4342
4347
|
let slashRequestSeq = 0;
|
|
4343
4348
|
const inputLines = readJsonLines(input);
|
|
@@ -4402,7 +4407,19 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
4402
4407
|
settlePermissionDecisionGate(true);
|
|
4403
4408
|
}
|
|
4404
4409
|
if (parsed.interrupt) {
|
|
4405
|
-
currentAbort
|
|
4410
|
+
const interruptedTurn = currentAbort;
|
|
4411
|
+
interruptedTurn?.abort();
|
|
4412
|
+
if (interruptedTurn) {
|
|
4413
|
+
for (const [id, pending] of pendingApprovals) {
|
|
4414
|
+
if (pending.turn === interruptedTurn) {
|
|
4415
|
+
settleApproval(
|
|
4416
|
+
id,
|
|
4417
|
+
{ kind: "decline", reason: "Approval turn interrupted" },
|
|
4418
|
+
"turn-interrupted",
|
|
4419
|
+
);
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4406
4423
|
continue;
|
|
4407
4424
|
}
|
|
4408
4425
|
if (parsed.approval) {
|
|
@@ -5825,10 +5842,11 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
5825
5842
|
// Per-turn abort scope: an {"type":"interrupt"} from the pump above
|
|
5826
5843
|
// aborts THIS turn (LLM fetch included — the signal reaches chatWithTools)
|
|
5827
5844
|
// while the conversation/process stays alive for the next message.
|
|
5828
|
-
|
|
5845
|
+
const turn = new AbortController();
|
|
5846
|
+
currentAbort = turn;
|
|
5829
5847
|
const turnSignal = options.signal
|
|
5830
|
-
? AbortSignal.any([options.signal,
|
|
5831
|
-
:
|
|
5848
|
+
? AbortSignal.any([options.signal, turn.signal])
|
|
5849
|
+
: turn.signal;
|
|
5832
5850
|
|
|
5833
5851
|
// Capture the resumed pairs once, then normalize those same pairs only in
|
|
5834
5852
|
// every provider request. The live authority array retains separate turns.
|
|
@@ -5843,6 +5861,9 @@ async function runAgentHeadlessStreamInWorkspace(
|
|
|
5843
5861
|
messages,
|
|
5844
5862
|
{
|
|
5845
5863
|
...loopOptionsBase,
|
|
5864
|
+
permissionConfirm: interactive
|
|
5865
|
+
? (context) => interactiveConfirm(context, turn)
|
|
5866
|
+
: undefined,
|
|
5846
5867
|
// Custom-command frontmatter scopes THIS turn (parity with `cc command
|
|
5847
5868
|
// run` / headless -p): a matched /name applies its model: and
|
|
5848
5869
|
// allowed-tools:. Lowest-priority override — an explicit per-turn
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
projectUsagePricingContext,
|
|
9
9
|
projectEnvelopePricingContext,
|
|
10
10
|
} from "../lib/usage-pricing-context.js";
|
|
11
|
+
import { createChatCompletionsStreamError } from "../lib/stream-retry.js";
|
|
11
12
|
|
|
12
13
|
export function _isNonNegativeSafeInteger(value) {
|
|
13
14
|
return Number.isSafeInteger(value) && value >= 0;
|
|
@@ -321,7 +322,8 @@ export function _openaiReduceLine(state, raw, onToken) {
|
|
|
321
322
|
state.terminationInvalid = true;
|
|
322
323
|
return state;
|
|
323
324
|
}
|
|
324
|
-
if (
|
|
325
|
+
if (obj?.error) throw createChatCompletionsStreamError();
|
|
326
|
+
if (state.streamDone) state.terminationInvalid = true;
|
|
325
327
|
if (!Array.isArray(obj.choices) || obj.choices.length > 1) {
|
|
326
328
|
state.terminationInvalid = true;
|
|
327
329
|
}
|