@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,87 @@
|
|
|
1
|
+
/** Deterministic fake Provider for child-process integration tests. Yields one text
|
|
2
|
+
* chunk then a natural stop - no network, no credentials. Registered by the
|
|
3
|
+
* Worker when OMA_FAKE_PROVIDER=1 is in its env.
|
|
4
|
+
*
|
|
5
|
+
* Scripted tool calls: when OMA_FAKE_TOOL is set to a JSON array of
|
|
6
|
+
* `{ name, input }`, the provider emits one tool_use (with a deterministic
|
|
7
|
+
* model tool-use id) per stream call until the script is exhausted, then
|
|
8
|
+
* falls back to text. This lets full-stack tests drive real tool execution
|
|
9
|
+
* (Product Tools, todo_write) through the real Worker loop. */
|
|
10
|
+
const FAKE_MODEL = {
|
|
11
|
+
id: "echo",
|
|
12
|
+
name: "Fake Echo",
|
|
13
|
+
provider: "fake",
|
|
14
|
+
api: "anthropic-messages",
|
|
15
|
+
reasoning: false,
|
|
16
|
+
input: ["text"],
|
|
17
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
18
|
+
contextWindow: 200_000,
|
|
19
|
+
maxTokens: 8192,
|
|
20
|
+
};
|
|
21
|
+
/** Second deterministic model: LOOP.md requires generator.model !=
|
|
22
|
+
* evaluator.model, and the child validates the model against the catalog. */
|
|
23
|
+
const FAKE_MODEL_2 = {
|
|
24
|
+
...FAKE_MODEL,
|
|
25
|
+
id: "echo2",
|
|
26
|
+
name: "Fake Echo 2",
|
|
27
|
+
};
|
|
28
|
+
let toolUseSeq = 0;
|
|
29
|
+
export function fakeProvider(env = process.env) {
|
|
30
|
+
let script = [];
|
|
31
|
+
try {
|
|
32
|
+
const raw = env.OMA_FAKE_TOOL;
|
|
33
|
+
if (raw)
|
|
34
|
+
script = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
script = [];
|
|
38
|
+
}
|
|
39
|
+
// OMA_FAKE_TOOLS_RECORD=<path>: write the tool names the provider
|
|
40
|
+
// actually received per request (first request only) — lets integration
|
|
41
|
+
// tests assert the loop advertised tool schemas to the model.
|
|
42
|
+
const toolsRecord = env.OMA_FAKE_TOOLS_RECORD;
|
|
43
|
+
let recorded = false;
|
|
44
|
+
return {
|
|
45
|
+
id: "fake",
|
|
46
|
+
name: "Fake",
|
|
47
|
+
getModels: () => [FAKE_MODEL, FAKE_MODEL_2],
|
|
48
|
+
async *stream(model, _messages, opts) {
|
|
49
|
+
if (toolsRecord && !recorded) {
|
|
50
|
+
recorded = true;
|
|
51
|
+
try {
|
|
52
|
+
await Bun.write(toolsRecord, JSON.stringify((opts?.tools ?? []).map((t) => t.name)));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* record is best-effort */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const next = script.shift();
|
|
59
|
+
if (next) {
|
|
60
|
+
const id = `toolu-fake-${++toolUseSeq}`;
|
|
61
|
+
yield { delta: { type: "tool_use", id, name: next.name } };
|
|
62
|
+
yield {
|
|
63
|
+
delta: { type: "input_json_delta", id, partial_json: JSON.stringify(next.input) },
|
|
64
|
+
};
|
|
65
|
+
yield { usage: { input: 10, output: 3, cacheRead: 1, cacheCreate: 0 } };
|
|
66
|
+
yield { stopReason: "tool_use" };
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// OMA_FAKE_THINKING emits a reasoning delta before the text so the
|
|
70
|
+
// thinking-transcript path (thinking_update events, TUI ctrl+t) is
|
|
71
|
+
// testable end to end.
|
|
72
|
+
if (env.OMA_FAKE_THINKING) {
|
|
73
|
+
yield { delta: { type: "reasoning", text: env.OMA_FAKE_THINKING } };
|
|
74
|
+
}
|
|
75
|
+
// Model-dependent text makes `--model` observable end to end.
|
|
76
|
+
// OMA_FAKE_TEXT overrides it (e.g. a JSON workflow verdict).
|
|
77
|
+
yield {
|
|
78
|
+
delta: {
|
|
79
|
+
type: "text",
|
|
80
|
+
text: env.OMA_FAKE_TEXT ?? (model.id === "echo2" ? "done2" : "done"),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
yield { usage: { input: 10, output: 3, cacheRead: 1, cacheCreate: 0 } };
|
|
84
|
+
yield { stopReason: "end_turn" };
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
2
|
+
export interface Logger {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
debug(message: string, ...args: unknown[]): void;
|
|
5
|
+
info(message: string, ...args: unknown[]): void;
|
|
6
|
+
warn(message: string, ...args: unknown[]): void;
|
|
7
|
+
error(message: string, ...args: unknown[]): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function consoleLogger(options?: {
|
|
10
|
+
level?: LogLevel;
|
|
11
|
+
}): Logger;
|
|
12
|
+
export declare function noopLogger(): Logger;
|
|
13
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAUD,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAkBpE;AAED,wBAAgB,UAAU,IAAI,MAAM,CAQnC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const LEVEL_ORDER = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
info: 1,
|
|
4
|
+
warn: 2,
|
|
5
|
+
error: 3,
|
|
6
|
+
silent: 4,
|
|
7
|
+
};
|
|
8
|
+
export function consoleLogger(options) {
|
|
9
|
+
const level = options?.level ?? "info";
|
|
10
|
+
return {
|
|
11
|
+
level,
|
|
12
|
+
debug(message, ...args) {
|
|
13
|
+
if (LEVEL_ORDER[level] <= LEVEL_ORDER.debug)
|
|
14
|
+
console.debug(message, ...args);
|
|
15
|
+
},
|
|
16
|
+
info(message, ...args) {
|
|
17
|
+
if (LEVEL_ORDER[level] <= LEVEL_ORDER.info)
|
|
18
|
+
console.log(message, ...args);
|
|
19
|
+
},
|
|
20
|
+
warn(message, ...args) {
|
|
21
|
+
if (LEVEL_ORDER[level] <= LEVEL_ORDER.warn)
|
|
22
|
+
console.warn(message, ...args);
|
|
23
|
+
},
|
|
24
|
+
error(message, ...args) {
|
|
25
|
+
if (LEVEL_ORDER[level] <= LEVEL_ORDER.error)
|
|
26
|
+
console.error(message, ...args);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function noopLogger() {
|
|
31
|
+
return {
|
|
32
|
+
level: "silent",
|
|
33
|
+
debug: () => { },
|
|
34
|
+
info: () => { },
|
|
35
|
+
warn: () => { },
|
|
36
|
+
error: () => { },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AgentRunSnapshot, BackendInputMessage, ProjectedHistoryItem, WorkspaceBinding } from "@chengchenccc/agent-contract";
|
|
2
|
+
import type { AppendBatchInput } from "../persistence/session-store.js";
|
|
3
|
+
export interface LoopInputResult {
|
|
4
|
+
readonly batch: AppendBatchInput;
|
|
5
|
+
readonly systemPrompt: string;
|
|
6
|
+
}
|
|
7
|
+
/** Cross-boundary input for one loop. Carries only domain facts - NO metaText
|
|
8
|
+
* and NO systemPrompt: the OmaSession renders the Meta Message
|
|
9
|
+
* internally from run/workspace/plugin/todo state (renderLoopMeta is the sole
|
|
10
|
+
* Meta owner), and reads the system prompt from `run.systemPrompt`. */
|
|
11
|
+
export interface CodingLoopInput {
|
|
12
|
+
readonly history: readonly ProjectedHistoryItem[];
|
|
13
|
+
readonly input: BackendInputMessage;
|
|
14
|
+
readonly run: AgentRunSnapshot<"oma">;
|
|
15
|
+
readonly workspace: WorkspaceBinding;
|
|
16
|
+
/** Product-run identity, when this run is product-driven (RPC path).
|
|
17
|
+
* Standalone CLI runs omit it: the agent has no product identity. */
|
|
18
|
+
readonly metadata?: {
|
|
19
|
+
readonly conversationId: string;
|
|
20
|
+
readonly agentId: string;
|
|
21
|
+
readonly branchId: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface LoopInputDeps {
|
|
25
|
+
readonly systemPrompt: string;
|
|
26
|
+
readonly metaText: string;
|
|
27
|
+
/** The actual driving input for this loop. Its `message` is persisted as the
|
|
28
|
+
* prompt/follow-up entry (never inferred from history); `inputId` is the
|
|
29
|
+
* durable idempotency source; `productEntryId`, when present, is written onto
|
|
30
|
+
* the appended entry so the same canonical Message is never persisted twice. */
|
|
31
|
+
readonly input: BackendInputMessage;
|
|
32
|
+
/** Projected Product history to sync idempotently (productEntryId). */
|
|
33
|
+
readonly history?: readonly ProjectedHistoryItem[];
|
|
34
|
+
}
|
|
35
|
+
/** Build the append batch for a loop: projected history + one Meta + the
|
|
36
|
+
* driving input Message (source = prompt for normal, follow_up otherwise).
|
|
37
|
+
* The input Message is preserved verbatim (blocks, role, identity). */
|
|
38
|
+
export declare function buildLoopInput(deps: LoopInputDeps, mode?: "normal" | "follow_up"): LoopInputResult;
|
|
39
|
+
//# sourceMappingURL=loop-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-input.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/loop-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AACD;;;wEAGwE;AACxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC;0EACsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAClB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;QAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;qFAGiF;IACjF,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IACpC,uEAAuE;IACvE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CACpD;AAED;;wEAEwE;AACxE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,aAAa,EACnB,IAAI,GAAE,QAAQ,GAAG,WAAsB,GACtC,eAAe,CAsCjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Build the append batch for a loop: projected history + one Meta + the
|
|
2
|
+
* driving input Message (source = prompt for normal, follow_up otherwise).
|
|
3
|
+
* The input Message is preserved verbatim (blocks, role, identity). */
|
|
4
|
+
export function buildLoopInput(deps, mode = "normal") {
|
|
5
|
+
const items = [];
|
|
6
|
+
for (const item of deps.history ?? []) {
|
|
7
|
+
items.push({
|
|
8
|
+
type: "message",
|
|
9
|
+
productEntryId: item.productEntryId,
|
|
10
|
+
role: item.message.role,
|
|
11
|
+
source: "product_history",
|
|
12
|
+
message: item.message,
|
|
13
|
+
createdAt: Date.now(),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
// Every new loop gets exactly one Meta user message.
|
|
17
|
+
items.push({
|
|
18
|
+
type: "message",
|
|
19
|
+
productEntryId: null,
|
|
20
|
+
role: "user",
|
|
21
|
+
source: "meta",
|
|
22
|
+
message: { role: "user", text: deps.metaText },
|
|
23
|
+
createdAt: Date.now(),
|
|
24
|
+
});
|
|
25
|
+
// The driving input: the full canonical Message, source-tagged by mode.
|
|
26
|
+
items.push({
|
|
27
|
+
type: "message",
|
|
28
|
+
productEntryId: deps.input.productEntryId ?? null,
|
|
29
|
+
role: deps.input.message.role,
|
|
30
|
+
source: mode === "follow_up" ? "follow_up" : "prompt",
|
|
31
|
+
message: deps.input.message,
|
|
32
|
+
createdAt: Date.now(),
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
batch: { entries: items },
|
|
36
|
+
systemPrompt: deps.systemPrompt,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Message } from "@chengchenccc/message";
|
|
2
|
+
/** Per-entry token-estimate memoization:
|
|
3
|
+
*
|
|
4
|
+
* Long sessions re-walk the settled branch every turn to compute total
|
|
5
|
+
* tokens for threshold-compaction checks. Settled messages (append-only,
|
|
6
|
+
* never mutated outside compaction) are estimated once and reused until
|
|
7
|
+
* compaction clears the cache.
|
|
8
|
+
*
|
|
9
|
+
* Keys on the session-tree entryId, which is stable and unique. Clear on
|
|
10
|
+
* compaction — covered entries are gone, surviving ones may have shifted. */
|
|
11
|
+
export declare class TokenEstimateCache {
|
|
12
|
+
private readonly cache;
|
|
13
|
+
estimate(entryId: string, message: Message, estimator: (message: Message) => number): number;
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=message-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-cache.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/message-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;;;;;8EAQ8E;AAC9E,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IAEnD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,GAAG,MAAM;IAQ5F,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Per-entry token-estimate memoization:
|
|
2
|
+
*
|
|
3
|
+
* Long sessions re-walk the settled branch every turn to compute total
|
|
4
|
+
* tokens for threshold-compaction checks. Settled messages (append-only,
|
|
5
|
+
* never mutated outside compaction) are estimated once and reused until
|
|
6
|
+
* compaction clears the cache.
|
|
7
|
+
*
|
|
8
|
+
* Keys on the session-tree entryId, which is stable and unique. Clear on
|
|
9
|
+
* compaction — covered entries are gone, surviving ones may have shifted. */
|
|
10
|
+
export class TokenEstimateCache {
|
|
11
|
+
cache = new Map();
|
|
12
|
+
estimate(entryId, message, estimator) {
|
|
13
|
+
const cached = this.cache.get(entryId);
|
|
14
|
+
if (cached !== undefined)
|
|
15
|
+
return cached;
|
|
16
|
+
const tokens = estimator(message);
|
|
17
|
+
this.cache.set(entryId, tokens);
|
|
18
|
+
return tokens;
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
this.cache.clear();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BackendModelCatalog } from "@chengchenccc/agent-contract";
|
|
2
|
+
import type { ModelRuntime } from "@chengchenccc/ai";
|
|
3
|
+
/** Map the process ModelRuntime catalog to the Backend model contract.
|
|
4
|
+
* Never exposes credentials, headers, Provider objects, or internal runtime
|
|
5
|
+
* state — only configured/missing availability. */
|
|
6
|
+
export interface ModelCatalogOptions {
|
|
7
|
+
modelRuntime: ModelRuntime;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildBackendModelCatalog(opts: ModelCatalogOptions): Promise<BackendModelCatalog>;
|
|
10
|
+
//# sourceMappingURL=model-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-catalog.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/model-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;oDAEoD;AAEpD,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAa9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function buildBackendModelCatalog(opts) {
|
|
2
|
+
const catalog = await opts.modelRuntime.getCatalog();
|
|
3
|
+
const models = catalog.models.map((entry) => ({
|
|
4
|
+
id: `${entry.providerId}/${entry.modelId}`,
|
|
5
|
+
displayName: entry.displayName,
|
|
6
|
+
reasoning: entry.reasoning,
|
|
7
|
+
inputModalities: entry.inputModalities,
|
|
8
|
+
contextWindow: entry.contextWindow,
|
|
9
|
+
maxOutputTokens: entry.maxOutputTokens,
|
|
10
|
+
available: entry.available,
|
|
11
|
+
cost: entry.cost,
|
|
12
|
+
}));
|
|
13
|
+
return { backendKind: "oma", models };
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AIMessageChunk, Message } from "@chengchenccc/message";
|
|
2
|
+
import type { SessionStore } from "../persistence/session-store.js";
|
|
3
|
+
import type { OmaLoopEvent } from "./agent-event.js";
|
|
4
|
+
/** Runtime capabilities injected into plugin hooks. Mirrors a subset of
|
|
5
|
+
* model stream, store, workspace, event emit.
|
|
6
|
+
*
|
|
7
|
+
* Plugins receive this as the last parameter of each hook, so factory
|
|
8
|
+
* closures capture configuration (modelRef, enabled) while runtime
|
|
9
|
+
* capabilities come from the `rt` argument. */
|
|
10
|
+
export interface PluginRuntime {
|
|
11
|
+
/** Stream a model call (bounded by the same modelTimeoutMs as the main
|
|
12
|
+
* loop). Plugins use this for side-channel summaries - never for the main
|
|
13
|
+
* agent turn. */
|
|
14
|
+
readonly streamModel: (providerId: string, modelId: string, messages: readonly Message[], opts?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}) => AsyncIterable<AIMessageChunk>;
|
|
17
|
+
/** Run an ephemeral side-channel model turn: appends `prompt` as a user
|
|
18
|
+
* message to the current branch history, streams through the run's model
|
|
19
|
+
* (with the same system prompt + tool catalog for prompt cache), collects
|
|
20
|
+
* text output, and discards any tool calls. The result is NEVER persisted
|
|
21
|
+
* to the session branch — it's a pure side-channel read.
|
|
22
|
+
*
|
|
23
|
+
* An ephemeral side-channel turn. Used by title/summary features so
|
|
24
|
+
* plugins don't need to manually construct messages or know the model
|
|
25
|
+
* ref. One call: `const text = await rt.runEphemeralTurn(prompt);` */
|
|
26
|
+
/** Set by the loop (not by external code). Optional on the interface
|
|
27
|
+
* so run-runtime/tests don't need a stub. */
|
|
28
|
+
readonly runEphemeralTurn?: (prompt: string, opts?: {
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}) => Promise<string>;
|
|
31
|
+
/** Session store (read-only for plugins): branch history, todo state. */
|
|
32
|
+
readonly store: SessionStore;
|
|
33
|
+
readonly sessionId: string;
|
|
34
|
+
/** Run workspace root. */
|
|
35
|
+
readonly workspaceRoot: string;
|
|
36
|
+
/** Emit a UI-transient event to the Run SSE (never to History). */
|
|
37
|
+
readonly emit: (event: OmaLoopEvent) => void;
|
|
38
|
+
/** The run's abort signal (for graceful shutdown). */
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=plugin-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-runtime.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/plugin-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;gDAKgD;AAChD,MAAM,WAAW,aAAa;IAC5B;;sBAEkB;IAClB,QAAQ,CAAC,WAAW,EAAE,CACpB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,KAC5B,aAAa,CAAC,cAAc,CAAC,CAAC;IAEnC;;;;;;;;2EAQuE;IACvE;kDAC8C;IAC9C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjG,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,0BAA0B;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAE7C,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AskQuestionInput, AskQuestionResult } from "@chengchenccc/agent-contract";
|
|
2
|
+
import type { Message } from "@chengchenccc/message";
|
|
3
|
+
import type { OmaLoopEvent } from "./agent-event.js";
|
|
4
|
+
import type { ApprovalDecision } from "./approval.js";
|
|
5
|
+
import type { PluginRuntime } from "./plugin-runtime.js";
|
|
6
|
+
export interface PluginTool {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly description: string;
|
|
9
|
+
readonly inputSchema?: Readonly<Record<string, unknown>>;
|
|
10
|
+
/** "serial" (default) = must run alone; "concurrent" = read-only, safe to
|
|
11
|
+
* run in parallel with other concurrent tools in the same turn. */
|
|
12
|
+
readonly executionMode?: "serial" | "concurrent";
|
|
13
|
+
/** Wall-clock timeout for this tool in ms (0 = disabled). Shown in the
|
|
14
|
+
* TUI tool card and surfaced on tool_execution_start for live display. */
|
|
15
|
+
readonly timeoutMs?: number;
|
|
16
|
+
execute(args: Readonly<Record<string, unknown>>, signal?: AbortSignal,
|
|
17
|
+
/** Per-call execution context: the model tool-use id (stable per-run
|
|
18
|
+
* idempotency identity for Product Tools). */
|
|
19
|
+
options?: {
|
|
20
|
+
callId?: string;
|
|
21
|
+
/** Streaming partial output (e.g. bash stdout) for live display. */
|
|
22
|
+
onOutput?: (partial: string) => void;
|
|
23
|
+
/** HITL: ask the human for an approval decision. Absent = no pipeline
|
|
24
|
+
* configured (the tool decides; fail closed itself when sensitive).
|
|
25
|
+
* Resolves null when no verdict could be obtained. */
|
|
26
|
+
request?: (req: {
|
|
27
|
+
reason?: string;
|
|
28
|
+
}) => Promise<ApprovalDecision | null>;
|
|
29
|
+
/** HITL: ask the user structured questions (ask_question tool).
|
|
30
|
+
* Absent = no ask pipeline (tool fails closed). Resolves null when
|
|
31
|
+
* no answer could be obtained. */
|
|
32
|
+
ask?: (input: AskQuestionInput) => Promise<AskQuestionResult | null>;
|
|
33
|
+
}): Promise<Readonly<Record<string, unknown>>>;
|
|
34
|
+
}
|
|
35
|
+
export interface PluginHooks {
|
|
36
|
+
/** Called ONCE at Run start (after agent_start, before the first model
|
|
37
|
+
* turn). Plugins use it for per-Run setup (load state, reset counters). */
|
|
38
|
+
beforeRun?(messages: readonly Message[], rt: PluginRuntime): void;
|
|
39
|
+
/** Called ONCE after the entire agent loop ends (all turns done), before
|
|
40
|
+
* agent_end. Plugins use this for per-Run summaries. */
|
|
41
|
+
afterRun?(status: "completed" | "failed" | "stopped", messages: readonly Message[], rt: PluginRuntime): void | Promise<void>;
|
|
42
|
+
/** Called before each model request; may transform messages. */
|
|
43
|
+
beforeModel?(messages: readonly Message[], rt: PluginRuntime): readonly Message[];
|
|
44
|
+
/** Called after each model turn (assistant text persisted, tools executed),
|
|
45
|
+
* before turn_end. */
|
|
46
|
+
afterModel?(messages: readonly Message[], rt: PluginRuntime): void;
|
|
47
|
+
/** Called before a tool executes. May return `{ block: true, reason }` to
|
|
48
|
+
* prevent execution — an error tool result is emitted instead.
|
|
49
|
+
* Returning void/undefined = observe only. */
|
|
50
|
+
beforeTool?(toolName: string, input: unknown, rt: PluginRuntime): undefined | {
|
|
51
|
+
block?: boolean;
|
|
52
|
+
reason?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Called after a tool executes. May return a UI-transient event OR a
|
|
55
|
+
* patch object `{ content?, isError?, terminate? }` that overrides the
|
|
56
|
+
* executed result field-by-field. */
|
|
57
|
+
afterTool?(toolName: string, result: unknown, rt: PluginRuntime): OmaLoopEvent | {
|
|
58
|
+
content?: unknown;
|
|
59
|
+
isError?: boolean;
|
|
60
|
+
terminate?: boolean;
|
|
61
|
+
} | undefined;
|
|
62
|
+
/** Rewrite tool call arguments before execution.
|
|
63
|
+
* Use for deobfuscation, normalization, or injecting context. */
|
|
64
|
+
transformToolArgs?(toolName: string, input: unknown, rt: PluginRuntime): unknown;
|
|
65
|
+
/** Called when the model naturally stops (no more tool calls). A plugin
|
|
66
|
+
* can veto by calling cancel() to force one more turn. */
|
|
67
|
+
beforeStop?(cancel: () => void, rt: PluginRuntime): void;
|
|
68
|
+
/** Called after the stop decision is finalized. `vetoed=true` means a
|
|
69
|
+
* plugin forced the loop to continue; `vetoed=false` means the loop
|
|
70
|
+
* accepted the natural stop (afterRun follows). */
|
|
71
|
+
afterStop?(vetoed: boolean, rt: PluginRuntime): void;
|
|
72
|
+
}
|
|
73
|
+
export interface MetaSectionProvider {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
render(): string;
|
|
76
|
+
}
|
|
77
|
+
export interface Plugin {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly hooks?: PluginHooks;
|
|
80
|
+
readonly tools?: readonly PluginTool[];
|
|
81
|
+
readonly meta?: readonly MetaSectionProvider[];
|
|
82
|
+
}
|
|
83
|
+
export declare function validatePlugins(plugins: readonly Plugin[]): void;
|
|
84
|
+
export declare function renderMeta(plugins: readonly Plugin[]): string;
|
|
85
|
+
export declare function collectTools(plugins: readonly Plugin[]): PluginTool[];
|
|
86
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/plugin.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function validatePlugins(plugins) {
|
|
2
|
+
const names = new Set();
|
|
3
|
+
const toolNames = new Set();
|
|
4
|
+
for (const p of plugins) {
|
|
5
|
+
if (names.has(p.name))
|
|
6
|
+
throw new Error(`Duplicate plugin name: ${p.name}`);
|
|
7
|
+
names.add(p.name);
|
|
8
|
+
for (const t of p.tools ?? []) {
|
|
9
|
+
if (toolNames.has(t.name))
|
|
10
|
+
throw new Error(`Duplicate tool name: ${t.name} (plugin ${p.name})`);
|
|
11
|
+
toolNames.add(t.name);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function renderMeta(plugins) {
|
|
16
|
+
return plugins
|
|
17
|
+
.flatMap((p) => p.meta ?? [])
|
|
18
|
+
.map((m) => `## ${m.name}\n${m.render()}`)
|
|
19
|
+
.join("\n\n");
|
|
20
|
+
}
|
|
21
|
+
export function collectTools(plugins) {
|
|
22
|
+
return plugins.flatMap((p) => p.tools ?? []);
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Process-tree teardown helper shared by MCP stdio clients.
|
|
2
|
+
|
|
3
|
+
* The MCP SDK's StdioClientTransport.close() only SIGKILLs its direct
|
|
4
|
+
* child. npm/npx-style servers spawn grandchildren (npm -> sh -> node)
|
|
5
|
+
* that inherit the stdio pipes; once the direct child dies they are
|
|
6
|
+
* reparented to init, so a post-close pgrep -P walk cannot find them.
|
|
7
|
+
* Collect the whole descendant tree BEFORE closing, then SIGKILL every
|
|
8
|
+
* pid after the SDK close. */
|
|
9
|
+
export declare function collectDescendants(pid: number): number[];
|
|
10
|
+
/** Collect pid + descendants, then SIGKILL them all (best-effort). */
|
|
11
|
+
export declare function killProcessTree(pid: number): void;
|
|
12
|
+
//# sourceMappingURL=process-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-tree.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/process-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;+BAO+B;AAC/B,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBxD;AAED,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CASjD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Process-tree teardown helper shared by MCP stdio clients.
|
|
2
|
+
|
|
3
|
+
* The MCP SDK's StdioClientTransport.close() only SIGKILLs its direct
|
|
4
|
+
* child. npm/npx-style servers spawn grandchildren (npm -> sh -> node)
|
|
5
|
+
* that inherit the stdio pipes; once the direct child dies they are
|
|
6
|
+
* reparented to init, so a post-close pgrep -P walk cannot find them.
|
|
7
|
+
* Collect the whole descendant tree BEFORE closing, then SIGKILL every
|
|
8
|
+
* pid after the SDK close. */
|
|
9
|
+
export function collectDescendants(pid) {
|
|
10
|
+
const descendants = [];
|
|
11
|
+
const queue = [pid];
|
|
12
|
+
while (queue.length > 0) {
|
|
13
|
+
const parent = queue.shift();
|
|
14
|
+
const out = Bun.spawnSync(["pgrep", "-P", String(parent)], { stdout: "pipe" })
|
|
15
|
+
.stdout.toString()
|
|
16
|
+
.trim();
|
|
17
|
+
if (!out)
|
|
18
|
+
continue;
|
|
19
|
+
for (const line of out.split("\n")) {
|
|
20
|
+
const child = Number(line);
|
|
21
|
+
if (child > 0) {
|
|
22
|
+
descendants.push(child);
|
|
23
|
+
queue.push(child);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return descendants;
|
|
28
|
+
}
|
|
29
|
+
/** Collect pid + descendants, then SIGKILL them all (best-effort). */
|
|
30
|
+
export function killProcessTree(pid) {
|
|
31
|
+
const tree = [pid, ...collectDescendants(pid)];
|
|
32
|
+
for (const target of tree) {
|
|
33
|
+
try {
|
|
34
|
+
process.kill(target, "SIGKILL");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* already gone */
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin } from "./plugin.js";
|
|
2
|
+
/** Inputs for rendering the per-loop <system-reminder> Meta user message.
|
|
3
|
+
* Runtime facts only: plugin-loaded meta sections (skill index) and the
|
|
4
|
+
* workspace/model echo. Product-side content never rides this channel -
|
|
5
|
+
* backend-owned identity/config lives in the workspace files the system
|
|
6
|
+
* prompt reads (ADR 0003). */
|
|
7
|
+
export interface LoopMetaInput {
|
|
8
|
+
readonly plugins: readonly Plugin[];
|
|
9
|
+
readonly workspace: {
|
|
10
|
+
readonly root: string;
|
|
11
|
+
readonly cwd?: string;
|
|
12
|
+
};
|
|
13
|
+
/** Resolved model display identity for the workspace/model fact line.
|
|
14
|
+
* Kept minimal so Meta rendering does not depend on a full Model type. */
|
|
15
|
+
readonly model?: {
|
|
16
|
+
readonly provider: string;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Render the unified <system-reminder> Meta user message from runtime facts.
|
|
21
|
+
* Empty sections are omitted. The structure follows oma-prompt.md. */
|
|
22
|
+
export declare function renderLoopMeta(input: LoopMetaInput): string;
|
|
23
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;+BAI+B;AAC/B,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE;+EAC2E;IAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE;AAQD;uEACuE;AACvE,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAmB3D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function section(heading, body) {
|
|
2
|
+
const trimmed = body.trim();
|
|
3
|
+
if (!trimmed)
|
|
4
|
+
return null;
|
|
5
|
+
return `# ${heading}\n\n${trimmed}`;
|
|
6
|
+
}
|
|
7
|
+
/** Render the unified <system-reminder> Meta user message from runtime facts.
|
|
8
|
+
* Empty sections are omitted. The structure follows oma-prompt.md. */
|
|
9
|
+
export function renderLoopMeta(input) {
|
|
10
|
+
const sections = [];
|
|
11
|
+
// Plugin Meta sections (skill index, todo helper, etc.)
|
|
12
|
+
const pluginSections = input.plugins
|
|
13
|
+
.flatMap((p) => p.meta ?? [])
|
|
14
|
+
.map((m) => section(m.name, m.render()))
|
|
15
|
+
.filter((s) => s !== null);
|
|
16
|
+
sections.push(...pluginSections);
|
|
17
|
+
// Workspace / runtime facts
|
|
18
|
+
const wsParts = [`Workspace root: ${input.workspace.root}`];
|
|
19
|
+
if (input.workspace.cwd)
|
|
20
|
+
wsParts.push(`Working directory: ${input.workspace.cwd}`);
|
|
21
|
+
if (input.model)
|
|
22
|
+
wsParts.push(`Model: ${input.model.provider}/${input.model.id}`);
|
|
23
|
+
const ws = section("Workspace", wsParts.join("\n"));
|
|
24
|
+
if (ws)
|
|
25
|
+
sections.push(ws);
|
|
26
|
+
if (sections.length === 0)
|
|
27
|
+
return "";
|
|
28
|
+
return `<system-reminder>\n${sections.join("\n\n")}\n</system-reminder>`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** oma's own prompt layer (mirrors omp's src/prompts layout): base
|
|
2
|
+
* identity + safety + memory discipline live here as md files; workspace
|
|
3
|
+
* files (AGENTS.md / SOUL.md / USER.md + knowledge index) remain the
|
|
4
|
+
* agent-specific layer and are appended when present. Explicit
|
|
5
|
+
* run-input systemPrompt (Loop scopes) still wins wholesale — callers
|
|
6
|
+
* bypass this builder. */
|
|
7
|
+
export declare function buildSystemPrompt(input: {
|
|
8
|
+
workspacePrompt?: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
/** Pre-read memory summary (workspace memory/memory_summary.md). */
|
|
11
|
+
memorySummary?: string;
|
|
12
|
+
}): string;
|
|
13
|
+
/** Workspace memory summary for prompt injection (absent when the agent
|
|
14
|
+
* has never written memories). */
|
|
15
|
+
export declare function readMemorySummary(cwd: string): string | undefined;
|
|
16
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/prompts.ts"],"names":[],"mappings":"AAKA;;;;;2BAK2B;AAC3B,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,MAAM,CAgBT;AAED;mCACmC;AACnC,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOjE"}
|