@oharness/engine 0.1.0
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.d.ts +196 -0
- package/dist/agent/agent.js +758 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/compaction.d.ts +68 -0
- package/dist/agent/compaction.js +179 -0
- package/dist/agent/compaction.js.map +1 -0
- package/dist/agent/hooks.d.ts +77 -0
- package/dist/agent/hooks.js +152 -0
- package/dist/agent/hooks.js.map +1 -0
- package/dist/agent/memory.d.ts +45 -0
- package/dist/agent/memory.js +147 -0
- package/dist/agent/memory.js.map +1 -0
- package/dist/agent/overflow.d.ts +35 -0
- package/dist/agent/overflow.js +69 -0
- package/dist/agent/overflow.js.map +1 -0
- package/dist/agent/permissions.d.ts +181 -0
- package/dist/agent/permissions.js +289 -0
- package/dist/agent/permissions.js.map +1 -0
- package/dist/agent/prompt.d.ts +25 -0
- package/dist/agent/prompt.js +63 -0
- package/dist/agent/prompt.js.map +1 -0
- package/dist/agent/session.d.ts +108 -0
- package/dist/agent/session.js +231 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/settings.d.ts +37 -0
- package/dist/agent/settings.js +113 -0
- package/dist/agent/settings.js.map +1 -0
- package/dist/agent/skills.d.ts +58 -0
- package/dist/agent/skills.js +225 -0
- package/dist/agent/skills.js.map +1 -0
- package/dist/agent/store.d.ts +308 -0
- package/dist/agent/store.js +596 -0
- package/dist/agent/store.js.map +1 -0
- package/dist/agent/subagent.d.ts +44 -0
- package/dist/agent/subagent.js +138 -0
- package/dist/agent/subagent.js.map +1 -0
- package/dist/agent/titles.d.ts +8 -0
- package/dist/agent/titles.js +23 -0
- package/dist/agent/titles.js.map +1 -0
- package/dist/agent/workspace.d.ts +60 -0
- package/dist/agent/workspace.js +156 -0
- package/dist/agent/workspace.js.map +1 -0
- package/dist/artifacts/publish.d.ts +94 -0
- package/dist/artifacts/publish.js +104 -0
- package/dist/artifacts/publish.js.map +1 -0
- package/dist/artifacts/store.d.ts +324 -0
- package/dist/artifacts/store.js +500 -0
- package/dist/artifacts/store.js.map +1 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/manager.d.ts +83 -0
- package/dist/auth/manager.js +266 -0
- package/dist/auth/manager.js.map +1 -0
- package/dist/auth/oauth.d.ts +83 -0
- package/dist/auth/oauth.js +327 -0
- package/dist/auth/oauth.js.map +1 -0
- package/dist/auth/providers/account.d.ts +59 -0
- package/dist/auth/providers/account.js +282 -0
- package/dist/auth/providers/account.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +24 -0
- package/dist/auth/providers/anthropic.js +209 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/generic.d.ts +57 -0
- package/dist/auth/providers/generic.js +155 -0
- package/dist/auth/providers/generic.js.map +1 -0
- package/dist/auth/providers/official.d.ts +3 -0
- package/dist/auth/providers/official.js +90 -0
- package/dist/auth/providers/official.js.map +1 -0
- package/dist/auth/providers/ottoport.d.ts +3 -0
- package/dist/auth/providers/ottoport.js +60 -0
- package/dist/auth/providers/ottoport.js.map +1 -0
- package/dist/auth/store.d.ts +22 -0
- package/dist/auth/store.js +138 -0
- package/dist/auth/store.js.map +1 -0
- package/dist/auth/types.d.ts +167 -0
- package/dist/auth/types.js +16 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/config.d.ts +197 -0
- package/dist/config.js +195 -0
- package/dist/config.js.map +1 -0
- package/dist/core/errors.d.ts +46 -0
- package/dist/core/errors.js +83 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/tokens.d.ts +12 -0
- package/dist/core/tokens.js +56 -0
- package/dist/core/tokens.js.map +1 -0
- package/dist/core/types.d.ts +91 -0
- package/dist/core/types.js +49 -0
- package/dist/core/types.js.map +1 -0
- package/dist/harness.d.ts +302 -0
- package/dist/harness.js +695 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +55 -0
- package/dist/mcp/client.js +199 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +77 -0
- package/dist/mcp/manager.js +325 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/oauth.d.ts +63 -0
- package/dist/mcp/oauth.js +302 -0
- package/dist/mcp/oauth.js.map +1 -0
- package/dist/mcp/protocol.d.ts +130 -0
- package/dist/mcp/protocol.js +14 -0
- package/dist/mcp/protocol.js.map +1 -0
- package/dist/mcp/registry.d.ts +52 -0
- package/dist/mcp/registry.js +100 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/registry.json +293 -0
- package/dist/mcp/secrets.d.ts +20 -0
- package/dist/mcp/secrets.js +75 -0
- package/dist/mcp/secrets.js.map +1 -0
- package/dist/mcp/transport.d.ts +51 -0
- package/dist/mcp/transport.js +158 -0
- package/dist/mcp/transport.js.map +1 -0
- package/dist/paths.d.ts +37 -0
- package/dist/paths.js +63 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugins.d.ts +55 -0
- package/dist/plugins.js +201 -0
- package/dist/plugins.js.map +1 -0
- package/dist/providers/builtin.d.ts +23 -0
- package/dist/providers/builtin.js +141 -0
- package/dist/providers/builtin.js.map +1 -0
- package/dist/providers/catalog.d.ts +129 -0
- package/dist/providers/catalog.js +254 -0
- package/dist/providers/catalog.js.map +1 -0
- package/dist/providers/catalog.json +472 -0
- package/dist/providers/discovery.d.ts +16 -0
- package/dist/providers/discovery.js +161 -0
- package/dist/providers/discovery.js.map +1 -0
- package/dist/providers/http.d.ts +24 -0
- package/dist/providers/http.js +139 -0
- package/dist/providers/http.js.map +1 -0
- package/dist/providers/index.d.ts +10 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/piai.d.ts +124 -0
- package/dist/providers/piai.js +551 -0
- package/dist/providers/piai.js.map +1 -0
- package/dist/providers/registry.d.ts +65 -0
- package/dist/providers/registry.js +195 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/resilient.d.ts +46 -0
- package/dist/providers/resilient.js +117 -0
- package/dist/providers/resilient.js.map +1 -0
- package/dist/providers/types.d.ts +182 -0
- package/dist/providers/types.js +50 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/schedule/cron.d.ts +35 -0
- package/dist/schedule/cron.js +125 -0
- package/dist/schedule/cron.js.map +1 -0
- package/dist/schedule/scheduler.d.ts +87 -0
- package/dist/schedule/scheduler.js +237 -0
- package/dist/schedule/scheduler.js.map +1 -0
- package/dist/storage/kv.d.ts +56 -0
- package/dist/storage/kv.js +173 -0
- package/dist/storage/kv.js.map +1 -0
- package/dist/storage/migrate.d.ts +11 -0
- package/dist/storage/migrate.js +93 -0
- package/dist/storage/migrate.js.map +1 -0
- package/dist/storage/project.d.ts +9 -0
- package/dist/storage/project.js +57 -0
- package/dist/storage/project.js.map +1 -0
- package/dist/storage/records.d.ts +32 -0
- package/dist/storage/records.js +48 -0
- package/dist/storage/records.js.map +1 -0
- package/dist/sync/client.d.ts +79 -0
- package/dist/sync/client.js +118 -0
- package/dist/sync/client.js.map +1 -0
- package/dist/sync/mirror.d.ts +85 -0
- package/dist/sync/mirror.js +389 -0
- package/dist/sync/mirror.js.map +1 -0
- package/dist/sync/protocol.d.ts +67 -0
- package/dist/sync/protocol.js +16 -0
- package/dist/sync/protocol.js.map +1 -0
- package/dist/sync/settings.d.ts +56 -0
- package/dist/sync/settings.js +60 -0
- package/dist/sync/settings.js.map +1 -0
- package/dist/tools/builtin/artifact.d.ts +16 -0
- package/dist/tools/builtin/artifact.js +134 -0
- package/dist/tools/builtin/artifact.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +3 -0
- package/dist/tools/builtin/bash.js +142 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/fs.d.ts +19 -0
- package/dist/tools/builtin/fs.js +280 -0
- package/dist/tools/builtin/fs.js.map +1 -0
- package/dist/tools/builtin/index.d.ts +22 -0
- package/dist/tools/builtin/index.js +42 -0
- package/dist/tools/builtin/index.js.map +1 -0
- package/dist/tools/builtin/mcp-resource.d.ts +3 -0
- package/dist/tools/builtin/mcp-resource.js +220 -0
- package/dist/tools/builtin/mcp-resource.js.map +1 -0
- package/dist/tools/builtin/memory.d.ts +10 -0
- package/dist/tools/builtin/memory.js +76 -0
- package/dist/tools/builtin/memory.js.map +1 -0
- package/dist/tools/builtin/recall.d.ts +13 -0
- package/dist/tools/builtin/recall.js +163 -0
- package/dist/tools/builtin/recall.js.map +1 -0
- package/dist/tools/builtin/search.d.ts +3 -0
- package/dist/tools/builtin/search.js +240 -0
- package/dist/tools/builtin/search.js.map +1 -0
- package/dist/tools/builtin/skill.d.ts +10 -0
- package/dist/tools/builtin/skill.js +46 -0
- package/dist/tools/builtin/skill.js.map +1 -0
- package/dist/tools/builtin/task.d.ts +9 -0
- package/dist/tools/builtin/task.js +68 -0
- package/dist/tools/builtin/task.js.map +1 -0
- package/dist/tools/builtin/todo.d.ts +20 -0
- package/dist/tools/builtin/todo.js +63 -0
- package/dist/tools/builtin/todo.js.map +1 -0
- package/dist/tools/define.d.ts +19 -0
- package/dist/tools/define.js +39 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.js +5 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +39 -0
- package/dist/tools/registry.js +101 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +112 -0
- package/dist/tools/types.js +22 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/util/id.d.ts +9 -0
- package/dist/util/id.js +19 -0
- package/dist/util/id.js.map +1 -0
- package/dist/util/json.d.ts +25 -0
- package/dist/util/json.js +100 -0
- package/dist/util/json.js.map +1 -0
- package/dist/util/jwt.d.ts +74 -0
- package/dist/util/jwt.js +177 -0
- package/dist/util/jwt.js.map +1 -0
- package/dist/util/logger.d.ts +13 -0
- package/dist/util/logger.js +59 -0
- package/dist/util/logger.js.map +1 -0
- package/dist/util/queue.d.ts +26 -0
- package/dist/util/queue.js +106 -0
- package/dist/util/queue.js.map +1 -0
- package/dist/util/schema.d.ts +17 -0
- package/dist/util/schema.js +98 -0
- package/dist/util/schema.js.map +1 -0
- package/dist/util/shell.d.ts +20 -0
- package/dist/util/shell.js +24 -0
- package/dist/util/shell.js.map +1 -0
- package/official.json +4 -0
- package/package.json +38 -0
- package/skills/artifact-authoring/SKILL.md +81 -0
- package/skills/canvas/SKILL.md +85 -0
- package/skills/skill-authoring/SKILL.md +85 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Message, StopReason, Usage } from "../core/types.ts";
|
|
2
|
+
import type { McpManager } from "../mcp/manager.ts";
|
|
3
|
+
import type { ThinkingConfig } from "../providers/types.ts";
|
|
4
|
+
import type { ToolFilter, ToolRegistry } from "../tools/registry.ts";
|
|
5
|
+
import type { SubagentRunOptions, SubagentRunResult, ToolHost, ToolProgress, ToolResult } from "../tools/types.ts";
|
|
6
|
+
import type { ArtifactDescriptor } from "../artifacts/store.ts";
|
|
7
|
+
import type { Logger } from "../util/logger.ts";
|
|
8
|
+
import type { WorkspacePolicy } from "./workspace.ts";
|
|
9
|
+
import { SkillRegistry } from "./skills.ts";
|
|
10
|
+
import { MemoryStore } from "./memory.ts";
|
|
11
|
+
import type { CompactionOptions } from "./compaction.ts";
|
|
12
|
+
import { HookRegistry } from "./hooks.ts";
|
|
13
|
+
import type { PermissionPrompt, PermissionRequest } from "./permissions.ts";
|
|
14
|
+
import type { Session } from "./session.ts";
|
|
15
|
+
import { SubagentRegistry } from "./subagent.ts";
|
|
16
|
+
export type AgentEvent = {
|
|
17
|
+
type: "turn_start";
|
|
18
|
+
turn: number;
|
|
19
|
+
model: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "text_delta";
|
|
22
|
+
text: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "thinking_delta";
|
|
25
|
+
text: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "assistant_message";
|
|
28
|
+
message: Message;
|
|
29
|
+
} | {
|
|
30
|
+
type: "tool_start";
|
|
31
|
+
toolCallId: string;
|
|
32
|
+
toolName: string;
|
|
33
|
+
title: string;
|
|
34
|
+
input: unknown;
|
|
35
|
+
} | {
|
|
36
|
+
type: "tool_progress";
|
|
37
|
+
progress: ToolProgress;
|
|
38
|
+
} | {
|
|
39
|
+
type: "tool_end";
|
|
40
|
+
toolCallId: string;
|
|
41
|
+
toolName: string;
|
|
42
|
+
result: ToolResult;
|
|
43
|
+
durationMs: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An artifact was created or revised. Carries a descriptor, never the body:
|
|
47
|
+
* see artifacts/store.ts for why. A frontend that cannot render this kind is
|
|
48
|
+
* still expected to acknowledge it — test/artifacts.test.ts enforces that.
|
|
49
|
+
*/
|
|
50
|
+
| {
|
|
51
|
+
type: "artifact";
|
|
52
|
+
artifact: ArtifactDescriptor;
|
|
53
|
+
} | {
|
|
54
|
+
type: "permission_request";
|
|
55
|
+
request: PermissionRequest;
|
|
56
|
+
} | {
|
|
57
|
+
type: "permission_result";
|
|
58
|
+
toolCallId: string;
|
|
59
|
+
allowed: boolean;
|
|
60
|
+
reason?: string;
|
|
61
|
+
/** Pattern written to settings, when the approval was persisted. */
|
|
62
|
+
remembered?: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: "compacted";
|
|
65
|
+
tokensBefore: number;
|
|
66
|
+
tokensAfter: number;
|
|
67
|
+
droppedMessages: number;
|
|
68
|
+
} | {
|
|
69
|
+
type: "model_changed";
|
|
70
|
+
from: string;
|
|
71
|
+
to: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "notice";
|
|
74
|
+
message: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `status` is the HTTP status behind a provider failure, when one could be
|
|
78
|
+
* recovered. It travels beside the message because some statuses are not
|
|
79
|
+
* errors to print at all: a 402 means the account is out of credits, which
|
|
80
|
+
* is a screen with a button on it, and telling that apart from a bad key by
|
|
81
|
+
* matching text in a sentence is a thing that breaks on rewording.
|
|
82
|
+
*/
|
|
83
|
+
| {
|
|
84
|
+
type: "error";
|
|
85
|
+
error: string;
|
|
86
|
+
fatal: boolean;
|
|
87
|
+
status?: number;
|
|
88
|
+
provider?: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "done";
|
|
91
|
+
stopReason: StopReason;
|
|
92
|
+
usage: Usage;
|
|
93
|
+
costUsd: number;
|
|
94
|
+
turns: number;
|
|
95
|
+
};
|
|
96
|
+
export interface AgentOptions {
|
|
97
|
+
session: Session;
|
|
98
|
+
tools: ToolRegistry;
|
|
99
|
+
hooks?: HookRegistry;
|
|
100
|
+
subagents?: SubagentRegistry;
|
|
101
|
+
mcp?: McpManager;
|
|
102
|
+
/** Called when a tool needs approval. Without it, `ask` becomes `deny`. */
|
|
103
|
+
permissionPrompt?: PermissionPrompt;
|
|
104
|
+
systemPrompt?: string;
|
|
105
|
+
appendSystemPrompt?: string;
|
|
106
|
+
projectInstructions?: string;
|
|
107
|
+
toolFilter?: ToolFilter;
|
|
108
|
+
thinking?: ThinkingConfig;
|
|
109
|
+
maxTurns?: number;
|
|
110
|
+
compaction?: CompactionOptions | false;
|
|
111
|
+
/**
|
|
112
|
+
* Character cap on a single tool result before it is truncated and archived.
|
|
113
|
+
* Defaults to `DEFAULT_TOOL_RESULT_LIMIT`; set 0 to disable.
|
|
114
|
+
*/
|
|
115
|
+
toolResultLimit?: number;
|
|
116
|
+
/** Cheaper model for compaction summaries; defaults to the session model. */
|
|
117
|
+
smallModel?: string;
|
|
118
|
+
/** Skills available to this agent; their descriptions enter the prompt. */
|
|
119
|
+
skills?: SkillRegistry;
|
|
120
|
+
/** Durable notes carried between sessions. */
|
|
121
|
+
memory?: MemoryStore;
|
|
122
|
+
/** Called after the agent writes into a skills directory. */
|
|
123
|
+
onSkillsChanged?: () => Promise<unknown>;
|
|
124
|
+
/** Restricts where writes may land. A policy gate, not an OS sandbox. */
|
|
125
|
+
workspace?: WorkspacePolicy;
|
|
126
|
+
/** Enable provider prompt caching where the model supports it. */
|
|
127
|
+
cache?: boolean;
|
|
128
|
+
agentId?: string;
|
|
129
|
+
logger?: Logger;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The agentic loop: prompt the model, run whatever tools it asks for, feed the
|
|
133
|
+
* results back, repeat until it stops calling tools.
|
|
134
|
+
*
|
|
135
|
+
* Everything provider-specific lives behind `Provider`, so this loop is the
|
|
136
|
+
* same regardless of which model is selected — including when the model
|
|
137
|
+
* changes partway through a session.
|
|
138
|
+
*/
|
|
139
|
+
export declare class Agent implements ToolHost {
|
|
140
|
+
readonly session: Session;
|
|
141
|
+
readonly tools: ToolRegistry;
|
|
142
|
+
readonly hooks: HookRegistry;
|
|
143
|
+
readonly subagents: SubagentRegistry;
|
|
144
|
+
readonly skills: SkillRegistry;
|
|
145
|
+
readonly memory?: MemoryStore;
|
|
146
|
+
readonly state: Map<string, unknown>;
|
|
147
|
+
private readonly opts;
|
|
148
|
+
private readonly logger;
|
|
149
|
+
private readonly agentId;
|
|
150
|
+
private controller;
|
|
151
|
+
private running;
|
|
152
|
+
private sessionStarted;
|
|
153
|
+
/** Set when a hook asks the turn to end; read by the main loop. */
|
|
154
|
+
private stopRequested?;
|
|
155
|
+
/** Memory index for this run's system prompt. */
|
|
156
|
+
private memoryIndex?;
|
|
157
|
+
constructor(opts: AgentOptions);
|
|
158
|
+
/**
|
|
159
|
+
* Announce a model switch so a UI can render it and hooks can react.
|
|
160
|
+
* Called by whoever changes the session's model.
|
|
161
|
+
*/
|
|
162
|
+
switchModel(ref: string): AsyncGenerator<AgentEvent, void, void>;
|
|
163
|
+
/**
|
|
164
|
+
* The model used for compaction summaries. Falls back to the session model
|
|
165
|
+
* if `smallModel` is unset or unresolvable — a bad alias should degrade to a
|
|
166
|
+
* pricier summary, never break the turn.
|
|
167
|
+
*/
|
|
168
|
+
private summarizerModel;
|
|
169
|
+
/** Run the SessionEnd hook. Call when the session is finished with. */
|
|
170
|
+
end(): Promise<void>;
|
|
171
|
+
/** Cancel the in-flight turn. The loop exits with `stopReason: "aborted"`. */
|
|
172
|
+
abort(): void;
|
|
173
|
+
get isRunning(): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Where the file tools are allowed to look. The policy lives here, so the
|
|
176
|
+
* tools ask rather than each re-deriving a notion of "inside the project".
|
|
177
|
+
*/
|
|
178
|
+
resolvePath(input: string, access: "read" | "write"): string;
|
|
179
|
+
listSubagentTypes(): Array<{
|
|
180
|
+
name: string;
|
|
181
|
+
description: string;
|
|
182
|
+
}>;
|
|
183
|
+
runSubagent(opts: SubagentRunOptions): Promise<SubagentRunResult>;
|
|
184
|
+
run(input: string | Message[], runOpts?: {
|
|
185
|
+
signal?: AbortSignal;
|
|
186
|
+
}): AsyncGenerator<AgentEvent, void, void>;
|
|
187
|
+
private ingestInput;
|
|
188
|
+
private maybeCompact;
|
|
189
|
+
private systemPrompt;
|
|
190
|
+
private buildRequest;
|
|
191
|
+
/** Consume the provider stream, emitting deltas and assembling the message. */
|
|
192
|
+
private streamAssistant;
|
|
193
|
+
private executeCalls;
|
|
194
|
+
private executeOne;
|
|
195
|
+
private checkPermission;
|
|
196
|
+
}
|