operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.4
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/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/runner.d.ts +21 -15
- package/dist/agent/runner.js +23 -26
- package/dist/agent/session.d.ts +67 -73
- package/dist/agent/session.js +170 -174
- package/dist/agent/workflow/tool.js +8 -21
- package/dist/capabilities/assembler.d.ts +6 -4
- package/dist/capabilities/assembler.js +10 -5
- package/dist/capabilities/background/index.js +33 -26
- package/dist/capabilities/capability-state.d.ts +5 -7
- package/dist/capabilities/capability-state.js +6 -4
- package/dist/capabilities/capability.d.ts +52 -40
- package/dist/capabilities/compaction/index.js +5 -4
- package/dist/capabilities/goal/index.d.ts +1 -0
- package/dist/capabilities/goal/index.js +13 -6
- package/dist/capabilities/index.d.ts +3 -3
- package/dist/capabilities/index.js +2 -2
- package/dist/capabilities/plan/index.js +12 -6
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +12 -0
- package/dist/capabilities/skills/index.js +38 -24
- package/dist/capabilities/skills/registry.d.ts +3 -4
- package/dist/capabilities/skills/registry.js +4 -7
- package/dist/capabilities/skills/service.js +1 -1
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +11 -5
- package/dist/capabilities/todo/index.js +12 -6
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/index.js +22 -16
- package/dist/capabilities/workflow/index.d.ts +4 -2
- package/dist/capabilities/workflow/index.js +14 -7
- package/dist/commands/index.js +6 -4
- package/dist/events/events.d.ts +2 -1
- package/dist/events/publisher.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +2 -0
- package/dist/loop/steer.d.ts +2 -0
- package/dist/loop/steer.js +7 -2
- package/dist/mcp/capability.js +22 -17
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +45 -2
- package/dist/mcp/manager.js +162 -11
- package/dist/plugins/index.js +10 -4
- package/dist/scope/index.d.ts +7 -0
- package/dist/scope/index.js +4 -0
- package/dist/scope/scope.d.ts +143 -0
- package/dist/scope/scope.js +406 -0
- package/dist/scope/token.d.ts +29 -0
- package/dist/scope/token.js +29 -0
- package/dist/scope/tokens.d.ts +98 -0
- package/dist/scope/tokens.js +63 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/origin.d.ts +9 -0
- package/dist/store/store.d.ts +6 -2
- package/dist/testing.d.ts +62 -0
- package/dist/testing.js +118 -0
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ import { asTaskRegistrar } from "../../capabilities/background/registrar.js";
|
|
|
15
15
|
import { newAgentId } from "../subagent.js";
|
|
16
16
|
import { guardSubagentInput } from "../subagent-tools.js";
|
|
17
17
|
import { createWorktree } from "../worktree.js";
|
|
18
|
-
import { runWorkflow, parseWorkflow, WorkflowJournal, journalAddress,
|
|
18
|
+
import { runWorkflow, parseWorkflow, WorkflowJournal, journalAddress, workflowPrompt, makeStructuredOutputTool, cloneAgentWithTool, validateValue, structuredInstruction, WORKFLOW_AGENT_TIMEOUT_MS, } from "./index.js";
|
|
19
19
|
/**
|
|
20
20
|
* The Workflow tool — a deterministic JS orchestration runtime over subagents.
|
|
21
21
|
* The script runs in a hardened VM (see workflow/sandbox.ts); its agent() hook spawns
|
|
@@ -179,7 +179,7 @@ export function buildWorkflowTool(spawner, parent) {
|
|
|
179
179
|
(args.script === undefined || args.script.trim().length === 0) &&
|
|
180
180
|
(args.name === undefined || args.name.length === 0);
|
|
181
181
|
if (resumeId !== undefined && resumeId.length > 0 && noExplicitSource) {
|
|
182
|
-
const priorJournal =
|
|
182
|
+
const priorJournal = parent.session.newWorkflowJournal(resumeId, ctx.toolCallId);
|
|
183
183
|
await priorJournal.load();
|
|
184
184
|
const recorded = priorJournal.recordedScript();
|
|
185
185
|
if (recorded === undefined) {
|
|
@@ -218,13 +218,12 @@ export function buildWorkflowTool(spawner, parent) {
|
|
|
218
218
|
// script. Goes through the Machine → on a server it lands in the sandbox, never the
|
|
219
219
|
// host disk. Best-effort: a persist failure never fails the run (path is left undefined).
|
|
220
220
|
const persistedScriptPath = await persistRunScript(ctx.machine, meta.name, runId, script);
|
|
221
|
-
// Resume journals
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
const
|
|
227
|
-
const mkJournal = (id) => wf.newJournal(id, ctx.toolCallId);
|
|
221
|
+
// Resume journals come from the session port: the workflow capability's manager, or
|
|
222
|
+
// the in-memory fallback Session.open provides when no capability is attached — either
|
|
223
|
+
// way bound to the session's store. Discovery needs no writes: the tool results below
|
|
224
|
+
// carry the run's lifecycle in `details`, and the `/workflows` list is a fold over the
|
|
225
|
+
// conversation (snapshot.ts).
|
|
226
|
+
const mkJournal = (id) => parent.session.newWorkflowJournal(id, ctx.toolCallId);
|
|
228
227
|
// Timestamps are stamped HOST-side (Date.now is banned only inside the sandbox).
|
|
229
228
|
const startedAt = new Date().toISOString();
|
|
230
229
|
const runDetails = (status, endedAt, outputTokens) => ({
|
|
@@ -554,16 +553,4 @@ function safeJsonStringify(value) {
|
|
|
554
553
|
return String(value);
|
|
555
554
|
}
|
|
556
555
|
}
|
|
557
|
-
// One fallback per session (not per run): resume journals of every workflow run in the
|
|
558
|
-
// session must land in the same store. Keyed by the session object's identity (the port
|
|
559
|
-
// is the same Session instance across every frame of a session).
|
|
560
|
-
const fallbackWorkflowManagers = new WeakMap();
|
|
561
|
-
function fallbackWorkflowManagerFor(session) {
|
|
562
|
-
let manager = fallbackWorkflowManagers.get(session);
|
|
563
|
-
if (manager === undefined) {
|
|
564
|
-
manager = new WorkflowManager(session.store);
|
|
565
|
-
fallbackWorkflowManagers.set(session, manager);
|
|
566
|
-
}
|
|
567
|
-
return manager;
|
|
568
|
-
}
|
|
569
556
|
//# sourceMappingURL=tool.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BeforeRunHook, LoopHooks, ShouldContinueAfterStopHook } from "../loop/types.ts";
|
|
2
2
|
import type { Tool } from "../tool/types.ts";
|
|
3
|
-
import type { AssembledGates, Capability,
|
|
3
|
+
import type { AssembledGates, Capability, RunContext, CapabilityDiagnostic } from "./capability.ts";
|
|
4
4
|
import { InjectionManager } from "./injection.ts";
|
|
5
5
|
export interface AssembleCapabilitiesOptions {
|
|
6
6
|
/** Max time to wait for a single capability's start(). Default 10s. */
|
|
@@ -14,7 +14,7 @@ export declare class AssembledCapabilities {
|
|
|
14
14
|
readonly boundaryContinuations: ShouldContinueAfterStopHook[];
|
|
15
15
|
readonly runStarts: BeforeRunHook[];
|
|
16
16
|
/**
|
|
17
|
-
* Stable arrays handed to `
|
|
17
|
+
* Stable arrays handed to `RunContext.gates`. Capabilities are started and absorbed one
|
|
18
18
|
* at a time, so a consumer that snapshotted at `start()` would miss every gate registered by a
|
|
19
19
|
* capability ordered after it — reading through this live reference avoids depending on order.
|
|
20
20
|
*/
|
|
@@ -26,7 +26,9 @@ export declare class AssembledCapabilities {
|
|
|
26
26
|
private readonly started;
|
|
27
27
|
private readonly ctx;
|
|
28
28
|
private readonly stopTimeoutMs;
|
|
29
|
-
constructor(
|
|
29
|
+
constructor(base: Omit<RunContext, "injection" | "gates">, options?: AssembleCapabilitiesOptions);
|
|
30
|
+
/** The run context handed to every capability's `start` and tool provider. */
|
|
31
|
+
get context(): RunContext;
|
|
30
32
|
listTools(): Promise<Tool[]>;
|
|
31
33
|
/** Apply every capability's tool filter in registration order. A thrower is skipped. */
|
|
32
34
|
applyToolFilters(tools: readonly Tool[]): readonly Tool[];
|
|
@@ -35,5 +37,5 @@ export declare class AssembledCapabilities {
|
|
|
35
37
|
stop(): Promise<void>;
|
|
36
38
|
_absorb(capability: Capability): void;
|
|
37
39
|
}
|
|
38
|
-
export declare function assembleCapabilities(capabilities: readonly Capability[], ctx:
|
|
40
|
+
export declare function assembleCapabilities(capabilities: readonly Capability[], ctx: Omit<RunContext, "injection" | "gates">, options?: AssembleCapabilitiesOptions): Promise<AssembledCapabilities>;
|
|
39
41
|
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -7,7 +7,7 @@ export class AssembledCapabilities {
|
|
|
7
7
|
boundaryContinuations = [];
|
|
8
8
|
runStarts = [];
|
|
9
9
|
/**
|
|
10
|
-
* Stable arrays handed to `
|
|
10
|
+
* Stable arrays handed to `RunContext.gates`. Capabilities are started and absorbed one
|
|
11
11
|
* at a time, so a consumer that snapshotted at `start()` would miss every gate registered by a
|
|
12
12
|
* capability ordered after it — reading through this live reference avoids depending on order.
|
|
13
13
|
*/
|
|
@@ -19,10 +19,14 @@ export class AssembledCapabilities {
|
|
|
19
19
|
started = [];
|
|
20
20
|
ctx;
|
|
21
21
|
stopTimeoutMs;
|
|
22
|
-
constructor(
|
|
23
|
-
this.ctx =
|
|
22
|
+
constructor(base, options = {}) {
|
|
23
|
+
this.ctx = { ...base, injection: this.injection, gates: this.gates };
|
|
24
24
|
this.stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;
|
|
25
25
|
}
|
|
26
|
+
/** The run context handed to every capability's `start` and tool provider. */
|
|
27
|
+
get context() {
|
|
28
|
+
return this.ctx;
|
|
29
|
+
}
|
|
26
30
|
async listTools() {
|
|
27
31
|
const tools = [...this.staticTools];
|
|
28
32
|
for (const provider of this.toolProviders) {
|
|
@@ -114,8 +118,9 @@ export async function assembleCapabilities(capabilities, ctx, options = {}) {
|
|
|
114
118
|
const assembled = new AssembledCapabilities(ctx, options);
|
|
115
119
|
const startTimeoutMs = options.startTimeoutMs ?? START_TIMEOUT_MS;
|
|
116
120
|
const seenNames = new Set();
|
|
117
|
-
//
|
|
118
|
-
|
|
121
|
+
// The live injection manager + gate arrays ride along so a capability like compaction can
|
|
122
|
+
// resync injector watermarks after collapsing the prefix.
|
|
123
|
+
const startCtx = assembled.context;
|
|
119
124
|
for (const capability of capabilities) {
|
|
120
125
|
if (seenNames.has(capability.name)) {
|
|
121
126
|
assembled.diagnostics.push({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { T } from "../../scope/tokens.js";
|
|
1
2
|
import { BackgroundManager } from "./manager.js";
|
|
2
3
|
import { StoreBackgroundTaskPersistence } from "./persist.js";
|
|
3
4
|
import { DiskBackgroundTaskPersistence } from "./persist-disk.js";
|
|
@@ -18,32 +19,38 @@ export function backgroundCapability(manager = new BackgroundManager()) {
|
|
|
18
19
|
// every task id it successfully spawned, while cold recovery injects ids whose ack was lost;
|
|
19
20
|
// exposing an unbounded list invites unrelated historical tasks into the reasoning path.
|
|
20
21
|
tools: [backgroundOutputTool(manager), backgroundStopTool(manager)],
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
provides: [
|
|
23
|
+
{
|
|
24
|
+
token: T.Background,
|
|
25
|
+
create: async (ctx) => {
|
|
26
|
+
// Each task's status is now durably recorded in a dedicated per-task store (disk
|
|
27
|
+
// sessions get the `<sessionDir>/tasks/<id>/` layout; other backends use KV state),
|
|
28
|
+
// so a task orphaned by a dead process can be reconciled to `lost` on reopen. Loading
|
|
29
|
+
// + reconcile happen in the store-cutover step; here we attach the persistence so live
|
|
30
|
+
// spawns start recording. Without a durable store the manager stays purely in memory.
|
|
31
|
+
const store = ctx.scope.get(T.Store);
|
|
32
|
+
manager.attach({
|
|
33
|
+
steer: ctx.scope.require(T.Steer),
|
|
34
|
+
events: ctx.scope.require(T.Events),
|
|
35
|
+
sessionId: ctx.sessionId,
|
|
36
|
+
persistence: makeTaskPersistence(store),
|
|
37
|
+
// Shard-backed output (a sub-agent's conversation) is read back from here rather than
|
|
38
|
+
// copied into the task, so the manager needs the log itself, not just the task store.
|
|
39
|
+
...(store !== undefined ? { store } : {}),
|
|
40
|
+
});
|
|
41
|
+
// Load prior-process task records so reconcile (triggered on first run via
|
|
42
|
+
// session.reconcileSubagents) can reclassify any that were left non-terminal.
|
|
43
|
+
await manager.loadFromDisk();
|
|
44
|
+
return manager;
|
|
45
|
+
},
|
|
46
|
+
// Only releases the event subscription taken in `create`. Running tasks are
|
|
47
|
+
// deliberately NOT stopped here: closing a session releases resources, it does not cancel
|
|
48
|
+
// work, and `attach` is last-writer-wins anyway.
|
|
49
|
+
dispose: () => {
|
|
50
|
+
manager.detachRuntime();
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
47
54
|
};
|
|
48
55
|
}
|
|
49
56
|
/** Disk sessions co-locate the task store under their home dir; every other
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { AgentRecord, SessionStore } from "../store/index.ts";
|
|
2
|
+
import type { ProvisionContext } from "./capability.ts";
|
|
2
3
|
/** The whole linear log in append order, or [] when there is no store / empty session. */
|
|
3
4
|
export declare function readLog(store: SessionStore | undefined): Promise<AgentRecord[]>;
|
|
4
|
-
/** The session's records for a capability's
|
|
5
|
-
*
|
|
6
|
-
* falling back to a direct `readLog`
|
|
7
|
-
export declare function readSessionLog(ctx:
|
|
8
|
-
readonly store?: SessionStore;
|
|
9
|
-
readonly logRecords?: () => Promise<readonly AgentRecord[]>;
|
|
10
|
-
}): Promise<readonly AgentRecord[]>;
|
|
5
|
+
/** The session's records for a capability's provision: the memoized `T.SessionLog` reader the
|
|
6
|
+
* session shares across capabilities (one read for goal/plan/todo + the context replay),
|
|
7
|
+
* falling back to a direct `readLog` of `T.Store` when a test-built scope has none. */
|
|
8
|
+
export declare function readSessionLog(ctx: ProvisionContext): Promise<readonly AgentRecord[]>;
|
|
11
9
|
/** The `details` of the latest tool result for `toolName` in the log, or undefined. */
|
|
12
10
|
export declare function latestToolDetails(records: readonly AgentRecord[], toolName: string): unknown;
|
|
13
11
|
//# sourceMappingURL=capability-state.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { T } from "../scope/tokens.js";
|
|
1
2
|
// Capability state lives in the linear session log, not in a side channel: a stateful capability
|
|
2
3
|
// writes its state snapshot into the `details` of the tool result that changed it, and rebuilds
|
|
3
4
|
// its in-memory state by folding the shard's records on session open. This keeps the state
|
|
@@ -11,11 +12,12 @@ export async function readLog(store) {
|
|
|
11
12
|
records.push(record);
|
|
12
13
|
return records;
|
|
13
14
|
}
|
|
14
|
-
/** The session's records for a capability's
|
|
15
|
-
*
|
|
16
|
-
* falling back to a direct `readLog`
|
|
15
|
+
/** The session's records for a capability's provision: the memoized `T.SessionLog` reader the
|
|
16
|
+
* session shares across capabilities (one read for goal/plan/todo + the context replay),
|
|
17
|
+
* falling back to a direct `readLog` of `T.Store` when a test-built scope has none. */
|
|
17
18
|
export function readSessionLog(ctx) {
|
|
18
|
-
|
|
19
|
+
const reader = ctx.scope.get(T.SessionLog);
|
|
20
|
+
return reader !== undefined ? reader() : readLog(ctx.scope.get(T.Store) ?? ctx.scope.get(T.StoreBackend));
|
|
19
21
|
}
|
|
20
22
|
/** Tool-result messages for `toolName` in the log, in append order. */
|
|
21
23
|
function toolResultsInLog(records, toolName) {
|
|
@@ -2,23 +2,19 @@ import type { LoopHooks } from "../loop/types.ts";
|
|
|
2
2
|
import type { PermissionPolicy } from "../permission/types.ts";
|
|
3
3
|
import type { Message } from "../protocol/index.ts";
|
|
4
4
|
import type { Tool } from "../tool/types.ts";
|
|
5
|
-
import type { Machine } from "../tool/machine.ts";
|
|
6
|
-
import type { BackgroundSpawner } from "../tool/background.ts";
|
|
7
|
-
import type { EventSink } from "../events/index.ts";
|
|
8
|
-
import type { AgentRecord, SessionStore } from "../store/index.ts";
|
|
9
|
-
import type { SteerBus } from "../loop/steer.ts";
|
|
10
|
-
import type { Responder } from "../permission/types.ts";
|
|
11
5
|
import type { Injector } from "./injection.ts";
|
|
12
6
|
import type { ToolProvider } from "./tool-provider.ts";
|
|
13
|
-
import type { Logger } from "../logging/index.ts";
|
|
14
7
|
import type { ChatModel } from "../llm/define-model.ts";
|
|
15
8
|
import type { ThinkingLevel } from "../llm/model.ts";
|
|
16
9
|
import type { ContextBreakdown } from "../agent/context-report.ts";
|
|
17
10
|
import type { CompactRequestOptions, PendingCompaction } from "./compaction/index.ts";
|
|
11
|
+
import type { Scope } from "../scope/scope.ts";
|
|
12
|
+
import type { Token } from "../scope/token.ts";
|
|
18
13
|
/**
|
|
19
14
|
* The narrow slice of the owning Session a capability may ACT on (as opposed to observe).
|
|
20
|
-
* Implemented by `Session`; handed to capabilities that
|
|
21
|
-
* just watching it — today the extension runtime's
|
|
15
|
+
* Implemented by `Session`; registered as `T.SessionControls` and handed to capabilities that
|
|
16
|
+
* participate in the run rather than just watching it — today the extension runtime's
|
|
17
|
+
* `ctx.actions`.
|
|
22
18
|
*
|
|
23
19
|
* Deliberately narrow: everything here is already a public Session operation, so nothing new
|
|
24
20
|
* becomes reachable — a capability simply gets a typed handle instead of the whole Session.
|
|
@@ -27,9 +23,9 @@ import type { CompactRequestOptions, PendingCompaction } from "./compaction/inde
|
|
|
27
23
|
*/
|
|
28
24
|
export interface SessionControls {
|
|
29
25
|
/**
|
|
30
|
-
* Cancel work. Scope depends on where the controls came from: from a `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
26
|
+
* Cancel work. Scope depends on where the controls came from: from a `RunContext` (per run)
|
|
27
|
+
* this aborts THAT run and leaves the session usable; from `T.SessionControls` it aborts the
|
|
28
|
+
* session. Either way the affected run(s) settle as `status: "aborted"`.
|
|
33
29
|
*/
|
|
34
30
|
abort(reason?: string): void;
|
|
35
31
|
compact(options?: CompactRequestOptions): Promise<PendingCompaction>;
|
|
@@ -37,38 +33,48 @@ export interface SessionControls {
|
|
|
37
33
|
setModel(model: string | ChatModel): void;
|
|
38
34
|
setThinking(level: ThinkingLevel): void;
|
|
39
35
|
}
|
|
40
|
-
|
|
36
|
+
/**
|
|
37
|
+
* What a capability's `Provision.create` receives: the session scope (everything the session
|
|
38
|
+
* registered — `T.Machine`, `T.Store`, `T.Events`, `T.Steer`, `T.SessionLog`,
|
|
39
|
+
* `T.SessionControls`, plus whatever earlier capabilities provided) and the two values every
|
|
40
|
+
* provision needs. Everything else is a `ctx.scope.get(T.…)` away.
|
|
41
|
+
*/
|
|
42
|
+
export interface ProvisionContext {
|
|
43
|
+
readonly scope: Scope<"session">;
|
|
44
|
+
readonly sessionId: string;
|
|
45
|
+
/** The session's signal (aborts when the session is cancelled). */
|
|
46
|
+
readonly signal: AbortSignal;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A service a capability contributes, declaring where it lives (the token's scope), how it is
|
|
50
|
+
* built and how it is torn down. `Session.open` runs `create` for each capability in order and
|
|
51
|
+
* registers the result under `token`; `scope.close()` disposes it in reverse registration order.
|
|
52
|
+
*
|
|
53
|
+
* `create` may be async (it typically folds the session log, attaches to the store, or connects
|
|
54
|
+
* to something). `dispose` defaults to `instance.close()` when present.
|
|
55
|
+
*/
|
|
56
|
+
export interface Provision<T = unknown> {
|
|
57
|
+
/** Session-tier by contract: a provision lives exactly as long as the session. */
|
|
58
|
+
readonly token: Token<T, "session">;
|
|
59
|
+
create(ctx: ProvisionContext): T | Promise<T>;
|
|
60
|
+
dispose?(instance: T): void | Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/** What a capability's per-run `start` (and its tool providers) receive. */
|
|
63
|
+
export interface RunContext {
|
|
64
|
+
readonly scope: Scope<"session">;
|
|
41
65
|
readonly sessionId: string;
|
|
42
|
-
|
|
43
|
-
readonly store?: SessionStore;
|
|
44
|
-
readonly events?: EventSink;
|
|
45
|
-
readonly responder?: Responder;
|
|
66
|
+
/** Aborts when this RUN is cancelled (downstream of the session signal). */
|
|
46
67
|
readonly signal: AbortSignal;
|
|
47
|
-
readonly
|
|
48
|
-
readonly injection?: import("./injection.ts").InjectionManager;
|
|
49
|
-
readonly steer?: SteerBus;
|
|
50
|
-
readonly logger?: Logger;
|
|
51
|
-
readonly controls?: SessionControls;
|
|
68
|
+
readonly injection: import("./injection.ts").InjectionManager;
|
|
52
69
|
/** Gates contributed by every capability in this run, for whoever needs to consult them. */
|
|
53
|
-
readonly gates
|
|
70
|
+
readonly gates: AssembledGates;
|
|
71
|
+
/** Same operations as the session's controls, except `abort` is scoped to this run. */
|
|
72
|
+
readonly controls: SessionControls;
|
|
54
73
|
}
|
|
55
74
|
/** Collected gate implementations, in capability registration order. */
|
|
56
75
|
export interface AssembledGates {
|
|
57
76
|
readonly compaction: readonly CompactionGate[];
|
|
58
77
|
}
|
|
59
|
-
export interface SessionContext {
|
|
60
|
-
readonly sessionId: string;
|
|
61
|
-
readonly machine: Machine;
|
|
62
|
-
readonly store?: SessionStore;
|
|
63
|
-
readonly events: EventSink;
|
|
64
|
-
readonly signal: AbortSignal;
|
|
65
|
-
readonly steer: SteerBus;
|
|
66
|
-
readonly controls?: SessionControls;
|
|
67
|
-
/** The session's records (append order), read once at open and memoized, so log-fold
|
|
68
|
-
* capabilities (goal/plan/todo) share one read instead of each calling `readLog`.
|
|
69
|
-
* Use `readSessionLog(ctx)` — it falls back to a direct read when this is absent. */
|
|
70
|
-
readonly logRecords?: () => Promise<readonly AgentRecord[]>;
|
|
71
|
-
}
|
|
72
78
|
/**
|
|
73
79
|
* Narrows the assembled toolset just before a turn runs. The mirror image of `toolProviders`:
|
|
74
80
|
* providers add, filters remove. Called once per turn with the complete registry (agent tools ∪
|
|
@@ -114,6 +120,13 @@ export type CompactionGate = (ctx: CompactionGateContext) => Promise<CompactionG
|
|
|
114
120
|
export interface CapabilityGates {
|
|
115
121
|
compaction?: CompactionGate;
|
|
116
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* A detachable part of the engine. Two tiers of lifecycle:
|
|
125
|
+
* - SESSION — `provides`: the services this capability contributes for the session's lifetime,
|
|
126
|
+
* each registered in the session scope by `Session.open` and disposed by `scope.close()`.
|
|
127
|
+
* - RUN — `start` / `stop`: per-run wiring, driven by the assembler.
|
|
128
|
+
* Everything else (tools, hooks, injectors, policies, gates) is static contribution.
|
|
129
|
+
*/
|
|
117
130
|
export interface Capability {
|
|
118
131
|
readonly name: string;
|
|
119
132
|
readonly tools?: readonly Tool[];
|
|
@@ -124,17 +137,16 @@ export interface Capability {
|
|
|
124
137
|
readonly policies?: readonly PermissionPolicy[];
|
|
125
138
|
readonly hooks?: Partial<LoopHooks>;
|
|
126
139
|
readonly injectors?: readonly Injector[];
|
|
127
|
-
|
|
140
|
+
/** Session-lived services, in dependency order. See {@link Provision}. */
|
|
141
|
+
readonly provides?: readonly Provision[];
|
|
128
142
|
/** Per-run startup. `signal` aborts when the assembler's start timeout expires — the
|
|
129
143
|
* timeout itself still wins the race (the capability is marked absent), but a
|
|
130
144
|
* signal-respecting implementation can release whatever it was holding. */
|
|
131
|
-
start?(ctx:
|
|
145
|
+
start?(ctx: RunContext, signal?: AbortSignal): Promise<void> | void;
|
|
132
146
|
/** Per-run teardown. `signal` aborts when the stop timeout expires; the run does not
|
|
133
147
|
* wait past the timeout either way, so use the signal to abandon slow flushes
|
|
134
148
|
* instead of leaking them into the background. */
|
|
135
149
|
stop?(signal?: AbortSignal): Promise<void> | void;
|
|
136
|
-
openSession?(ctx: SessionContext): Promise<void> | void;
|
|
137
|
-
closeSession?(): Promise<void> | void;
|
|
138
150
|
}
|
|
139
151
|
export interface CapabilityDiagnostic {
|
|
140
152
|
readonly capability: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { T } from "../../scope/tokens.js";
|
|
1
2
|
import { APIContextOverflowError } from "../../llm/errors.js";
|
|
2
3
|
import { noopLogger } from "../../logging/index.js";
|
|
3
4
|
import { CompactionStrategy, DEFAULT_COMPACTION_CONFIG } from "./strategy.js";
|
|
@@ -88,7 +89,7 @@ export function compactionCapability(options) {
|
|
|
88
89
|
};
|
|
89
90
|
return {
|
|
90
91
|
name: "compaction",
|
|
91
|
-
service,
|
|
92
|
+
provides: [{ token: T.Compaction, create: () => service }],
|
|
92
93
|
hooks: {
|
|
93
94
|
beforeStep: async (ctx) => {
|
|
94
95
|
maxOutputTokens = ctx.model.maxOutputTokens;
|
|
@@ -134,9 +135,9 @@ export function compactionCapability(options) {
|
|
|
134
135
|
},
|
|
135
136
|
start: (ctx) => {
|
|
136
137
|
injection = ctx.injection;
|
|
137
|
-
gates = ctx.gates
|
|
138
|
-
events = ctx.
|
|
139
|
-
logger = ctx.
|
|
138
|
+
gates = ctx.gates.compaction;
|
|
139
|
+
events = ctx.scope.get(T.Events);
|
|
140
|
+
logger = ctx.scope.get(T.Logger) ?? noopLogger;
|
|
140
141
|
sessionId = ctx.sessionId;
|
|
141
142
|
lastAssistantAtMs = Date.now();
|
|
142
143
|
},
|
|
@@ -2,5 +2,6 @@ import type { Capability } from "../capability.ts";
|
|
|
2
2
|
import { GoalStore } from "./goal-store.ts";
|
|
3
3
|
export { GoalStore } from "./goal-store.ts";
|
|
4
4
|
export type { GoalSnapshot, GoalStatus, GoalBudget, GoalPersisted, GoalDetails } from "./goal-store.ts";
|
|
5
|
+
/** `store` may be pre-built by an embedder (or a test) that wants to hold the instance. */
|
|
5
6
|
export declare function goalCapability(store?: GoalStore): Capability;
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readSessionLog } from "../capability-state.js";
|
|
2
|
+
import { T } from "../../scope/tokens.js";
|
|
2
3
|
import { GoalStore } from "./goal-store.js";
|
|
3
4
|
import { getGoalTool, setGoalBudgetTool, updateGoalTool } from "./tools.js";
|
|
4
5
|
import { GoalInjector } from "./injector.js";
|
|
@@ -14,18 +15,24 @@ function goalDriver(store) {
|
|
|
14
15
|
return { continue: store.isActive() };
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
/** `store` may be pre-built by an embedder (or a test) that wants to hold the instance. */
|
|
17
19
|
export function goalCapability(store = new GoalStore()) {
|
|
18
20
|
return {
|
|
19
21
|
name: "goal",
|
|
20
22
|
tools: [updateGoalTool(store), getGoalTool(store), setGoalBudgetTool(store)],
|
|
21
|
-
service: store,
|
|
22
23
|
injectors: [new GoalInjector(store)],
|
|
23
24
|
hooks: { shouldContinueAfterStop: goalDriver(store) },
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
provides: [
|
|
26
|
+
{
|
|
27
|
+
token: T.Goal,
|
|
28
|
+
// Rebuild the goal (incl. turn/token counters) by replaying the session log, so resume
|
|
29
|
+
// and fork restore it instead of starting from an empty in-memory store.
|
|
30
|
+
create: async (ctx) => {
|
|
31
|
+
store.reconstruct(await readSessionLog(ctx));
|
|
32
|
+
return store;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
29
36
|
};
|
|
30
37
|
}
|
|
31
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type { AssembledGates, Capability,
|
|
1
|
+
export type { AssembledGates, Capability, CapabilityDiagnostic, CapabilityGates, CompactionGate, CompactionGateContext, CompactionGateResult, Provision, ProvisionContext, RunContext, SessionControls, ToolFilter, } from "./capability.ts";
|
|
2
2
|
export type { Injector, InjectionContext, InjectionResult, InjectionAppender } from "./injection.ts";
|
|
3
3
|
export { BoundaryInjector, InjectionManager, systemReminder } from "./injection.ts";
|
|
4
|
-
export { readLog } from "./capability-state.ts";
|
|
4
|
+
export { readLog, readSessionLog } from "./capability-state.ts";
|
|
5
5
|
export type { ToolProvider } from "./tool-provider.ts";
|
|
6
6
|
export { staticToolProvider, tagToolSource, toolSource } from "./tool-provider.ts";
|
|
7
7
|
export { planCapability, PlanMode } from "./plan/index.ts";
|
|
@@ -20,6 +20,6 @@ export { userHooksCapability, HookEngine, HOOK_EVENT_TYPES } from "./user-hooks/
|
|
|
20
20
|
export type { HookDef, HookEventType } from "./user-hooks/index.ts";
|
|
21
21
|
export { backgroundCapability, BackgroundManager, CommandBackgroundTask, AgentBackgroundTask, WorkflowBackgroundTask, QuestionBackgroundTask, backgroundListTool, backgroundOutputTool, backgroundStopTool, TERMINAL_STATUSES, isBackgroundTaskTerminal, StoreBackgroundTaskPersistence, DiskBackgroundTaskPersistence, isPersistedTaskTerminal, isValidPersistedTask, } from "./background/index.ts";
|
|
22
22
|
export type { BackgroundManagerOptions, BackgroundManagerRuntime, BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot, BackgroundTask, BackgroundTaskInfo, BackgroundTaskInfoBase, BackgroundTaskSink, BackgroundTaskSettlement, BackgroundTaskSettlementStatus, BackgroundTaskStatus, CommandBackgroundTaskInfo, AgentBackgroundTaskInfo, AgentBackgroundTaskOptions, WorkflowBackgroundTaskInfo, WorkflowBackgroundTaskOptions, QuestionBackgroundTaskInfo, QuestionBackgroundTaskOptions, BackgroundTaskPersistence, PersistedTask, TaskOutputRef, TaskOutputLocation, } from "./background/index.ts";
|
|
23
|
-
export { skillsCapability, SkillRegistry, SkillNotFoundError, SkillCatalogInjector, skillTool, flowSkillProvider, flowSkillToolName, resolveSkillRoots, discoverSkills, parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError, normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./skills/index.ts";
|
|
23
|
+
export { skillsCapability, loadSkillRoots, SkillRegistry, SkillNotFoundError, SkillCatalogInjector, skillTool, flowSkillProvider, flowSkillToolName, resolveSkillRoots, discoverSkills, parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError, normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./skills/index.ts";
|
|
24
24
|
export type { SkillsOptions, SkillCatalog, SkillDefinition, SkillMetadata, SkillSource, SkillSummary, SkillRoot, SkillPluginContext, SkippedSkill, FlowSkillExecutor, FlowSkillRequest, SkillRegistryOptions, ResolveSkillRootsOptions, DiscoverSkillsOptions, } from "./skills/index.ts";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BoundaryInjector, InjectionManager, systemReminder } from "./injection.js";
|
|
2
|
-
export { readLog } from "./capability-state.js";
|
|
2
|
+
export { readLog, readSessionLog } from "./capability-state.js";
|
|
3
3
|
export { staticToolProvider, tagToolSource, toolSource } from "./tool-provider.js";
|
|
4
4
|
// Extensions are a HARNESS concept and live in `operon-agents` — core deliberately knows
|
|
5
5
|
// nothing about them. What an extension runtime is built out of is all here: `Capability`,
|
|
@@ -18,5 +18,5 @@ export { taskCapability, TaskStore, TaskListInjector, StoreTaskListPersistence,
|
|
|
18
18
|
export { compactionCapability, CompactionService, CompactionStrategy, DEFAULT_COMPACTION_CONFIG, MicroCompaction, estimateTokens, estimateTokensForMessages } from "./compaction/index.js";
|
|
19
19
|
export { userHooksCapability, HookEngine, HOOK_EVENT_TYPES } from "./user-hooks/index.js";
|
|
20
20
|
export { backgroundCapability, BackgroundManager, CommandBackgroundTask, AgentBackgroundTask, WorkflowBackgroundTask, QuestionBackgroundTask, backgroundListTool, backgroundOutputTool, backgroundStopTool, TERMINAL_STATUSES, isBackgroundTaskTerminal, StoreBackgroundTaskPersistence, DiskBackgroundTaskPersistence, isPersistedTaskTerminal, isValidPersistedTask, } from "./background/index.js";
|
|
21
|
-
export { skillsCapability, SkillRegistry, SkillNotFoundError, SkillCatalogInjector, skillTool, flowSkillProvider, flowSkillToolName, resolveSkillRoots, discoverSkills, parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError, normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./skills/index.js";
|
|
21
|
+
export { skillsCapability, loadSkillRoots, SkillRegistry, SkillNotFoundError, SkillCatalogInjector, skillTool, flowSkillProvider, flowSkillToolName, resolveSkillRoots, discoverSkills, parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError, normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./skills/index.js";
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readSessionLog } from "../capability-state.js";
|
|
2
|
+
import { T } from "../../scope/tokens.js";
|
|
2
3
|
import { PlanMode } from "./plan-mode.js";
|
|
3
4
|
import { enterPlanModeTool, exitPlanModeTool } from "./tools.js";
|
|
4
5
|
import { exitPlanModeReviewAskPolicy, planModeGuardDenyPolicy, planModeToolApprovePolicy, } from "./policies.js";
|
|
@@ -7,7 +8,6 @@ export { PlanMode } from "./plan-mode.js";
|
|
|
7
8
|
export function planCapability(planMode = new PlanMode()) {
|
|
8
9
|
return {
|
|
9
10
|
name: "plan",
|
|
10
|
-
service: planMode,
|
|
11
11
|
tools: [enterPlanModeTool(planMode), exitPlanModeTool(planMode)],
|
|
12
12
|
policies: [
|
|
13
13
|
planModeGuardDenyPolicy(planMode),
|
|
@@ -15,11 +15,17 @@ export function planCapability(planMode = new PlanMode()) {
|
|
|
15
15
|
planModeToolApprovePolicy(planMode),
|
|
16
16
|
],
|
|
17
17
|
injectors: [new PlanModeInjector(planMode)],
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
provides: [
|
|
19
|
+
{
|
|
20
|
+
token: T.Plan,
|
|
21
|
+
create: async (ctx) => {
|
|
22
|
+
planMode.attachMachine(ctx.scope.require(T.Machine));
|
|
23
|
+
// Rebuild plan-mode state from the log's latest enter/exit result (resume/fork aware).
|
|
24
|
+
planMode.reconstruct(await readSessionLog(ctx));
|
|
25
|
+
return planMode;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
23
29
|
};
|
|
24
30
|
}
|
|
25
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,7 +6,7 @@ export function flowSkillToolName(skillName) {
|
|
|
6
6
|
const suffix = skillName.replace(/[^a-zA-Z0-9_-]+/g, "_").toLowerCase() || "skill";
|
|
7
7
|
return `skill_${suffix}`;
|
|
8
8
|
}
|
|
9
|
-
function flowSkillTool(skill, registry, executor) {
|
|
9
|
+
function flowSkillTool(skill, registry, executor, sessionId) {
|
|
10
10
|
const toolName = flowSkillToolName(skill.name);
|
|
11
11
|
return defineTool({
|
|
12
12
|
name: toolName,
|
|
@@ -34,7 +34,7 @@ function flowSkillTool(skill, registry, executor) {
|
|
|
34
34
|
isError: true,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
const instructions = registry.renderSkillPrompt(skill, "");
|
|
37
|
+
const instructions = registry.renderSkillPrompt(skill, "", sessionId);
|
|
38
38
|
const output = await executor({ skill, instructions, input: args.input, signal: ctx.signal });
|
|
39
39
|
return { content: [{ type: "text", text: output }], details: { skill: skill.name, source: skill.source } };
|
|
40
40
|
},
|
|
@@ -44,7 +44,7 @@ function flowSkillTool(skill, registry, executor) {
|
|
|
44
44
|
export function flowSkillProvider(registry, executor) {
|
|
45
45
|
return {
|
|
46
46
|
id: "skill-flow",
|
|
47
|
-
listTools: () => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor)),
|
|
47
|
+
listTools: (ctx) => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor, ctx.sessionId)),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=flow-provider.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Capability } from "../capability.ts";
|
|
2
|
+
import type { Machine } from "../../tool/machine.ts";
|
|
2
3
|
import { SkillRegistry } from "./registry.ts";
|
|
3
4
|
import type { FlowSkillExecutor, SkillDefinition, SkillRoot } from "./types.ts";
|
|
4
5
|
export type { SkillRegistryOptions } from "./registry.ts";
|
|
@@ -14,7 +15,11 @@ export type { ActivateSkillRequest, SkillActivationResult, SkillActivationTrigge
|
|
|
14
15
|
export { normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./types.ts";
|
|
15
16
|
export type { SkillCatalog, SkillDefinition, SkillMetadata, SkillSource, SkillSummary, SkillRoot, SkillPluginContext, SkippedSkill, FlowSkillExecutor, FlowSkillRequest, } from "./types.ts";
|
|
16
17
|
export interface SkillsOptions {
|
|
18
|
+
/** A pre-built registry — e.g. the workspace's shared one (`T.SkillRegistry`). */
|
|
17
19
|
readonly registry?: SkillRegistry;
|
|
20
|
+
/** `false` = the registry is already loaded (a workspace scanned it once); skip the per-session
|
|
21
|
+
* scan and only bind this session to it. Default `true`. */
|
|
22
|
+
readonly scan?: boolean;
|
|
18
23
|
readonly roots?: readonly SkillRoot[];
|
|
19
24
|
/**
|
|
20
25
|
* Additional skill roots resolved lazily at session-open (merged after `roots`). Use this for
|
|
@@ -39,5 +44,12 @@ export interface SkillsOptions {
|
|
|
39
44
|
readonly flowExecutor?: FlowSkillExecutor;
|
|
40
45
|
readonly onWarning?: (message: string, cause?: unknown) => void;
|
|
41
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Scan the skill roots into `registry` — the static roots, the lazily-provided ones (e.g. enabled
|
|
49
|
+
* plugins' skill dirs), and the default project/user roots when asked. Called per session by
|
|
50
|
+
* `skillsCapability` (unless `scan: false`), or once per workspace by a host that shares one
|
|
51
|
+
* registry across the sessions of a working directory.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadSkillRoots(machine: Machine, registry: SkillRegistry, options?: Omit<SkillsOptions, "registry" | "scan" | "flowExecutor" | "onWarning">): Promise<void>;
|
|
42
54
|
export declare function skillsCapability(options?: SkillsOptions): Capability;
|
|
43
55
|
//# sourceMappingURL=index.d.ts.map
|