@noetic-tools/core 0.0.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/LICENSE +201 -0
- package/README.md +38 -0
- package/dist/adapters/in-memory-fs-adapter.d.ts +3 -0
- package/dist/adapters/in-memory-fs-adapter.js +245 -0
- package/dist/adapters/in-memory-shell-adapter.d.ts +9 -0
- package/dist/adapters/in-memory-shell-adapter.js +20 -0
- package/dist/adapters/in-memory-subprocess-adapter.d.ts +5 -0
- package/dist/adapters/in-memory-subprocess-adapter.js +126 -0
- package/dist/adapters/local-fs-adapter.d.ts +3 -0
- package/dist/adapters/local-fs-adapter.js +43 -0
- package/dist/adapters/local-shell-adapter.d.ts +51 -0
- package/dist/adapters/local-shell-adapter.js +167 -0
- package/dist/adapters/local-subprocess-adapter.d.ts +16 -0
- package/dist/adapters/local-subprocess-adapter.js +187 -0
- package/dist/adapters/openrouter.d.ts +57 -0
- package/dist/adapters/openrouter.js +248 -0
- package/dist/builders/channel-builder.d.ts +36 -0
- package/dist/builders/channel-builder.js +15 -0
- package/dist/builders/control-flow-builders.d.ts +79 -0
- package/dist/builders/control-flow-builders.js +53 -0
- package/dist/builders/every.d.ts +45 -0
- package/dist/builders/every.js +60 -0
- package/dist/builders/layer-provides-builders.d.ts +32 -0
- package/dist/builders/layer-provides-builders.js +33 -0
- package/dist/builders/loop-builder.d.ts +23 -0
- package/dist/builders/loop-builder.js +46 -0
- package/dist/builders/memory-builder.d.ts +11 -0
- package/dist/builders/memory-builder.js +15 -0
- package/dist/builders/provide-builder.d.ts +20 -0
- package/dist/builders/provide-builder.js +34 -0
- package/dist/builders/spawn-builder.d.ts +20 -0
- package/dist/builders/spawn-builder.js +33 -0
- package/dist/builders/step-builders.d.ts +62 -0
- package/dist/builders/step-builders.js +99 -0
- package/dist/builders/tool-builder.d.ts +52 -0
- package/dist/builders/tool-builder.js +59 -0
- package/dist/conditions/conditions.d.ts +114 -0
- package/dist/conditions/conditions.js +271 -0
- package/dist/conditions/cosine-similarity.d.ts +11 -0
- package/dist/conditions/cosine-similarity.js +28 -0
- package/dist/conditions/index.d.ts +3 -0
- package/dist/conditions/index.js +2 -0
- package/dist/errors/noetic-config-error.d.ts +41 -0
- package/dist/errors/noetic-config-error.js +44 -0
- package/dist/errors/noetic-error.d.ts +18 -0
- package/dist/errors/noetic-error.js +52 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +112 -0
- package/dist/internal-test.d.ts +11 -0
- package/dist/internal-test.js +11 -0
- package/dist/interpreter/clone-guard.d.ts +4 -0
- package/dist/interpreter/clone-guard.js +18 -0
- package/dist/interpreter/collect-tools.d.ts +12 -0
- package/dist/interpreter/collect-tools.js +70 -0
- package/dist/interpreter/execute-branch.d.ts +3 -0
- package/dist/interpreter/execute-branch.js +10 -0
- package/dist/interpreter/execute-every.d.ts +15 -0
- package/dist/interpreter/execute-every.js +143 -0
- package/dist/interpreter/execute-fork.d.ts +3 -0
- package/dist/interpreter/execute-fork.js +215 -0
- package/dist/interpreter/execute-llm.d.ts +4 -0
- package/dist/interpreter/execute-llm.js +217 -0
- package/dist/interpreter/execute-loop.d.ts +3 -0
- package/dist/interpreter/execute-loop.js +171 -0
- package/dist/interpreter/execute-provide.d.ts +10 -0
- package/dist/interpreter/execute-provide.js +64 -0
- package/dist/interpreter/execute-run.d.ts +3 -0
- package/dist/interpreter/execute-run.js +39 -0
- package/dist/interpreter/execute-spawn.d.ts +11 -0
- package/dist/interpreter/execute-spawn.js +113 -0
- package/dist/interpreter/execute-tool.d.ts +5 -0
- package/dist/interpreter/execute-tool.js +81 -0
- package/dist/interpreter/execute.d.ts +14 -0
- package/dist/interpreter/execute.js +119 -0
- package/dist/interpreter/framework-cast.d.ts +10 -0
- package/dist/interpreter/framework-cast.js +16 -0
- package/dist/interpreter/message-helpers.d.ts +9 -0
- package/dist/interpreter/message-helpers.js +42 -0
- package/dist/interpreter/typeguards.d.ts +25 -0
- package/dist/interpreter/typeguards.js +50 -0
- package/dist/memory/budget.d.ts +23 -0
- package/dist/memory/budget.js +117 -0
- package/dist/memory/function-call-utils.d.ts +6 -0
- package/dist/memory/function-call-utils.js +25 -0
- package/dist/memory/layer-api.d.ts +14 -0
- package/dist/memory/layer-api.js +91 -0
- package/dist/memory/layer-lifecycle.d.ts +160 -0
- package/dist/memory/layer-lifecycle.js +552 -0
- package/dist/memory/layer-usage.d.ts +15 -0
- package/dist/memory/layer-usage.js +48 -0
- package/dist/memory/layers/durable-task-state.d.ts +79 -0
- package/dist/memory/layers/durable-task-state.js +118 -0
- package/dist/memory/layers/file-reference.d.ts +55 -0
- package/dist/memory/layers/file-reference.js +538 -0
- package/dist/memory/layers/history-window.d.ts +29 -0
- package/dist/memory/layers/history-window.js +114 -0
- package/dist/memory/layers/observational-memory.d.ts +53 -0
- package/dist/memory/layers/observational-memory.js +110 -0
- package/dist/memory/layers/plan.d.ts +55 -0
- package/dist/memory/layers/plan.js +369 -0
- package/dist/memory/layers/static-content.d.ts +27 -0
- package/dist/memory/layers/static-content.js +35 -0
- package/dist/memory/layers/steering.d.ts +51 -0
- package/dist/memory/layers/steering.js +258 -0
- package/dist/memory/layers/tool-memory-layer.d.ts +16 -0
- package/dist/memory/layers/tool-memory-layer.js +43 -0
- package/dist/memory/layers/working-memory.d.ts +44 -0
- package/dist/memory/layers/working-memory.js +92 -0
- package/dist/memory/projector.d.ts +10 -0
- package/dist/memory/projector.js +19 -0
- package/dist/memory/scope.d.ts +3 -0
- package/dist/memory/scope.js +31 -0
- package/dist/memory/strip-unresolved.d.ts +13 -0
- package/dist/memory/strip-unresolved.js +35 -0
- package/dist/observability/genai-attributes.d.ts +11 -0
- package/dist/observability/genai-attributes.js +12 -0
- package/dist/observability/span-impl.d.ts +20 -0
- package/dist/observability/span-impl.js +33 -0
- package/dist/observability/trace-exporter.d.ts +15 -0
- package/dist/observability/trace-exporter.js +26 -0
- package/dist/patterns/flow.d.ts +52 -0
- package/dist/patterns/flow.js +103 -0
- package/dist/patterns/interview.d.ts +53 -0
- package/dist/patterns/interview.js +113 -0
- package/dist/patterns/plans.d.ts +45 -0
- package/dist/patterns/plans.js +125 -0
- package/dist/patterns/ralph-wiggum.d.ts +20 -0
- package/dist/patterns/ralph-wiggum.js +37 -0
- package/dist/patterns/react.d.ts +18 -0
- package/dist/patterns/react.js +39 -0
- package/dist/portable.d.ts +26 -0
- package/dist/portable.js +34 -0
- package/dist/runtime/agent-harness.d.ts +206 -0
- package/dist/runtime/agent-harness.js +1170 -0
- package/dist/runtime/broadcaster-utils.d.ts +30 -0
- package/dist/runtime/broadcaster-utils.js +53 -0
- package/dist/runtime/channel-store.d.ts +18 -0
- package/dist/runtime/channel-store.js +187 -0
- package/dist/runtime/context-impl.d.ts +80 -0
- package/dist/runtime/context-impl.js +140 -0
- package/dist/runtime/cwd-helpers.d.ts +42 -0
- package/dist/runtime/cwd-helpers.js +68 -0
- package/dist/runtime/detached-handle.d.ts +14 -0
- package/dist/runtime/detached-handle.js +56 -0
- package/dist/runtime/event-broadcaster.d.ts +61 -0
- package/dist/runtime/event-broadcaster.js +187 -0
- package/dist/runtime/exec-context-factory.d.ts +25 -0
- package/dist/runtime/exec-context-factory.js +30 -0
- package/dist/runtime/in-memory-storage.d.ts +9 -0
- package/dist/runtime/in-memory-storage.js +33 -0
- package/dist/runtime/item-log-impl.d.ts +11 -0
- package/dist/runtime/item-log-impl.js +25 -0
- package/dist/runtime/message-queue.d.ts +30 -0
- package/dist/runtime/message-queue.js +46 -0
- package/dist/runtime/session-runner.d.ts +77 -0
- package/dist/runtime/session-runner.js +253 -0
- package/dist/runtime/session-streams.d.ts +11 -0
- package/dist/runtime/session-streams.js +204 -0
- package/dist/runtime/tool-memory.d.ts +6 -0
- package/dist/runtime/tool-memory.js +22 -0
- package/dist/schemas/item.d.ts +35 -0
- package/dist/schemas/item.js +155 -0
- package/dist/types/channel.d.ts +29 -0
- package/dist/types/channel.js +1 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +1 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/context.js +1 -0
- package/dist/types/detached.d.ts +17 -0
- package/dist/types/detached.js +7 -0
- package/dist/types/embed.d.ts +5 -0
- package/dist/types/embed.js +1 -0
- package/dist/types/error.d.ts +51 -0
- package/dist/types/error.js +1 -0
- package/dist/types/fs-adapter.d.ts +51 -0
- package/dist/types/fs-adapter.js +3 -0
- package/dist/types/harness-result.d.ts +43 -0
- package/dist/types/harness-result.js +2 -0
- package/dist/types/items.d.ts +115 -0
- package/dist/types/items.js +2 -0
- package/dist/types/memory.d.ts +336 -0
- package/dist/types/memory.js +13 -0
- package/dist/types/mutable-context.d.ts +13 -0
- package/dist/types/mutable-context.js +1 -0
- package/dist/types/observability.d.ts +30 -0
- package/dist/types/observability.js +1 -0
- package/dist/types/runtime.d.ts +255 -0
- package/dist/types/runtime.js +1 -0
- package/dist/types/shell-adapter.d.ts +34 -0
- package/dist/types/shell-adapter.js +10 -0
- package/dist/types/steering.d.ts +89 -0
- package/dist/types/steering.js +14 -0
- package/dist/types/step.d.ts +206 -0
- package/dist/types/step.js +1 -0
- package/dist/types/subprocess-adapter.d.ts +41 -0
- package/dist/types/subprocess-adapter.js +1 -0
- package/dist/types/tool-context.d.ts +34 -0
- package/dist/types/tool-context.js +1 -0
- package/dist/unstable.d.ts +28 -0
- package/dist/unstable.js +24 -0
- package/dist/until/combinators.d.ts +17 -0
- package/dist/until/combinators.js +49 -0
- package/dist/until/never.d.ts +9 -0
- package/dist/until/never.js +12 -0
- package/dist/until/predicates.d.ts +43 -0
- package/dist/until/predicates.js +126 -0
- package/package.json +81 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { loop } from '../builders/loop-builder';
|
|
2
|
+
import { spawn } from '../builders/spawn-builder';
|
|
3
|
+
import { step } from '../builders/step-builders';
|
|
4
|
+
import { any } from '../until/combinators';
|
|
5
|
+
import { until } from '../until/predicates';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a ReAct (Reason + Act) agent loop: an LLM step with tools iterated until no tool calls or limits are hit.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
* @param opts - Model, tools, optional instructions, step/cost limits, and memory layers.
|
|
11
|
+
* @returns A `StepLoop` (no memory) or `StepSpawn` wrapping a loop (with memory).
|
|
12
|
+
*/
|
|
13
|
+
export function react(opts) {
|
|
14
|
+
const llmStep = step.llm({
|
|
15
|
+
id: 'react-step',
|
|
16
|
+
model: opts.model,
|
|
17
|
+
instructions: opts.instructions,
|
|
18
|
+
tools: opts.tools,
|
|
19
|
+
});
|
|
20
|
+
const loopStep = loop({
|
|
21
|
+
id: 'react-loop',
|
|
22
|
+
steps: [
|
|
23
|
+
llmStep,
|
|
24
|
+
],
|
|
25
|
+
until: any(until.noToolCalls(), until.maxSteps(opts.maxSteps ?? 10), ...(opts.maxCost
|
|
26
|
+
? [
|
|
27
|
+
until.maxCost(opts.maxCost),
|
|
28
|
+
]
|
|
29
|
+
: [])),
|
|
30
|
+
});
|
|
31
|
+
if (!opts.memory) {
|
|
32
|
+
return loopStep;
|
|
33
|
+
}
|
|
34
|
+
return spawn({
|
|
35
|
+
id: 'react-agent',
|
|
36
|
+
child: loopStep,
|
|
37
|
+
memory: opts.memory,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @public */
|
|
2
|
+
export { createInMemoryFsAdapter } from './adapters/in-memory-fs-adapter';
|
|
3
|
+
/** @public */
|
|
4
|
+
export { createInMemoryShellAdapter } from './adapters/in-memory-shell-adapter';
|
|
5
|
+
/** @public */
|
|
6
|
+
export { createInMemorySubprocessAdapter } from './adapters/in-memory-subprocess-adapter';
|
|
7
|
+
/** @public */
|
|
8
|
+
export { step } from './builders/step-builders';
|
|
9
|
+
/** @public */
|
|
10
|
+
export { tool, toolWithGenerator } from './builders/tool-builder';
|
|
11
|
+
/** @public */
|
|
12
|
+
export { durableTaskState } from './memory/layers/durable-task-state';
|
|
13
|
+
/** @public */
|
|
14
|
+
export { historyWindow } from './memory/layers/history-window';
|
|
15
|
+
/** @public */
|
|
16
|
+
export { observationalMemory } from './memory/layers/observational-memory';
|
|
17
|
+
/** @public */
|
|
18
|
+
export { planMemory } from './memory/layers/plan';
|
|
19
|
+
/** @public */
|
|
20
|
+
export { toolMemoryLayer } from './memory/layers/tool-memory-layer';
|
|
21
|
+
/** @public */
|
|
22
|
+
export { workingMemory } from './memory/layers/working-memory';
|
|
23
|
+
/** @public */
|
|
24
|
+
export { AgentHarness } from './runtime/agent-harness';
|
|
25
|
+
/** @public */
|
|
26
|
+
export { createInMemoryStorage } from './runtime/in-memory-storage';
|
package/dist/portable.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region Portable Adapters
|
|
2
|
+
/** @public */
|
|
3
|
+
export { createInMemoryFsAdapter } from './adapters/in-memory-fs-adapter';
|
|
4
|
+
/** @public */
|
|
5
|
+
export { createInMemoryShellAdapter } from './adapters/in-memory-shell-adapter';
|
|
6
|
+
/** @public */
|
|
7
|
+
export { createInMemorySubprocessAdapter } from './adapters/in-memory-subprocess-adapter';
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region Builders
|
|
10
|
+
/** @public */
|
|
11
|
+
export { step } from './builders/step-builders';
|
|
12
|
+
/** @public */
|
|
13
|
+
export { tool, toolWithGenerator } from './builders/tool-builder';
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region Memory Layers
|
|
16
|
+
/** @public */
|
|
17
|
+
export { durableTaskState } from './memory/layers/durable-task-state';
|
|
18
|
+
/** @public */
|
|
19
|
+
export { historyWindow } from './memory/layers/history-window';
|
|
20
|
+
/** @public */
|
|
21
|
+
export { observationalMemory } from './memory/layers/observational-memory';
|
|
22
|
+
/** @public */
|
|
23
|
+
export { planMemory } from './memory/layers/plan';
|
|
24
|
+
/** @public */
|
|
25
|
+
export { toolMemoryLayer } from './memory/layers/tool-memory-layer';
|
|
26
|
+
/** @public */
|
|
27
|
+
export { workingMemory } from './memory/layers/working-memory';
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region Runtime
|
|
30
|
+
/** @public */
|
|
31
|
+
export { AgentHarness } from './runtime/agent-harness';
|
|
32
|
+
/** @public */
|
|
33
|
+
export { createInMemoryStorage } from './runtime/in-memory-storage';
|
|
34
|
+
//#endregion
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { ZodType } from 'zod';
|
|
2
|
+
import type { LayerStateStore } from '../memory/layer-lifecycle';
|
|
3
|
+
import type { Channel, ChannelHandle, ExternalChannel } from '../types/channel';
|
|
4
|
+
import type { LLMResponse, LlmProviderConfig } from '../types/common';
|
|
5
|
+
import type { Context, CwdState } from '../types/context';
|
|
6
|
+
import type { DetachedHandle } from '../types/detached';
|
|
7
|
+
import type { FsAdapter } from '../types/fs-adapter';
|
|
8
|
+
import type { HarnessResponse, StreamEvent, StreamingItem } from '../types/harness-result';
|
|
9
|
+
import type { ExecuteInput, Item, ItemSchemaExtensions } from '../types/items';
|
|
10
|
+
import type { ContextMemory, MemoryLayer, StorageAdapter } from '../types/memory';
|
|
11
|
+
import type { Span, TraceExporter } from '../types/observability';
|
|
12
|
+
import type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, DeliveryMode, ExecuteOptions, HarnessStatus, RecallLayerOutput, SessionScope } from '../types/runtime';
|
|
13
|
+
import type { ShellAdapter } from '../types/shell-adapter';
|
|
14
|
+
import type { SteeringDecision } from '../types/steering';
|
|
15
|
+
import type { Step } from '../types/step';
|
|
16
|
+
import type { SubprocessAdapter } from '../types/subprocess-adapter';
|
|
17
|
+
import type { EventBroadcaster } from './event-broadcaster';
|
|
18
|
+
interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<string, unknown>> {
|
|
19
|
+
name: string;
|
|
20
|
+
initialStep?: Step<ContextMemory, string, string>;
|
|
21
|
+
/** Default memory layers applied to every context created via `createContext()` / `execute()`. */
|
|
22
|
+
memory?: MemoryLayer[];
|
|
23
|
+
storage?: StorageAdapter;
|
|
24
|
+
hooks?: AgentHooks;
|
|
25
|
+
params: TParams;
|
|
26
|
+
paramsSchema?: ZodType<TParams>;
|
|
27
|
+
/** Filesystem adapter. Defaults to local node:fs when not provided. */
|
|
28
|
+
fs?: FsAdapter;
|
|
29
|
+
/** Shell adapter. Defaults to local sh when not provided. */
|
|
30
|
+
shell?: ShellAdapter;
|
|
31
|
+
/** Subprocess adapter. Defaults to an in-memory, same-process adapter. */
|
|
32
|
+
subprocess?: SubprocessAdapter;
|
|
33
|
+
llm?: LlmProviderConfig;
|
|
34
|
+
/** Harness-wide item schema extensions. */
|
|
35
|
+
itemSchemas?: ItemSchemaExtensions;
|
|
36
|
+
/** Whether unknown extension item types must match a registered schema. Defaults to true. */
|
|
37
|
+
strictItemSchemas?: boolean;
|
|
38
|
+
traceExporter?: TraceExporter;
|
|
39
|
+
layerStateStore?: LayerStateStore;
|
|
40
|
+
/** Default delivery mode for messages that don't specify one. Defaults to `next-turn`. */
|
|
41
|
+
defaultDeliveryMode?: DeliveryMode;
|
|
42
|
+
/**
|
|
43
|
+
* Abort the in-flight model call if the provider stream emits no events for this
|
|
44
|
+
* many milliseconds. Defaults to `DEFAULT_STREAM_IDLE_TIMEOUT_MS` (120s).
|
|
45
|
+
* Pass `0` or a negative number to disable the watchdog.
|
|
46
|
+
*/
|
|
47
|
+
streamIdleTimeoutMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Initial working directory for the harness. Used as the seed value for the
|
|
50
|
+
* shared `cwdState.cwd` on every Context this harness creates, including
|
|
51
|
+
* those produced by spawn/fork. Defaults to `process.cwd()`.
|
|
52
|
+
*/
|
|
53
|
+
initialCwd?: string;
|
|
54
|
+
/** @internal Test-only escape hatch to inject a mock callModel implementation. */
|
|
55
|
+
_testCallModel?: (request: CallModelRequest) => Promise<LLMResponse>;
|
|
56
|
+
}
|
|
57
|
+
interface StreamIdleWatchdog {
|
|
58
|
+
/** Bump the deadline because a stream event just arrived. */
|
|
59
|
+
reset: () => void;
|
|
60
|
+
/** Clear the pending timer. Safe to call multiple times. */
|
|
61
|
+
stop: () => void;
|
|
62
|
+
}
|
|
63
|
+
/** @internal Create a watchdog that aborts `controller` when no
|
|
64
|
+
* {@link StreamIdleWatchdog.reset reset} is called within `timeoutMs`. When
|
|
65
|
+
* `timeoutMs <= 0`, returns an inert no-op so callers can always call `.reset()`
|
|
66
|
+
* / `.stop()` without a branch. Starts armed: the caller is responsible for
|
|
67
|
+
* `.stop()` in a `finally`. `onTimeout` runs before the abort so observers can
|
|
68
|
+
* emit a framework event with the original cause. Exported only for unit tests. */
|
|
69
|
+
export declare function createStreamIdleWatchdog(timeoutMs: number, controller: AbortController, onTimeout?: () => void): StreamIdleWatchdog;
|
|
70
|
+
/**
|
|
71
|
+
* Default agent harness for executing agent steps with built-in channel, memory, and trace support.
|
|
72
|
+
* Provides channel store, memory layer lifecycle, and trace export with no external dependencies.
|
|
73
|
+
*
|
|
74
|
+
* Messages submitted via `execute()` are enqueued on a per-thread session and
|
|
75
|
+
* processed by a `SessionRunner`. Consumers observe responses via the session-
|
|
76
|
+
* scoped accessors: `getAgentResponse`, `getItemStream`, etc.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare class AgentHarness<TParams extends Record<string, unknown> = Record<string, unknown>> implements AgentHarnessContract<TParams> {
|
|
81
|
+
readonly config: AgentConfig<TParams>;
|
|
82
|
+
readonly fs: FsAdapter;
|
|
83
|
+
readonly shell: ShellAdapter;
|
|
84
|
+
readonly subprocess: SubprocessAdapter;
|
|
85
|
+
private readonly initialStep?;
|
|
86
|
+
private readonly _memory?;
|
|
87
|
+
private readonly client?;
|
|
88
|
+
private readonly channelStore;
|
|
89
|
+
private readonly callModelOverride?;
|
|
90
|
+
private readonly defaultDeliveryMode;
|
|
91
|
+
private readonly streamIdleTimeoutMs;
|
|
92
|
+
private readonly sessions;
|
|
93
|
+
readonly layerStateStore: LayerStateStore;
|
|
94
|
+
readonly traceExporter: TraceExporter;
|
|
95
|
+
/**
|
|
96
|
+
* Long-lived shared cwd state. The same reference is seeded into every
|
|
97
|
+
* root Context this harness creates, so successive `run()` calls — and the
|
|
98
|
+
* TUI — observe each other's `cd`s.
|
|
99
|
+
*/
|
|
100
|
+
readonly rootCwdState: CwdState;
|
|
101
|
+
private readonly itemSchemas;
|
|
102
|
+
constructor(opts: AgentHarnessOpts<TParams>);
|
|
103
|
+
/**
|
|
104
|
+
* Update the harness-wide root cwd. The TUI calls this in response to a
|
|
105
|
+
* user-issued `! cd`, so the next root Context (and any tool inspecting
|
|
106
|
+
* `harness.rootCwdState.cwd`) observes the new value. Caller is responsible
|
|
107
|
+
* for passing an absolute, validated path.
|
|
108
|
+
*/
|
|
109
|
+
setRootCwd(nextCwd: string): void;
|
|
110
|
+
execute(input: ExecuteInput, options?: ExecuteOptions): Promise<void>;
|
|
111
|
+
getAgentResponse(scope?: SessionScope): Promise<HarnessResponse>;
|
|
112
|
+
getItemStream(scope?: SessionScope): AsyncIterable<StreamingItem>;
|
|
113
|
+
getTextStream(scope?: SessionScope): AsyncIterable<string>;
|
|
114
|
+
getReasoningStream(scope?: SessionScope): AsyncIterable<string>;
|
|
115
|
+
getFullStream(scope?: SessionScope): AsyncIterable<StreamEvent>;
|
|
116
|
+
abort(scope?: SessionScope & {
|
|
117
|
+
reason?: string;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
getStatus(scope?: SessionScope): HarnessStatus;
|
|
120
|
+
getQueueSize(scope?: SessionScope): number;
|
|
121
|
+
seedSessionHistory(threadId: string, items: ReadonlyArray<Item>): void;
|
|
122
|
+
private getOrCreateSession;
|
|
123
|
+
private requireSession;
|
|
124
|
+
callModel(request: CallModelRequest): Promise<LLMResponse>;
|
|
125
|
+
/** @internal Drain only messages tagged `between-rounds` from the queue. */
|
|
126
|
+
private drainBetweenRoundsMessages;
|
|
127
|
+
run<I, O>(s: Step<ContextMemory, I, O>, input: I, ctx: Context): Promise<O>;
|
|
128
|
+
/** Run all layer `init` hooks before the first step executes. Per spec 11,
|
|
129
|
+
* init MUST complete before any recall fires so layer state is populated. */
|
|
130
|
+
private initAndRun;
|
|
131
|
+
detachedSpawn<I, O>(s: Step<ContextMemory, I, O>, input: I, parentCtx: Context, overrides?: {
|
|
132
|
+
/** Override the child's thread id. Default inherits from `parentCtx.threadId`. */
|
|
133
|
+
threadId?: string;
|
|
134
|
+
/** Override the child's resource id. Default inherits from `parentCtx.resourceId`. */
|
|
135
|
+
resourceId?: string;
|
|
136
|
+
/** Override the child's initial cwd. Used by worktree isolation to root the child at the worktree path. */
|
|
137
|
+
cwdInit?: string;
|
|
138
|
+
}): DetachedHandle<O>;
|
|
139
|
+
createContext(opts?: {
|
|
140
|
+
parent?: Context;
|
|
141
|
+
items?: Item[];
|
|
142
|
+
state?: unknown;
|
|
143
|
+
threadId?: string;
|
|
144
|
+
resourceId?: string;
|
|
145
|
+
memory?: MemoryLayer[];
|
|
146
|
+
/**
|
|
147
|
+
* Initial cwd for the new context. When set, takes precedence over both
|
|
148
|
+
* the parent snapshot and the harness root cwd — used by worktree
|
|
149
|
+
* isolation to root a child agent at the worktree path.
|
|
150
|
+
*/
|
|
151
|
+
cwdInit?: string;
|
|
152
|
+
_broadcaster?: EventBroadcaster;
|
|
153
|
+
}): Context;
|
|
154
|
+
send<T>(channel: Channel<T>, value: T, _ctx: Context): void;
|
|
155
|
+
recv<T>(channel: Channel<T>, _ctx: Context, opts?: {
|
|
156
|
+
timeout?: number;
|
|
157
|
+
}): Promise<T>;
|
|
158
|
+
tryRecv<T>(channel: Channel<T>, _ctx: Context): T | null;
|
|
159
|
+
getChannelHandle<T>(channel: ExternalChannel<T>, executionId: string): ChannelHandle<T>;
|
|
160
|
+
/** Resolves layer-provided tools and merges with step tools into ctx.unifiedTools. */
|
|
161
|
+
private setUnifiedTools;
|
|
162
|
+
private toExecCtx;
|
|
163
|
+
initLayers(layers: MemoryLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
|
|
164
|
+
recallLayers(layers: MemoryLayer[], input: string, ctx: Context): Promise<RecallLayerOutput[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Compute the items array that would be sent to the model on the next turn —
|
|
167
|
+
* the same arrangement `executeLLM` builds: harness-level memory layers'
|
|
168
|
+
* recall outputs concatenated with the session's accumulated history.
|
|
169
|
+
*
|
|
170
|
+
* Read-mostly: `recallLayers` writes layer-state snapshots to
|
|
171
|
+
* `layerStateStore` exactly as a real turn would, so successive previews
|
|
172
|
+
* remain consistent with what the next real turn produces.
|
|
173
|
+
*/
|
|
174
|
+
previewRequestItems(scope?: SessionScope): Promise<ReadonlyArray<Item>>;
|
|
175
|
+
storeLayers(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<void>;
|
|
176
|
+
disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
|
|
177
|
+
checkpoint(_ctx: Context): Promise<void>;
|
|
178
|
+
restore(_executionId: string): Promise<Context | null>;
|
|
179
|
+
cancel(_ctx: Context, _reason?: string): Promise<void>;
|
|
180
|
+
createSpan(name: string, parent: Span | null): Span;
|
|
181
|
+
getLayerState<T>(executionId: string, layerId: string): T | undefined;
|
|
182
|
+
setLayerState<T>(executionId: string, layerId: string, state: T): void;
|
|
183
|
+
beforeToolCall(layers: MemoryLayer[], toolName: string, toolArgs: unknown, ctx: Context): Promise<SteeringDecision>;
|
|
184
|
+
afterModelCall(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<SteeringDecision>;
|
|
185
|
+
projectHistory(layers: MemoryLayer[], items: ReadonlyArray<Item>, ctx: Context): Promise<ReadonlyArray<Item>>;
|
|
186
|
+
runAppendPipeline(layers: MemoryLayer[], items: Item[], ctx: Context): Promise<{
|
|
187
|
+
items: Item[];
|
|
188
|
+
rerenderRequests: {
|
|
189
|
+
layerId: string;
|
|
190
|
+
slot: number;
|
|
191
|
+
timing: 'immediate' | 'batched';
|
|
192
|
+
scope: 'self' | 'slot-after' | 'all';
|
|
193
|
+
}[];
|
|
194
|
+
}>;
|
|
195
|
+
executeRerender(requests: {
|
|
196
|
+
layerId: string;
|
|
197
|
+
slot: number;
|
|
198
|
+
timing: 'immediate' | 'batched';
|
|
199
|
+
scope: 'self' | 'slot-after' | 'all';
|
|
200
|
+
}[], layers: MemoryLayer[], ctx: Context, budgets: Map<string, number>, query?: string): Promise<{
|
|
201
|
+
layerId: string;
|
|
202
|
+
items: Item[];
|
|
203
|
+
tokenCount: number;
|
|
204
|
+
}[]>;
|
|
205
|
+
}
|
|
206
|
+
export {};
|