@vib-rato/agent-core 0.16.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/CHANGELOG.md +852 -0
- package/README.md +493 -0
- package/dist/types/agent-loop.d.ts +229 -0
- package/dist/types/agent.d.ts +533 -0
- package/dist/types/append-only-context.d.ts +141 -0
- package/dist/types/attempt-scope.d.ts +84 -0
- package/dist/types/compaction/adaptive.d.ts +31 -0
- package/dist/types/compaction/branch-summarization.d.ts +103 -0
- package/dist/types/compaction/compaction.d.ts +330 -0
- package/dist/types/compaction/entries.d.ts +124 -0
- package/dist/types/compaction/errors.d.ts +26 -0
- package/dist/types/compaction/index.d.ts +12 -0
- package/dist/types/compaction/messages.d.ts +61 -0
- package/dist/types/compaction/openai.d.ts +65 -0
- package/dist/types/compaction/pruning.d.ts +130 -0
- package/dist/types/compaction/utils.d.ts +32 -0
- package/dist/types/compaction.d.ts +1 -0
- package/dist/types/harmony-leak.d.ts +100 -0
- package/dist/types/heap-eviction-retainers.test.d.ts +1 -0
- package/dist/types/image-placeholder-guard.d.ts +4 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/proxy.d.ts +95 -0
- package/dist/types/run-collector.d.ts +223 -0
- package/dist/types/run-resource-ledger.d.ts +2 -0
- package/dist/types/telemetry.d.ts +605 -0
- package/dist/types/thinking.d.ts +18 -0
- package/dist/types/tool-dispatch-identity.d.ts +27 -0
- package/dist/types/types.d.ts +790 -0
- package/package.json +72 -0
- package/src/agent-loop.ts +5632 -0
- package/src/agent.ts +2437 -0
- package/src/append-only-context.ts +496 -0
- package/src/attempt-scope.ts +195 -0
- package/src/compaction/adaptive.ts +92 -0
- package/src/compaction/branch-summarization.ts +358 -0
- package/src/compaction/compaction.ts +1569 -0
- package/src/compaction/entries.ts +158 -0
- package/src/compaction/errors.ts +31 -0
- package/src/compaction/index.ts +13 -0
- package/src/compaction/messages.ts +212 -0
- package/src/compaction/openai.ts +580 -0
- package/src/compaction/prompts/auto-handoff-threshold-focus.md +1 -0
- package/src/compaction/prompts/branch-summary-context.md +5 -0
- package/src/compaction/prompts/branch-summary-preamble.md +2 -0
- package/src/compaction/prompts/branch-summary.md +30 -0
- package/src/compaction/prompts/compaction-short-summary.md +9 -0
- package/src/compaction/prompts/compaction-summary-context.md +5 -0
- package/src/compaction/prompts/compaction-summary.md +38 -0
- package/src/compaction/prompts/compaction-turn-prefix.md +17 -0
- package/src/compaction/prompts/compaction-update-summary.md +45 -0
- package/src/compaction/prompts/file-operations.md +10 -0
- package/src/compaction/prompts/handoff-document.md +56 -0
- package/src/compaction/prompts/summarization-system.md +3 -0
- package/src/compaction/pruning.ts +1026 -0
- package/src/compaction/utils.ts +189 -0
- package/src/compaction.ts +1 -0
- package/src/harmony-leak.ts +457 -0
- package/src/heap-eviction-retainers.test.ts +293 -0
- package/src/image-placeholder-guard.ts +20 -0
- package/src/index.ts +23 -0
- package/src/prompts/escaped-nonascii-recovery.md +3 -0
- package/src/prompts/repeated-tool-failure-recovery.md +1 -0
- package/src/proxy.ts +408 -0
- package/src/run-collector.ts +728 -0
- package/src/run-resource-ledger.ts +345 -0
- package/src/telemetry.ts +2161 -0
- package/src/thinking.ts +20 -0
- package/src/tool-dispatch-identity.ts +87 -0
- package/src/types.ts +882 -0
package/src/thinking.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effort } from "@vib-rato/ai/model-thinking";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent-local thinking selector.
|
|
5
|
+
*
|
|
6
|
+
* `off` disables reasoning, while `inherit` defers to a higher-level selector.
|
|
7
|
+
*/
|
|
8
|
+
export const ThinkingLevel = {
|
|
9
|
+
Inherit: "inherit",
|
|
10
|
+
Off: "off",
|
|
11
|
+
Minimal: Effort.Minimal,
|
|
12
|
+
Low: Effort.Low,
|
|
13
|
+
Medium: Effort.Medium,
|
|
14
|
+
High: Effort.High,
|
|
15
|
+
XHigh: Effort.XHigh,
|
|
16
|
+
Max: Effort.Max,
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
export type ThinkingLevel = (typeof ThinkingLevel)[keyof typeof ThinkingLevel];
|
|
20
|
+
export type ResolvedThinkingLevel = Exclude<ThinkingLevel, "inherit">;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity of the tool object a `tool_execution_start` event was produced for.
|
|
3
|
+
*
|
|
4
|
+
* The producer already knows exactly which tool object it dispatched to: the agent loop
|
|
5
|
+
* resolves it once, from the run's immutable tool snapshot, before it emits anything. Any
|
|
6
|
+
* consumer that instead re-resolves `event.toolName` later reads a MUTABLE registry — a
|
|
7
|
+
* mid-run `setTools`, MCP reload, or tool refresh can hand the same wire name to a
|
|
8
|
+
* completely different object — and would then attribute the call to a tool that never
|
|
9
|
+
* ran.
|
|
10
|
+
*
|
|
11
|
+
* The binding is deliberately a side channel rather than an event field:
|
|
12
|
+
*
|
|
13
|
+
* - a tool object exposes `execute`, closures over session state, and its own
|
|
14
|
+
* description/parameters; putting it on `AgentEvent` would make it enumerable, walkable,
|
|
15
|
+
* and reachable by every serializer, wire envelope, and log sink that copies events, and
|
|
16
|
+
* `JSON.stringify(event)` would start emitting tool metadata;
|
|
17
|
+
* - the map is weak on the event object, so the association disappears with the event it
|
|
18
|
+
* describes and pins nothing alive;
|
|
19
|
+
* - it carries no arguments, no results, no call ids, and no timing — only object identity,
|
|
20
|
+
* which is exactly what provenance checks (`WeakSet.has`) need and nothing more.
|
|
21
|
+
*/
|
|
22
|
+
const dispatchedToolByEvent = new WeakMap<object, object>();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Record, at the producer boundary, the tool object this event was emitted for.
|
|
26
|
+
*
|
|
27
|
+
* A call with no resolved tool (an unknown name the loop is about to reject, or a call
|
|
28
|
+
* aborted before dispatch) binds nothing: there is no object, so there is nothing to prove.
|
|
29
|
+
*/
|
|
30
|
+
export function bindDispatchedToolIdentity(event: object, tool: object | undefined): void {
|
|
31
|
+
if (!tool) return;
|
|
32
|
+
dispatchedToolByEvent.set(event, tool);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The tool object this event was actually dispatched to, if its producer bound one. */
|
|
36
|
+
export function dispatchedToolIdentity(event: object): object | undefined {
|
|
37
|
+
return dispatchedToolByEvent.get(event);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Tool events emitted only to keep the stream's start/end PAIRING intact, for calls that
|
|
42
|
+
* were never dispatched.
|
|
43
|
+
*
|
|
44
|
+
* A skipped or aborted call still has to produce a result, and every consumer downstream
|
|
45
|
+
* is built around results arriving in pairs, so the loop synthesizes the missing start.
|
|
46
|
+
* That is a stream-shape obligation and nothing more: no `execute` ran, no work began, and
|
|
47
|
+
* no time was spent in a tool.
|
|
48
|
+
*
|
|
49
|
+
* Consumers that merely relay or record events are unaffected and must stay unaffected.
|
|
50
|
+
* Consumers that publish a claim about what is RUNNING are not: between the synthetic
|
|
51
|
+
* start and its end, such a consumer would report a tool as active that was never entered.
|
|
52
|
+
*
|
|
53
|
+
* A side channel rather than an `AgentEvent` field, for the same reasons the dispatched
|
|
54
|
+
* identity is one — no wire/schema surface to serialize, copy, or persist — and a `WeakSet`
|
|
55
|
+
* because the mark is meaningful only for the exact event object it was applied to.
|
|
56
|
+
*/
|
|
57
|
+
const nonDispatchedToolEvents = new WeakSet<object>();
|
|
58
|
+
|
|
59
|
+
/** Mark an event as pairing-only: emitted for a call the loop never dispatched. */
|
|
60
|
+
export function markNonDispatchedToolEvent(event: object): void {
|
|
61
|
+
nonDispatchedToolEvents.add(event);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Whether this exact event was synthesized for a call that never ran. */
|
|
65
|
+
export function isNonDispatchedToolEvent(event: object): boolean {
|
|
66
|
+
return nonDispatchedToolEvents.has(event);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Active tool a call name dispatches to. Tools emitted via OpenAI's custom-tool path
|
|
71
|
+
* (e.g. `apply_patch` on GPT-5) come back under their wire-level name, which may differ
|
|
72
|
+
* from the harness-internal `name`. Match on either, preferring `name` for determinism if
|
|
73
|
+
* both somehow collide.
|
|
74
|
+
*
|
|
75
|
+
* This is the single dispatch-matching rule: execution, external-event identity binding,
|
|
76
|
+
* and every "is this tool callable" check must agree, or a label can describe a tool the
|
|
77
|
+
* call would never have reached.
|
|
78
|
+
*/
|
|
79
|
+
export function activeToolForCallName<T extends { name: string; customWireName?: string }>(
|
|
80
|
+
tools: ReadonlyArray<T> | undefined,
|
|
81
|
+
callName: string,
|
|
82
|
+
): T | undefined {
|
|
83
|
+
return (
|
|
84
|
+
tools?.find(tool => tool.name === callName) ??
|
|
85
|
+
tools?.find(tool => tool.customWireName !== undefined && tool.customWireName === callName)
|
|
86
|
+
);
|
|
87
|
+
}
|