@chengchenccc/oh-my-agent 0.1.1-rc.1
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 +79 -0
- package/dist/cli/args.d.ts +24 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +120 -0
- package/dist/cli/initial-input.d.ts +32 -0
- package/dist/cli/initial-input.d.ts.map +1 -0
- package/dist/cli/initial-input.js +131 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/core/__fixtures__/echo-model.d.ts +6 -0
- package/dist/core/__fixtures__/echo-model.d.ts.map +1 -0
- package/dist/core/__fixtures__/echo-model.js +10 -0
- package/dist/core/__fixtures__/mcp-echo-server.d.ts +2 -0
- package/dist/core/__fixtures__/mcp-echo-server.d.ts.map +1 -0
- package/dist/core/__fixtures__/mcp-echo-server.js +54 -0
- package/dist/core/agent-runtime.d.ts +21 -0
- package/dist/core/agent-runtime.d.ts.map +1 -0
- package/dist/core/agent-runtime.js +14 -0
- package/dist/core/memory/autonomous-memory.d.ts +21 -0
- package/dist/core/memory/autonomous-memory.d.ts.map +1 -0
- package/dist/core/memory/autonomous-memory.js +202 -0
- package/dist/core/persistence/in-memory-session-store.d.ts +3 -0
- package/dist/core/persistence/in-memory-session-store.d.ts.map +1 -0
- package/dist/core/persistence/in-memory-session-store.js +109 -0
- package/dist/core/persistence/session-store.contract.d.ts +5 -0
- package/dist/core/persistence/session-store.contract.d.ts.map +1 -0
- package/dist/core/persistence/session-store.contract.js +183 -0
- package/dist/core/persistence/session-store.d.ts +33 -0
- package/dist/core/persistence/session-store.d.ts.map +1 -0
- package/dist/core/persistence/session-store.js +22 -0
- package/dist/core/persistence/session-tree.d.ts +49 -0
- package/dist/core/persistence/session-tree.d.ts.map +1 -0
- package/dist/core/persistence/session-tree.js +1 -0
- package/dist/core/plugins/plugin-code.d.ts +13 -0
- package/dist/core/plugins/plugin-code.d.ts.map +1 -0
- package/dist/core/plugins/plugin-code.js +62 -0
- package/dist/core/plugins/plugin-marketplace.d.ts +72 -0
- package/dist/core/plugins/plugin-marketplace.d.ts.map +1 -0
- package/dist/core/plugins/plugin-marketplace.js +340 -0
- package/dist/core/plugins/plugin-resolve.d.ts +32 -0
- package/dist/core/plugins/plugin-resolve.d.ts.map +1 -0
- package/dist/core/plugins/plugin-resolve.js +101 -0
- package/dist/core/plugins/plugin-trust.d.ts +24 -0
- package/dist/core/plugins/plugin-trust.d.ts.map +1 -0
- package/dist/core/plugins/plugin-trust.js +89 -0
- package/dist/core/runtime/agent-event.d.ts +98 -0
- package/dist/core/runtime/agent-event.d.ts.map +1 -0
- package/dist/core/runtime/agent-event.js +1 -0
- package/dist/core/runtime/agent-loop.d.ts +142 -0
- package/dist/core/runtime/agent-loop.d.ts.map +1 -0
- package/dist/core/runtime/agent-loop.js +1008 -0
- package/dist/core/runtime/approval.d.ts +23 -0
- package/dist/core/runtime/approval.d.ts.map +1 -0
- package/dist/core/runtime/approval.js +25 -0
- package/dist/core/runtime/compaction.d.ts +22 -0
- package/dist/core/runtime/compaction.d.ts.map +1 -0
- package/dist/core/runtime/compaction.js +90 -0
- package/dist/core/runtime/context-estimate.d.ts +42 -0
- package/dist/core/runtime/context-estimate.d.ts.map +1 -0
- package/dist/core/runtime/context-estimate.js +34 -0
- package/dist/core/runtime/create-runtime.d.ts +81 -0
- package/dist/core/runtime/create-runtime.d.ts.map +1 -0
- package/dist/core/runtime/create-runtime.js +250 -0
- package/dist/core/runtime/fake-provider.d.ts +3 -0
- package/dist/core/runtime/fake-provider.d.ts.map +1 -0
- package/dist/core/runtime/fake-provider.js +87 -0
- package/dist/core/runtime/logger.d.ts +13 -0
- package/dist/core/runtime/logger.d.ts.map +1 -0
- package/dist/core/runtime/logger.js +38 -0
- package/dist/core/runtime/loop-input.d.ts +39 -0
- package/dist/core/runtime/loop-input.d.ts.map +1 -0
- package/dist/core/runtime/loop-input.js +38 -0
- package/dist/core/runtime/message-cache.d.ts +16 -0
- package/dist/core/runtime/message-cache.d.ts.map +1 -0
- package/dist/core/runtime/message-cache.js +23 -0
- package/dist/core/runtime/model-catalog.d.ts +10 -0
- package/dist/core/runtime/model-catalog.d.ts.map +1 -0
- package/dist/core/runtime/model-catalog.js +14 -0
- package/dist/core/runtime/plugin-runtime.d.ts +41 -0
- package/dist/core/runtime/plugin-runtime.d.ts.map +1 -0
- package/dist/core/runtime/plugin-runtime.js +1 -0
- package/dist/core/runtime/plugin.d.ts +86 -0
- package/dist/core/runtime/plugin.d.ts.map +1 -0
- package/dist/core/runtime/plugin.js +23 -0
- package/dist/core/runtime/process-tree.d.ts +12 -0
- package/dist/core/runtime/process-tree.d.ts.map +1 -0
- package/dist/core/runtime/process-tree.js +40 -0
- package/dist/core/runtime/prompt.d.ts +23 -0
- package/dist/core/runtime/prompt.d.ts.map +1 -0
- package/dist/core/runtime/prompt.js +29 -0
- package/dist/core/runtime/prompts.d.ts +16 -0
- package/dist/core/runtime/prompts.d.ts.map +1 -0
- package/dist/core/runtime/prompts.js +36 -0
- package/dist/core/runtime/retry.d.ts +20 -0
- package/dist/core/runtime/retry.d.ts.map +1 -0
- package/dist/core/runtime/retry.js +60 -0
- package/dist/core/runtime/run-runtime.d.ts +93 -0
- package/dist/core/runtime/run-runtime.d.ts.map +1 -0
- package/dist/core/runtime/run-runtime.js +664 -0
- package/dist/core/runtime/runtime-catalog.d.ts +12 -0
- package/dist/core/runtime/runtime-catalog.d.ts.map +1 -0
- package/dist/core/runtime/runtime-catalog.js +89 -0
- package/dist/core/runtime/stream-rules.d.ts +9 -0
- package/dist/core/runtime/stream-rules.d.ts.map +1 -0
- package/dist/core/runtime/stream-rules.js +44 -0
- package/dist/core/runtime/title.d.ts +7 -0
- package/dist/core/runtime/title.d.ts.map +1 -0
- package/dist/core/runtime/title.js +114 -0
- package/dist/core/runtime/todo.d.ts +16 -0
- package/dist/core/runtime/todo.d.ts.map +1 -0
- package/dist/core/runtime/todo.js +40 -0
- package/dist/core/runtime/tool-filter.d.ts +12 -0
- package/dist/core/runtime/tool-filter.d.ts.map +1 -0
- package/dist/core/runtime/tool-filter.js +23 -0
- package/dist/core/runtime/tool-pruning.d.ts +29 -0
- package/dist/core/runtime/tool-pruning.d.ts.map +1 -0
- package/dist/core/runtime/tool-pruning.js +105 -0
- package/dist/core/session/input-history.d.ts +8 -0
- package/dist/core/session/input-history.d.ts.map +1 -0
- package/dist/core/session/input-history.js +41 -0
- package/dist/core/session/session-file.d.ts +84 -0
- package/dist/core/session/session-file.d.ts.map +1 -0
- package/dist/core/session/session-file.js +392 -0
- package/dist/core/session/session-loop.d.ts +33 -0
- package/dist/core/session/session-loop.d.ts.map +1 -0
- package/dist/core/session/session-loop.js +30 -0
- package/dist/core/settings/project-settings.d.ts +46 -0
- package/dist/core/settings/project-settings.d.ts.map +1 -0
- package/dist/core/settings/project-settings.js +85 -0
- package/dist/core/settings/workspace-context.d.ts +10 -0
- package/dist/core/settings/workspace-context.d.ts.map +1 -0
- package/dist/core/settings/workspace-context.js +48 -0
- package/dist/core/tools/agent-fs-like.d.ts +15 -0
- package/dist/core/tools/agent-fs-like.d.ts.map +1 -0
- package/dist/core/tools/agent-fs-like.js +4 -0
- package/dist/core/tools/ask-question.d.ts +5 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +51 -0
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +109 -0
- package/dist/core/tools/eval.d.ts +10 -0
- package/dist/core/tools/eval.d.ts.map +1 -0
- package/dist/core/tools/eval.js +83 -0
- package/dist/core/tools/file-tools.d.ts +18 -0
- package/dist/core/tools/file-tools.d.ts.map +1 -0
- package/dist/core/tools/file-tools.js +249 -0
- package/dist/core/tools/glob.d.ts +5 -0
- package/dist/core/tools/glob.d.ts.map +1 -0
- package/dist/core/tools/glob.js +54 -0
- package/dist/core/tools/grep.d.ts +5 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +61 -0
- package/dist/core/tools/index.d.ts +14 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +14 -0
- package/dist/core/tools/ls-tree.d.ts +10 -0
- package/dist/core/tools/ls-tree.d.ts.map +1 -0
- package/dist/core/tools/ls-tree.js +177 -0
- package/dist/core/tools/mcp-mount.d.ts +63 -0
- package/dist/core/tools/mcp-mount.d.ts.map +1 -0
- package/dist/core/tools/mcp-mount.js +287 -0
- package/dist/core/tools/read-image.d.ts +6 -0
- package/dist/core/tools/read-image.d.ts.map +1 -0
- package/dist/core/tools/read-image.js +98 -0
- package/dist/core/tools/skill.d.ts +11 -0
- package/dist/core/tools/skill.d.ts.map +1 -0
- package/dist/core/tools/skill.js +65 -0
- package/dist/core/tools/skills.d.ts +10 -0
- package/dist/core/tools/skills.d.ts.map +1 -0
- package/dist/core/tools/skills.js +116 -0
- package/dist/core/tools/todo-store.d.ts +8 -0
- package/dist/core/tools/todo-store.d.ts.map +1 -0
- package/dist/core/tools/todo-store.js +100 -0
- package/dist/core/tools/todo.d.ts +8 -0
- package/dist/core/tools/todo.d.ts.map +1 -0
- package/dist/core/tools/todo.js +91 -0
- package/dist/core/tools/url-guard.d.ts +12 -0
- package/dist/core/tools/url-guard.d.ts.map +1 -0
- package/dist/core/tools/url-guard.js +58 -0
- package/dist/core/tools/web-ports-std.d.ts +6 -0
- package/dist/core/tools/web-ports-std.d.ts.map +1 -0
- package/dist/core/tools/web-ports-std.js +145 -0
- package/dist/core/tools/web-ports.d.ts +56 -0
- package/dist/core/tools/web-ports.d.ts.map +1 -0
- package/dist/core/tools/web-ports.js +62 -0
- package/dist/core/tools/workspace-sandbox.d.ts +20 -0
- package/dist/core/tools/workspace-sandbox.d.ts.map +1 -0
- package/dist/core/tools/workspace-sandbox.js +84 -0
- package/dist/core/workflow/subagent-registry.d.ts +40 -0
- package/dist/core/workflow/subagent-registry.d.ts.map +1 -0
- package/dist/core/workflow/subagent-registry.js +118 -0
- package/dist/core/workflow/workflow-evaluator.d.ts +23 -0
- package/dist/core/workflow/workflow-evaluator.d.ts.map +1 -0
- package/dist/core/workflow/workflow-evaluator.js +21 -0
- package/dist/core/workflow/workflow-executor.d.ts +108 -0
- package/dist/core/workflow/workflow-executor.d.ts.map +1 -0
- package/dist/core/workflow/workflow-executor.js +549 -0
- package/dist/core/workflow/workflow-tools.d.ts +50 -0
- package/dist/core/workflow/workflow-tools.d.ts.map +1 -0
- package/dist/core/workflow/workflow-tools.js +217 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/main.d.ts +9 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +97 -0
- package/dist/modes/json-mode.d.ts +5 -0
- package/dist/modes/json-mode.d.ts.map +1 -0
- package/dist/modes/json-mode.js +46 -0
- package/dist/modes/print-mode.d.ts +20 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +82 -0
- package/dist/modes/rpc/jsonl.d.ts +23 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +88 -0
- package/dist/modes/rpc/rpc-mode.d.ts +18 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +326 -0
- package/dist/modes/tui/settings-overlay.d.ts +23 -0
- package/dist/modes/tui/settings-overlay.d.ts.map +1 -0
- package/dist/modes/tui/settings-overlay.js +136 -0
- package/dist/modes/tui/tui-commands-session.d.ts +3 -0
- package/dist/modes/tui/tui-commands-session.d.ts.map +1 -0
- package/dist/modes/tui/tui-commands-session.js +191 -0
- package/dist/modes/tui/tui-commands.d.ts +52 -0
- package/dist/modes/tui/tui-commands.d.ts.map +1 -0
- package/dist/modes/tui/tui-commands.js +373 -0
- package/dist/modes/tui/tui-components.d.ts +81 -0
- package/dist/modes/tui/tui-components.d.ts.map +1 -0
- package/dist/modes/tui/tui-components.js +248 -0
- package/dist/modes/tui/tui-format.d.ts +65 -0
- package/dist/modes/tui/tui-format.d.ts.map +1 -0
- package/dist/modes/tui/tui-format.js +246 -0
- package/dist/modes/tui/tui-frame-provider.d.ts +16 -0
- package/dist/modes/tui/tui-frame-provider.d.ts.map +1 -0
- package/dist/modes/tui/tui-frame-provider.js +31 -0
- package/dist/modes/tui/tui-interactive.d.ts +16 -0
- package/dist/modes/tui/tui-interactive.d.ts.map +1 -0
- package/dist/modes/tui/tui-interactive.js +123 -0
- package/dist/modes/tui/tui-io.d.ts +12 -0
- package/dist/modes/tui/tui-io.d.ts.map +1 -0
- package/dist/modes/tui/tui-io.js +620 -0
- package/dist/modes/tui/tui-mode.d.ts +120 -0
- package/dist/modes/tui/tui-mode.d.ts.map +1 -0
- package/dist/modes/tui/tui-mode.js +391 -0
- package/dist/modes/tui/tui-render.d.ts +54 -0
- package/dist/modes/tui/tui-render.d.ts.map +1 -0
- package/dist/modes/tui/tui-render.js +399 -0
- package/dist/modes/tui/tui-slash.d.ts +12 -0
- package/dist/modes/tui/tui-slash.d.ts.map +1 -0
- package/dist/modes/tui/tui-slash.js +64 -0
- package/dist/modes/tui/tui-tool-render.d.ts +6 -0
- package/dist/modes/tui/tui-tool-render.d.ts.map +1 -0
- package/dist/modes/tui/tui-tool-render.js +79 -0
- package/dist/modes/tui/tui-transcript-reconciler.d.ts +25 -0
- package/dist/modes/tui/tui-transcript-reconciler.d.ts.map +1 -0
- package/dist/modes/tui/tui-transcript-reconciler.js +97 -0
- package/dist/modes/tui/view-state.d.ts +67 -0
- package/dist/modes/tui/view-state.d.ts.map +1 -0
- package/dist/modes/tui/view-state.js +353 -0
- package/dist/prompts/agents/subagent.md +26 -0
- package/dist/prompts/system/base.md +20 -0
- package/dist/prompts/system/memory.md +23 -0
- package/dist/prompts/system/safety.md +12 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/mapping.d.ts +25 -0
- package/dist/protocol/mapping.d.ts.map +1 -0
- package/dist/protocol/mapping.js +115 -0
- package/dist/protocol/transport.d.ts +1396 -0
- package/dist/protocol/transport.d.ts.map +1 -0
- package/dist/protocol/transport.js +170 -0
- package/package.json +49 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import basePrompt from "../../prompts/system/base.md" with { type: "text" };
|
|
4
|
+
import memoryPrompt from "../../prompts/system/memory.md" with { type: "text" };
|
|
5
|
+
import safetyPrompt from "../../prompts/system/safety.md" with { type: "text" };
|
|
6
|
+
/** oma's own prompt layer (mirrors omp's src/prompts layout): base
|
|
7
|
+
* identity + safety + memory discipline live here as md files; workspace
|
|
8
|
+
* files (AGENTS.md / SOUL.md / USER.md + knowledge index) remain the
|
|
9
|
+
* agent-specific layer and are appended when present. Explicit
|
|
10
|
+
* run-input systemPrompt (Loop scopes) still wins wholesale — callers
|
|
11
|
+
* bypass this builder. */
|
|
12
|
+
export function buildSystemPrompt(input) {
|
|
13
|
+
const now = new Date();
|
|
14
|
+
const date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
15
|
+
const parts = [basePrompt.trim(), safetyPrompt.trim()];
|
|
16
|
+
const memoryBlock = input.memorySummary?.trim()
|
|
17
|
+
? `${memoryPrompt.trim()}\n\n<memory_summary>\n${input.memorySummary.trim()}\n</memory_summary>`
|
|
18
|
+
: memoryPrompt.trim();
|
|
19
|
+
parts.push(memoryBlock);
|
|
20
|
+
if (input.workspacePrompt?.trim()) {
|
|
21
|
+
parts.push(`<workspace_context>\n${input.workspacePrompt.trim()}\n</workspace_context>`);
|
|
22
|
+
}
|
|
23
|
+
parts.push(`Current date: ${date}`, `Current working directory: ${input.cwd}`);
|
|
24
|
+
return parts.join("\n\n");
|
|
25
|
+
}
|
|
26
|
+
/** Workspace memory summary for prompt injection (absent when the agent
|
|
27
|
+
* has never written memories). */
|
|
28
|
+
export function readMemorySummary(cwd) {
|
|
29
|
+
try {
|
|
30
|
+
const text = readFileSync(join(cwd, ".oma", "memory", "memory_summary.md"), "utf-8");
|
|
31
|
+
return text.trim() || undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AIMessageChunk } from "@chengchenccc/message";
|
|
2
|
+
export interface RetryOptions {
|
|
3
|
+
readonly maxAttempts: number;
|
|
4
|
+
readonly baseDelayMs: number;
|
|
5
|
+
/** Lifecycle callbacks so the loop can emit retry_start/retry_end. */
|
|
6
|
+
readonly onRetryStart?: (attempt: number) => void | Promise<void>;
|
|
7
|
+
readonly onRetryEnd?: (attempt: number) => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/** Wrap a model stream with provider-only retry. Only normalized transient
|
|
10
|
+
* errors from ProviderError are retried. Tool/business/overflow/auth errors
|
|
11
|
+
* pass through immediately. The same input messages are reused (no duplicate
|
|
12
|
+
* Meta/Prompt/history in the tree).
|
|
13
|
+
*
|
|
14
|
+
* Streaming is real-time: chunks are forwarded immediately, not buffered.
|
|
15
|
+
* Retry is only permitted when the attempt has produced ZERO output (a
|
|
16
|
+
* transient connection error before the first token). Once the first chunk
|
|
17
|
+
* is emitted the attempt is committed — a later failure makes the Run fail,
|
|
18
|
+
* never produces a partial "AAB" contamination. */
|
|
19
|
+
export declare function retryStream(streamFactory: (signal?: AbortSignal) => AsyncIterable<AIMessageChunk>, opts: RetryOptions, signal?: AbortSignal): AsyncIterable<AIMessageChunk>;
|
|
20
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,sEAAsE;IACtE,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED;;;;;;;;;oDASoD;AACpD,wBAAuB,WAAW,CAChC,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,aAAa,CAAC,cAAc,CAAC,EACtE,IAAI,EAAE,YAAY,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,aAAa,CAAC,cAAc,CAAC,CAgD/B"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProviderError } from "@chengchenccc/ai";
|
|
2
|
+
/** Wrap a model stream with provider-only retry. Only normalized transient
|
|
3
|
+
* errors from ProviderError are retried. Tool/business/overflow/auth errors
|
|
4
|
+
* pass through immediately. The same input messages are reused (no duplicate
|
|
5
|
+
* Meta/Prompt/history in the tree).
|
|
6
|
+
*
|
|
7
|
+
* Streaming is real-time: chunks are forwarded immediately, not buffered.
|
|
8
|
+
* Retry is only permitted when the attempt has produced ZERO output (a
|
|
9
|
+
* transient connection error before the first token). Once the first chunk
|
|
10
|
+
* is emitted the attempt is committed — a later failure makes the Run fail,
|
|
11
|
+
* never produces a partial "AAB" contamination. */
|
|
12
|
+
export async function* retryStream(streamFactory, opts, signal) {
|
|
13
|
+
let attempt = 0;
|
|
14
|
+
let lastError;
|
|
15
|
+
while (attempt < opts.maxAttempts) {
|
|
16
|
+
if (signal?.aborted)
|
|
17
|
+
throw new Error("Aborted");
|
|
18
|
+
attempt++;
|
|
19
|
+
let committed = false; // becomes true on the first forwarded chunk
|
|
20
|
+
try {
|
|
21
|
+
for await (const chunk of streamFactory(signal)) {
|
|
22
|
+
committed = true;
|
|
23
|
+
yield chunk;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
lastError = err;
|
|
28
|
+
await opts.onRetryEnd?.(attempt);
|
|
29
|
+
// Only retry if the attempt produced zero output AND the error is
|
|
30
|
+
// a retryable transient provider error. A committed attempt that
|
|
31
|
+
// fails mid-stream cannot be retried (partial output already emitted).
|
|
32
|
+
const canRetry = !committed && err instanceof ProviderError && err.retryable && attempt < opts.maxAttempts;
|
|
33
|
+
if (canRetry) {
|
|
34
|
+
// The retry callback fires only for an actual retry - attempt 1 is
|
|
35
|
+
// the normal path and must not surface as a retry status.
|
|
36
|
+
await opts.onRetryStart?.(attempt + 1);
|
|
37
|
+
// Server-requested delay (Retry-After header) takes precedence over
|
|
38
|
+
// backoff capped at 60s when the server doesn't suggest a delay.
|
|
39
|
+
const serverDelay = err.retryAfterMs;
|
|
40
|
+
const backoff = opts.baseDelayMs * 2 ** (attempt - 1);
|
|
41
|
+
const cappedBackoff = Math.min(backoff, 60_000);
|
|
42
|
+
const delay = serverDelay !== undefined ? Math.min(serverDelay, 60_000) : Math.random() * cappedBackoff;
|
|
43
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
44
|
+
const timer = setTimeout(resolve, delay);
|
|
45
|
+
const onAbort = () => resolve();
|
|
46
|
+
if (signal?.aborted)
|
|
47
|
+
resolve();
|
|
48
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
49
|
+
await promise;
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
signal?.removeEventListener("abort", onAbort);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
await opts.onRetryEnd?.(attempt);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw lastError;
|
|
60
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type AgentRunSnapshot, type ProjectedHistoryItem } from "@chengchenccc/agent-contract";
|
|
2
|
+
import { type ModelRuntime } from "@chengchenccc/ai";
|
|
3
|
+
import type { Message } from "@chengchenccc/message";
|
|
4
|
+
import { type ContextBudget, type ContextSummarizer, type OmaSession, type Plugin, type PluginTool, type SessionStore } from "../agent-runtime.js";
|
|
5
|
+
import type { PluginMcpConfig } from "../plugins/plugin-resolve.js";
|
|
6
|
+
import { type WebFetchPort, type WebSearchPort } from "../tools/index.js";
|
|
7
|
+
import { type ApprovalHandler } from "./approval.js";
|
|
8
|
+
import { type ToolFilter } from "./tool-filter.js";
|
|
9
|
+
/** Dependencies for ONE Run's runtime assembly. The runtime is per-Run: a
|
|
10
|
+
|
|
11
|
+
/** Dependencies for ONE Run's runtime assembly. The runtime is per-Run: a
|
|
12
|
+
* fresh in-memory SessionStore and a fresh OmaSession are created
|
|
13
|
+
* for every execute() - no state is shared across Runs except the
|
|
14
|
+
* process-level Provider/ModelRuntime. */
|
|
15
|
+
export interface RunRuntimeDeps {
|
|
16
|
+
workspaceRoot: string;
|
|
17
|
+
/** Gates tool installation: read_only runs omit write/edit/bash. */
|
|
18
|
+
workspaceAccess: "read_only" | "read_write";
|
|
19
|
+
runId: string;
|
|
20
|
+
modelRuntime: ModelRuntime;
|
|
21
|
+
/** Canonical `<provider>/<model>` id of the Run's model. The context
|
|
22
|
+
* budget and the summarizer bind to THIS model - never the catalog's
|
|
23
|
+
* first entry (which may be a different window or a different provider). */
|
|
24
|
+
modelId: string;
|
|
25
|
+
/** Skill pack roots (absolute dirs scanned for SKILL.md). Frozen per Run. */
|
|
26
|
+
skillRoots: readonly string[];
|
|
27
|
+
webSearch?: WebSearchPort;
|
|
28
|
+
webFetch?: WebFetchPort;
|
|
29
|
+
/** Real-time session-file persistence (pi appendMessage): fires after
|
|
30
|
+
* every conversational persist with the canonical messages written. */
|
|
31
|
+
onPersistMessages?: (messages: readonly Message[]) => void;
|
|
32
|
+
/** Loaded plugin code components (mode layer already applied the trust
|
|
33
|
+
* policy); the runtime only mounts them. */
|
|
34
|
+
codePlugins?: readonly Plugin[];
|
|
35
|
+
/** Plugin .mcp.json configs (already trust-approved by the mode layer). */
|
|
36
|
+
pluginMcpServers?: readonly PluginMcpConfig[];
|
|
37
|
+
/** Frozen Run permissionMode (ADR 0020 decision 7). "deny" drops plugin
|
|
38
|
+
* code components at assembly; native tools are unaffected (MVP scope). */
|
|
39
|
+
permissionMode?: "ask" | "auto" | "deny";
|
|
40
|
+
/** --tools filter (CLI): applied to the final tool table (native + MCP +
|
|
41
|
+
* plugin) at assembly. Undefined = all tools. */
|
|
42
|
+
toolFilter?: ToolFilter;
|
|
43
|
+
/** Standalone modes (tui/print/json): the workspace's own .mcp.json is
|
|
44
|
+
* repo-controlled, so mount it only when content-trusted (record in
|
|
45
|
+
* <agentDir>/trusted-plugins.json; /mcp trust records it). Backend RPC
|
|
46
|
+
* leaves this unset — the workspace bridge writes that file and the
|
|
47
|
+
* product owns it. */
|
|
48
|
+
gateWorkspaceMcp?: boolean;
|
|
49
|
+
/** HITL approval pipeline (spec): resolves the ask-mode gate and
|
|
50
|
+
* tools' options.request. Absent + ask = fail-closed error results. */
|
|
51
|
+
approvalHandler?: ApprovalHandler;
|
|
52
|
+
}
|
|
53
|
+
export interface RunRuntime {
|
|
54
|
+
readonly runId: string;
|
|
55
|
+
readonly store: SessionStore;
|
|
56
|
+
readonly session: OmaSession;
|
|
57
|
+
readonly summarize: ContextSummarizer;
|
|
58
|
+
readonly contextBudget: ContextBudget | undefined;
|
|
59
|
+
/** Set before startLoop so modelStream resolves the run's model. */
|
|
60
|
+
setActiveRun(run: AgentRunSnapshot<"oma"> | null): void;
|
|
61
|
+
/** Workflow mode: execute a vm-sandboxed script (agent() subagents) and
|
|
62
|
+
* return its value. Used directly by create-runtime when the Run input
|
|
63
|
+
* carries `workflow`, and by the workflow_run tool otherwise. */
|
|
64
|
+
executeWorkflow(input: {
|
|
65
|
+
script: string;
|
|
66
|
+
args?: unknown;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
ok: boolean;
|
|
69
|
+
totalTokens: number;
|
|
70
|
+
value: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
/** Subagent usage accumulated across workflow_agent_completed events
|
|
73
|
+
* (T5/B6: the run's outcome merges it so fan-out spend reaches the
|
|
74
|
+
* product ledger, not just the advisory gate). */
|
|
75
|
+
workflowUsage(): {
|
|
76
|
+
inputTokens: number;
|
|
77
|
+
outputTokens: number;
|
|
78
|
+
cacheReadTokens: number;
|
|
79
|
+
cacheWriteTokens: number;
|
|
80
|
+
};
|
|
81
|
+
/** Close MCP clients etc. Call after the run settles. */
|
|
82
|
+
close(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/** Single provider assembly shared by the CLI catalog (--list-models) and
|
|
85
|
+
* Run loops: register built-in providers from the process env. The fake
|
|
86
|
+
* deterministic provider is available for tests. */
|
|
87
|
+
export declare function registerBuiltinProviders(runtime: ModelRuntime, env?: Readonly<Record<string, string | undefined>>): void;
|
|
88
|
+
/** Build the complete Runtime assembly for exactly ONE Run. The Run's
|
|
89
|
+
* in-memory SessionStore is created here (never shared with other Runs);
|
|
90
|
+
* the model is resolved per run from the AgentRunSnapshot. */
|
|
91
|
+
export declare function assembleRunRuntime(deps: RunRuntimeDeps): Promise<RunRuntime>;
|
|
92
|
+
export type { AgentRunSnapshot, PluginTool, ProjectedHistoryItem };
|
|
93
|
+
//# sourceMappingURL=run-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-runtime.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/run-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,YAAY,EAAqB,MAAM,kBAA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