@cjhyy/code-shell-core 0.5.0-rc.0 → 0.5.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent-definition-registry.d.ts +29 -0
- package/dist/agent/agent-definition-registry.js +74 -0
- package/dist/agent/agent-definition.d.ts +37 -0
- package/dist/agent/agent-definition.js +59 -0
- package/dist/arena/arena.js +11 -12
- package/dist/arena/context/context-tools.js +2 -4
- package/dist/arena/context/within-root.d.ts +7 -0
- package/dist/arena/context/within-root.js +15 -0
- package/dist/arena/iterate/phases/argue.js +8 -2
- package/dist/arena/iterate/phases/revise.js +1 -1
- package/dist/arena/iterate/phases/tournament.js +3 -3
- package/dist/arena/phases/adjudication.js +1 -4
- package/dist/arena/phases/build-consensus.js +1 -4
- package/dist/arena/phases/cross-review.js +2 -8
- package/dist/arena/phases/debate-rounds.js +1 -4
- package/dist/arena/phases/participant-research.js +1 -4
- package/dist/arena/phases/planning-detail-expansion.js +8 -10
- package/dist/arena/planner.js +0 -1
- package/dist/arena/providers/docs.d.ts +1 -0
- package/dist/arena/providers/docs.js +5 -2
- package/dist/arena/providers/repo.d.ts +1 -0
- package/dist/arena/providers/repo.js +5 -2
- package/dist/arena/strategies/utils.js +36 -3
- package/dist/arena/transitions.d.ts +7 -2
- package/dist/arena/transitions.js +9 -4
- package/dist/arena/types.d.ts +8 -2
- package/dist/automation/cron-expr.d.ts +31 -0
- package/dist/automation/cron-expr.js +151 -0
- package/dist/automation/index.d.ts +41 -0
- package/dist/automation/index.js +39 -0
- package/dist/automation/runner.d.ts +67 -0
- package/dist/automation/runner.js +56 -0
- package/dist/automation/scheduler.d.ts +156 -0
- package/dist/automation/scheduler.js +546 -0
- package/dist/automation/store.d.ts +39 -0
- package/dist/automation/store.js +119 -0
- package/dist/automation/write-policy.d.ts +34 -0
- package/dist/automation/write-policy.js +113 -0
- package/dist/automation/write-run.d.ts +51 -0
- package/dist/automation/write-run.js +38 -0
- package/dist/capability-control/index.d.ts +5 -0
- package/dist/capability-control/index.js +3 -0
- package/dist/capability-control/overlay.d.ts +49 -0
- package/dist/capability-control/overlay.js +89 -0
- package/dist/capability-control/project.d.ts +65 -0
- package/dist/capability-control/project.js +147 -0
- package/dist/capability-control/service.d.ts +70 -0
- package/dist/capability-control/service.js +147 -0
- package/dist/capability-control/types.d.ts +62 -0
- package/dist/capability-control/types.js +17 -0
- package/dist/cli/agent-server-stdio.d.ts +12 -1
- package/dist/cli/agent-server-stdio.js +118 -18
- package/dist/cli/agent-server-tcp.d.ts +20 -0
- package/dist/cli/agent-server-tcp.js +120 -0
- package/dist/cli/graceful-shutdown.d.ts +27 -0
- package/dist/cli/graceful-shutdown.js +30 -0
- package/dist/context/compaction.js +23 -15
- package/dist/context/manager.d.ts +0 -20
- package/dist/context/manager.js +0 -37
- package/dist/cron/cron-runtime.d.ts +2 -0
- package/dist/cron/cron-runtime.js +2 -0
- package/dist/cron/cron-store.d.ts +2 -0
- package/dist/cron/cron-store.js +2 -0
- package/dist/cron/scheduler.d.ts +5 -32
- package/dist/cron/scheduler.js +5 -113
- package/dist/data/openrouter-sync.js +1 -1
- package/dist/engine/engine.d.ts +256 -16
- package/dist/engine/engine.js +856 -200
- package/dist/engine/goal.d.ts +42 -0
- package/dist/engine/goal.js +52 -0
- package/dist/engine/image-compression.d.ts +81 -0
- package/dist/engine/image-compression.js +186 -0
- package/dist/engine/image-policy.d.ts +152 -0
- package/dist/engine/image-policy.js +165 -0
- package/dist/engine/reactive-threshold.d.ts +13 -0
- package/dist/engine/reactive-threshold.js +17 -0
- package/dist/engine/runtime.js +7 -0
- package/dist/engine/session-title.d.ts +13 -0
- package/dist/engine/session-title.js +34 -0
- package/dist/engine/turn-loop.d.ts +29 -8
- package/dist/engine/turn-loop.js +498 -316
- package/dist/git/parse-log.d.ts +13 -0
- package/dist/git/parse-log.js +21 -0
- package/dist/git/utils.d.ts +8 -6
- package/dist/git/utils.js +57 -26
- package/dist/git/worktree.js +33 -18
- package/dist/hooks/events.d.ts +23 -1
- package/dist/hooks/goal-stop-hook.d.ts +30 -0
- package/dist/hooks/goal-stop-hook.js +102 -0
- package/dist/hooks/hook-output.d.ts +33 -0
- package/dist/hooks/hook-output.js +79 -0
- package/dist/hooks/registry.d.ts +7 -0
- package/dist/hooks/registry.js +38 -1
- package/dist/hooks/shell-runner.d.ts +2 -0
- package/dist/hooks/shell-runner.js +43 -2
- package/dist/index.d.ts +32 -7
- package/dist/index.js +30 -3
- package/dist/llm/capabilities/reasoning-control.d.ts +24 -0
- package/dist/llm/capabilities/reasoning-control.js +38 -0
- package/dist/llm/capabilities/rules.js +33 -3
- package/dist/llm/capabilities/types.d.ts +22 -2
- package/dist/llm/clamp-max-tokens.d.ts +11 -0
- package/dist/llm/clamp-max-tokens.js +17 -0
- package/dist/llm/client-base.d.ts +41 -4
- package/dist/llm/client-base.js +67 -13
- package/dist/llm/client-factory.d.ts +3 -3
- package/dist/llm/client-factory.js +2 -2
- package/dist/llm/model-pool.d.ts +15 -11
- package/dist/llm/model-pool.js +23 -20
- package/dist/llm/provider-catalog.d.ts +2 -2
- package/dist/llm/providers/anthropic.d.ts +32 -2
- package/dist/llm/providers/anthropic.js +147 -8
- package/dist/llm/providers/openai.d.ts +11 -2
- package/dist/llm/providers/openai.js +253 -52
- package/dist/llm/reasoning-setting.d.ts +51 -0
- package/dist/llm/reasoning-setting.js +32 -0
- package/dist/llm/stop-reason.d.ts +13 -0
- package/dist/llm/stop-reason.js +21 -0
- package/dist/llm/strip-vision.d.ts +32 -0
- package/dist/llm/strip-vision.js +94 -0
- package/dist/llm/types.d.ts +5 -6
- package/dist/logging/logger.js +18 -4
- package/dist/logging/sanitize-messages.d.ts +10 -0
- package/dist/logging/sanitize-messages.js +90 -0
- package/dist/lsp/client.js +28 -8
- package/dist/lsp/manager.js +2 -1
- package/dist/lsp/root-path.d.ts +9 -0
- package/dist/lsp/root-path.js +12 -0
- package/dist/onboarding.js +18 -11
- package/dist/plugins/gitOps.d.ts +34 -0
- package/dist/plugins/gitOps.js +59 -3
- package/dist/plugins/installer/codex/convertAgents.d.ts +7 -0
- package/dist/plugins/installer/codex/convertAgents.js +55 -0
- package/dist/plugins/installer/codex/convertMcp.d.ts +8 -0
- package/dist/plugins/installer/codex/convertMcp.js +45 -0
- package/dist/plugins/installer/codex/convertSkills.d.ts +12 -0
- package/dist/plugins/installer/codex/convertSkills.js +33 -0
- package/dist/plugins/installer/detectFormat.d.ts +2 -0
- package/dist/plugins/installer/detectFormat.js +6 -0
- package/dist/plugins/installer/install.d.ts +7 -0
- package/dist/plugins/installer/install.js +99 -0
- package/dist/plugins/installer/installFromSource.d.ts +13 -0
- package/dist/plugins/installer/installFromSource.js +45 -0
- package/dist/plugins/installer/list.d.ts +9 -0
- package/dist/plugins/installer/list.js +30 -0
- package/dist/plugins/installer/loadPluginAgents.d.ts +3 -0
- package/dist/plugins/installer/loadPluginAgents.js +23 -0
- package/dist/plugins/installer/loadPluginMcp.d.ts +7 -0
- package/dist/plugins/installer/loadPluginMcp.js +74 -0
- package/dist/plugins/installer/parseSource.d.ts +20 -0
- package/dist/plugins/installer/parseSource.js +74 -0
- package/dist/plugins/installer/paths.d.ts +5 -0
- package/dist/plugins/installer/paths.js +25 -0
- package/dist/plugins/installer/types.d.ts +49 -0
- package/dist/plugins/installer/types.js +27 -0
- package/dist/plugins/installer/uninstall.d.ts +2 -0
- package/dist/plugins/installer/uninstall.js +14 -0
- package/dist/plugins/installer/update.d.ts +14 -0
- package/dist/plugins/installer/update.js +65 -0
- package/dist/plugins/loadPluginHooks.d.ts +8 -1
- package/dist/plugins/loadPluginHooks.js +11 -1
- package/dist/plugins/marketplaceManager.d.ts +8 -1
- package/dist/plugins/marketplaceManager.js +38 -4
- package/dist/plugins/pluginCommandHook.js +34 -0
- package/dist/plugins/pluginInstaller.d.ts +21 -0
- package/dist/plugins/pluginInstaller.js +128 -29
- package/dist/plugins/schemas.js +40 -6
- package/dist/plugins/types.d.ts +4 -0
- package/dist/preset/index.js +16 -0
- package/dist/prompt/composer.d.ts +10 -0
- package/dist/prompt/composer.js +29 -4
- package/dist/prompt/sections/orchestration.md +8 -0
- package/dist/protocol/chat-session-manager.d.ts +8 -1
- package/dist/protocol/chat-session-manager.js +10 -0
- package/dist/protocol/chat-session.d.ts +17 -0
- package/dist/protocol/chat-session.js +28 -0
- package/dist/protocol/redact.d.ts +50 -0
- package/dist/protocol/redact.js +71 -0
- package/dist/protocol/server.d.ts +41 -2
- package/dist/protocol/server.js +231 -33
- package/dist/protocol/tcp-transport.d.ts +45 -0
- package/dist/protocol/tcp-transport.js +74 -0
- package/dist/protocol/types.d.ts +23 -0
- package/dist/protocol/types.js +6 -0
- package/dist/remote/bridge.d.ts +11 -2
- package/dist/remote/bridge.js +61 -33
- package/dist/run/ArtifactTracker.js +5 -4
- package/dist/run/EngineRunner.d.ts +27 -1
- package/dist/run/EngineRunner.js +46 -8
- package/dist/run/FileRunStore.js +32 -8
- package/dist/run/RunLock.d.ts +28 -2
- package/dist/run/RunLock.js +49 -7
- package/dist/run/RunManager.js +51 -3
- package/dist/run/RunQueue.d.ts +1 -0
- package/dist/run/RunQueue.js +8 -2
- package/dist/run/factory.d.ts +7 -0
- package/dist/run/factory.js +1 -0
- package/dist/run/index.d.ts +2 -2
- package/dist/run/index.js +1 -1
- package/dist/run/redirect-target.d.ts +7 -0
- package/dist/run/redirect-target.js +13 -0
- package/dist/run/types.js +1 -1
- package/dist/services/browser-open.d.ts +13 -0
- package/dist/services/browser-open.js +16 -0
- package/dist/services/dream-consolidation.d.ts +57 -0
- package/dist/services/dream-consolidation.js +151 -0
- package/dist/services/memory-orchestrator.js +18 -0
- package/dist/services/notifier.d.ts +8 -0
- package/dist/services/notifier.js +39 -25
- package/dist/services/oauth.js +5 -7
- package/dist/services/session-memory-sort.d.ts +8 -0
- package/dist/services/session-memory-sort.js +9 -0
- package/dist/services/session-memory.js +8 -9
- package/dist/session/file-history.js +10 -3
- package/dist/session/session-manager.d.ts +23 -1
- package/dist/session/session-manager.js +73 -2
- package/dist/settings/disk-defaults.d.ts +35 -0
- package/dist/settings/disk-defaults.js +24 -0
- package/dist/settings/manager.d.ts +45 -1
- package/dist/settings/manager.js +121 -17
- package/dist/settings/manager.test.d.ts +1 -0
- package/dist/settings/manager.test.js +73 -0
- package/dist/settings/personalization.d.ts +19 -0
- package/dist/settings/personalization.js +7 -0
- package/dist/settings/schema.d.ts +1163 -126
- package/dist/settings/schema.js +126 -10
- package/dist/skills/scanner.d.ts +13 -6
- package/dist/skills/scanner.js +23 -4
- package/dist/tool-system/builtin/add-marketplace.d.ts +12 -0
- package/dist/tool-system/builtin/add-marketplace.js +76 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +15 -0
- package/dist/tool-system/builtin/agent-registry.js +14 -4
- package/dist/tool-system/builtin/agent.d.ts +55 -0
- package/dist/tool-system/builtin/agent.js +165 -17
- package/dist/tool-system/builtin/apply-patch/index.js +22 -3
- package/dist/tool-system/builtin/arena.js +6 -7
- package/dist/tool-system/builtin/complete-goal.d.ts +25 -0
- package/dist/tool-system/builtin/complete-goal.js +45 -0
- package/dist/tool-system/builtin/cron.js +53 -9
- package/dist/tool-system/builtin/edit.d.ts +2 -1
- package/dist/tool-system/builtin/edit.js +6 -1
- package/dist/tool-system/builtin/generate-image.d.ts +25 -0
- package/dist/tool-system/builtin/generate-image.js +146 -0
- package/dist/tool-system/builtin/glob.js +7 -0
- package/dist/tool-system/builtin/grep.js +6 -0
- package/dist/tool-system/builtin/index.d.ts +18 -1
- package/dist/tool-system/builtin/index.js +62 -1
- package/dist/tool-system/builtin/notebook-edit.d.ts +2 -1
- package/dist/tool-system/builtin/notebook-edit.js +8 -1
- package/dist/tool-system/builtin/read.d.ts +2 -1
- package/dist/tool-system/builtin/read.js +9 -1
- package/dist/tool-system/builtin/skill.js +23 -5
- package/dist/tool-system/builtin/sleep.js +9 -3
- package/dist/tool-system/builtin/task.js +4 -1
- package/dist/tool-system/builtin/update-automation-memory.d.ts +24 -0
- package/dist/tool-system/builtin/update-automation-memory.js +60 -0
- package/dist/tool-system/builtin/view-image.d.ts +18 -0
- package/dist/tool-system/builtin/view-image.js +96 -0
- package/dist/tool-system/builtin/web-search.d.ts +4 -1
- package/dist/tool-system/builtin/web-search.js +36 -3
- package/dist/tool-system/builtin/write.d.ts +2 -1
- package/dist/tool-system/builtin/write.js +7 -1
- package/dist/tool-system/context.d.ts +43 -0
- package/dist/tool-system/executor.d.ts +0 -1
- package/dist/tool-system/executor.js +34 -40
- package/dist/tool-system/investigation-guard.d.ts +4 -1
- package/dist/tool-system/investigation-guard.js +19 -3
- package/dist/tool-system/mcp-manager.d.ts +36 -12
- package/dist/tool-system/mcp-manager.js +173 -10
- package/dist/tool-system/path-policy.d.ts +94 -0
- package/dist/tool-system/path-policy.js +279 -0
- package/dist/tool-system/permission.js +43 -50
- package/dist/tool-system/plan-mode-allowlist.d.ts +21 -0
- package/dist/tool-system/plan-mode-allowlist.js +43 -0
- package/dist/tool-system/registry.js +12 -1
- package/dist/tool-system/validation.d.ts +10 -0
- package/dist/tool-system/validation.js +16 -3
- package/dist/types.d.ts +90 -15
- package/dist/utils/format.js +4 -2
- package/dist/utils/lockfile.js +9 -2
- package/dist/utils/theme.d.ts +6 -0
- package/dist/utils/theme.js +4 -2
- package/package.json +2 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive-compaction probe gating.
|
|
3
|
+
*
|
|
4
|
+
* During streaming the turn loop accumulates an estimate of the response
|
|
5
|
+
* size and periodically asks the ContextManager whether we're nearing the
|
|
6
|
+
* context limit. The old gate (`tokens % 2000 === 0`) almost never matched a
|
|
7
|
+
* running `+= ceil(len/4)` accumulator, so the probe never fired. This fires
|
|
8
|
+
* once per 2000-token bucket crossed, tracked by `lastBucket`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function crossedReactiveThreshold(accumulatedTokens: number, lastBucket: number): {
|
|
11
|
+
crossed: boolean;
|
|
12
|
+
bucket: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive-compaction probe gating.
|
|
3
|
+
*
|
|
4
|
+
* During streaming the turn loop accumulates an estimate of the response
|
|
5
|
+
* size and periodically asks the ContextManager whether we're nearing the
|
|
6
|
+
* context limit. The old gate (`tokens % 2000 === 0`) almost never matched a
|
|
7
|
+
* running `+= ceil(len/4)` accumulator, so the probe never fired. This fires
|
|
8
|
+
* once per 2000-token bucket crossed, tracked by `lastBucket`.
|
|
9
|
+
*/
|
|
10
|
+
const REACTIVE_BUCKET = 2000;
|
|
11
|
+
export function crossedReactiveThreshold(accumulatedTokens, lastBucket) {
|
|
12
|
+
const bucket = Math.floor(accumulatedTokens / REACTIVE_BUCKET);
|
|
13
|
+
if (bucket >= 1 && bucket > lastBucket) {
|
|
14
|
+
return { crossed: true, bucket };
|
|
15
|
+
}
|
|
16
|
+
return { crossed: false, bucket: lastBucket };
|
|
17
|
+
}
|
package/dist/engine/runtime.js
CHANGED
|
@@ -35,6 +35,13 @@ export class EngineRuntime {
|
|
|
35
35
|
let cached = this.sandboxCache.get(key);
|
|
36
36
|
if (!cached) {
|
|
37
37
|
cached = resolveSandboxBackend(config, cwd);
|
|
38
|
+
// Don't cache a rejection: an explicit-mode probe that throws (e.g.
|
|
39
|
+
// `seatbelt` on a host without sandbox-exec) must be retryable after the
|
|
40
|
+
// user fixes the config, not sticky until process restart.
|
|
41
|
+
cached.catch(() => {
|
|
42
|
+
if (this.sandboxCache.get(key) === cached)
|
|
43
|
+
this.sandboxCache.delete(key);
|
|
44
|
+
});
|
|
38
45
|
this.sandboxCache.set(key, cached);
|
|
39
46
|
}
|
|
40
47
|
return cached;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session title generation — best-effort, one-line LLM title for the sidebar.
|
|
3
|
+
*
|
|
4
|
+
* Pure function (no Engine `this`) so it's trivially unit-testable. The Engine
|
|
5
|
+
* resolves the aux client and wiring; this only does the LLM call + cleanup.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMClientBase } from "../llm/client-base.js";
|
|
8
|
+
/**
|
|
9
|
+
* Ask the aux client for a one-line title from the first user message + first
|
|
10
|
+
* assistant reply. Returns the cleaned title, or null on any failure / empty
|
|
11
|
+
* output (caller treats null as "keep existing title").
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildSessionTitle(client: LLMClientBase, firstUserText: string, firstAssistantText: string): Promise<string | null>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const SYSTEM_PROMPT = "You generate a very short title (≤6 words, no quotes, no trailing punctuation) " +
|
|
2
|
+
"summarizing a chat, in the same language as the user's message.";
|
|
3
|
+
/** Strip wrapping quotes/whitespace the model sometimes adds. */
|
|
4
|
+
function clean(raw) {
|
|
5
|
+
return raw
|
|
6
|
+
.trim()
|
|
7
|
+
.replace(/^["'“”‘’「『]+/, "")
|
|
8
|
+
.replace(/["'“”‘’」』]+$/, "")
|
|
9
|
+
.trim();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ask the aux client for a one-line title from the first user message + first
|
|
13
|
+
* assistant reply. Returns the cleaned title, or null on any failure / empty
|
|
14
|
+
* output (caller treats null as "keep existing title").
|
|
15
|
+
*/
|
|
16
|
+
export async function buildSessionTitle(client, firstUserText, firstAssistantText) {
|
|
17
|
+
try {
|
|
18
|
+
const prompt = `User: ${firstUserText.slice(0, 2000)}\n\n` +
|
|
19
|
+
`Assistant: ${firstAssistantText.slice(0, 2000)}\n\n` +
|
|
20
|
+
`Title:`;
|
|
21
|
+
const resp = await client.createMessage({
|
|
22
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
23
|
+
messages: [{ role: "user", content: prompt }],
|
|
24
|
+
tools: [],
|
|
25
|
+
maxTokens: 64,
|
|
26
|
+
reasoning: { mode: "off" },
|
|
27
|
+
});
|
|
28
|
+
const title = clean(resp.text ?? "");
|
|
29
|
+
return title.length > 0 ? title : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* Following Claude Code's po_() pattern:
|
|
5
5
|
* pre_check → model_call → post_check → tool_exec → context_mgmt → hook_notify → next turn
|
|
6
6
|
*/
|
|
7
|
-
import type { Message, StreamCallback, TerminalReason } from "../types.js";
|
|
7
|
+
import type { Message, StreamCallback, TerminalReason, ContentBlock, ToolResult } from "../types.js";
|
|
8
8
|
import { ModelFacade } from "./model-facade.js";
|
|
9
9
|
import { ToolExecutor } from "../tool-system/executor.js";
|
|
10
10
|
import { ContextManager } from "../context/manager.js";
|
|
11
11
|
import { HookRegistry } from "../hooks/registry.js";
|
|
12
12
|
import { Transcript } from "../session/transcript.js";
|
|
13
|
+
import { type GoalConfig } from "./goal.js";
|
|
13
14
|
export interface TurnLoopConfig {
|
|
14
15
|
maxTurns: number;
|
|
15
16
|
maxToolCallsPerTurn: number;
|
|
@@ -22,6 +23,21 @@ export interface TurnLoopConfig {
|
|
|
22
23
|
* the on-disk turnCount/status frozen at the last completion.
|
|
23
24
|
*/
|
|
24
25
|
onTurnBoundary?: (turnCount: number) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Goal mode: the normalized GoalConfig (objective + optional token/time
|
|
28
|
+
* budgets), passed to on_stop handlers via ctx.data.goal so the
|
|
29
|
+
* GoalStopHook can judge completion. The run-scoped budget tracker reads
|
|
30
|
+
* the budgets to force-stop an unattended run. Undefined when no goal is
|
|
31
|
+
* set (on_stop still fires but built-in Goal handler is a no-op without it).
|
|
32
|
+
*/
|
|
33
|
+
goal?: GoalConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Max consecutive times an on_stop handler may block termination before
|
|
36
|
+
* the loop forces a stop, mirroring Claude Code's stop-hook block cap.
|
|
37
|
+
* Resets to 0 whenever a turn completes without being blocked. Defaults
|
|
38
|
+
* to 8. Independent of maxTurns, which still bounds total turns.
|
|
39
|
+
*/
|
|
40
|
+
maxStopBlocks?: number;
|
|
25
41
|
}
|
|
26
42
|
export interface CtxOverheadStore {
|
|
27
43
|
/** Tokens for system prompt + tool defs, derived from provider's promptTokens. */
|
|
@@ -64,6 +80,12 @@ export interface TurnLoopResult {
|
|
|
64
80
|
reason: TerminalReason;
|
|
65
81
|
messages: Message[];
|
|
66
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* 把一个 ToolResult 映射成发给 LLM 的 tool_result ContentBlock。
|
|
85
|
+
* 有 contentBlocks(view_image 的图片块)就原样用作 content;否则
|
|
86
|
+
* 用文本(成功用 result,失败用 "Error: ...")。抽成纯函数以便单测。
|
|
87
|
+
*/
|
|
88
|
+
export declare function toolResultToBlock(result: ToolResult): ContentBlock;
|
|
67
89
|
export declare class TurnLoop {
|
|
68
90
|
private readonly deps;
|
|
69
91
|
private readonly config;
|
|
@@ -79,6 +101,12 @@ export declare class TurnLoop {
|
|
|
79
101
|
private currentTurnLog;
|
|
80
102
|
/** Last emitted ctx token estimate; used to skip no-op usage_update events. */
|
|
81
103
|
private lastCtxEmit;
|
|
104
|
+
/**
|
|
105
|
+
* Consecutive on_stop blocks (Goal mode kept the agent going). Reset to 0
|
|
106
|
+
* on any unblocked completion. When it reaches config.maxStopBlocks the
|
|
107
|
+
* loop forces a stop so a stuck goal can't loop forever.
|
|
108
|
+
*/
|
|
109
|
+
private stopBlockCount;
|
|
82
110
|
constructor(deps: TurnLoopDeps, config: TurnLoopConfig);
|
|
83
111
|
/**
|
|
84
112
|
* Emit a lifecycle hook with isSubAgent + sessionId auto-merged into data.
|
|
@@ -105,13 +133,6 @@ export declare class TurnLoop {
|
|
|
105
133
|
* If streaming fails, emit tombstone and retry non-streaming.
|
|
106
134
|
*/
|
|
107
135
|
private callModelWithFallback;
|
|
108
|
-
/**
|
|
109
|
-
* Execute tools with overlap: start concurrent-safe (read-only) tools
|
|
110
|
-
* immediately in parallel while sequential (write) tools run one-by-one.
|
|
111
|
-
* Both groups run simultaneously — we don't wait for safe tools to finish
|
|
112
|
-
* before starting unsafe ones.
|
|
113
|
-
*/
|
|
114
|
-
private executeToolsOverlapped;
|
|
115
136
|
get currentTurn(): number;
|
|
116
137
|
/**
|
|
117
138
|
* Generate synthetic error tool_results for any dangling tool_use blocks
|