operon-agents-core 0.1.0-alpha.37 → 0.1.0-alpha.38
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/compose-hooks.js +1 -1
- package/dist/agent/environment-notice-injector.d.ts +11 -0
- package/dist/agent/environment-notice-injector.js +23 -0
- package/dist/agent/run-support.d.ts +1 -3
- package/dist/agent/run-support.js +1 -14
- package/dist/agent/runner.js +1 -0
- package/dist/agent/session.d.ts +4 -2
- package/dist/agent/session.js +8 -8
- package/dist/agent/toolset.js +2 -3
- package/dist/agent/workflow/prompt.js +1 -1
- package/dist/agent/workflow/tool.js +4 -10
- package/dist/agent/worktree.d.ts +7 -3
- package/dist/agent/worktree.js +24 -22
- package/dist/capabilities/compaction/full.js +1 -0
- package/dist/capabilities/injection.d.ts +2 -0
- package/dist/loop/run-turn.d.ts +1 -1
- package/dist/loop/tool-call.d.ts +2 -2
- package/dist/loop/tool-call.js +4 -2
- package/dist/loop/turn-step.d.ts +1 -1
- package/dist/tool/environment-table.d.ts +3 -5
- package/dist/tool/environment-table.js +3 -5
- package/dist/tool/environment-target.js +3 -0
- package/package.json +1 -1
|
@@ -87,7 +87,7 @@ function buildAuthorizer(state, context, tools) {
|
|
|
87
87
|
getTools: typeof tools === "function" ? tools : () => tools,
|
|
88
88
|
getEnvironments: () => {
|
|
89
89
|
const frame = frameEnvironmentsFor(state);
|
|
90
|
-
if (frame === undefined)
|
|
90
|
+
if (frame === undefined || frame.declared.length <= 1)
|
|
91
91
|
return undefined;
|
|
92
92
|
return {
|
|
93
93
|
home: frame.home,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InjectionContext, InjectionResult, Injector } from "../capabilities/injection.ts";
|
|
2
|
+
/** One pending environment update per session, delivered once to each frame. */
|
|
3
|
+
export declare class EnvironmentNoticeInjector implements Injector {
|
|
4
|
+
readonly id = "environments";
|
|
5
|
+
private text?;
|
|
6
|
+
private readonly delivered;
|
|
7
|
+
publish(text: string): void;
|
|
8
|
+
take(address: string): string | undefined;
|
|
9
|
+
inject(ctx: InjectionContext): InjectionResult | null;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=environment-notice-injector.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** One pending environment update per session, delivered once to each frame. */
|
|
2
|
+
export class EnvironmentNoticeInjector {
|
|
3
|
+
id = "environments";
|
|
4
|
+
text;
|
|
5
|
+
delivered = new Set();
|
|
6
|
+
publish(text) {
|
|
7
|
+
this.text = text;
|
|
8
|
+
this.delivered.clear();
|
|
9
|
+
}
|
|
10
|
+
take(address) {
|
|
11
|
+
if (this.text === undefined || this.delivered.has(address))
|
|
12
|
+
return undefined;
|
|
13
|
+
this.delivered.add(address);
|
|
14
|
+
return this.text;
|
|
15
|
+
}
|
|
16
|
+
inject(ctx) {
|
|
17
|
+
if (ctx.trigger === "compaction")
|
|
18
|
+
return null;
|
|
19
|
+
const text = this.take(ctx.address);
|
|
20
|
+
return text === undefined ? null : { text, variant: "status" };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=environment-notice-injector.js.map
|
|
@@ -62,9 +62,7 @@ export declare function runCtxFor<TContext>(state: RunState<TContext>): AgentRun
|
|
|
62
62
|
*/
|
|
63
63
|
export declare function deriveChild<TContext>(parent: RunState<TContext>, opts: DeriveOptions, spawner: Pick<Agent<TContext>, "model">): RunState<TContext>;
|
|
64
64
|
/**
|
|
65
|
-
* The environments
|
|
66
|
-
* them — `undefined` for a frame that reaches one environment (every single-environment
|
|
67
|
-
* session), which keeps that path exactly as it was.
|
|
65
|
+
* The environments this frame can address, including the home of a single-environment session.
|
|
68
66
|
*/
|
|
69
67
|
export declare function frameEnvironmentsFor<TContext>(state: RunState<TContext>): FrameEnvironments | undefined;
|
|
70
68
|
/** Append the frame's environment list to its system prompt (multi-environment frames only). */
|
|
@@ -130,9 +130,7 @@ export function deriveChild(parent, opts, spawner) {
|
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* The environments
|
|
134
|
-
* them — `undefined` for a frame that reaches one environment (every single-environment
|
|
135
|
-
* session), which keeps that path exactly as it was.
|
|
133
|
+
* The environments this frame can address, including the home of a single-environment session.
|
|
136
134
|
*/
|
|
137
135
|
export function frameEnvironmentsFor(state) {
|
|
138
136
|
const table = state.environments;
|
|
@@ -170,19 +168,8 @@ export function injectAtTurnBoundary(state, context) {
|
|
|
170
168
|
// longer, because the journal itself broadcasts (`historyChangeEmitter`).
|
|
171
169
|
context.appendMessage(message, origin);
|
|
172
170
|
});
|
|
173
|
-
// Environment status (a declared machine not connected this open, a changed working directory,
|
|
174
|
-
// an `updateEnvironments`): a reminder at the boundary, never a system-prompt change, so the
|
|
175
|
-
// cached prefix holds. Once per frame per notice.
|
|
176
|
-
const notice = state.session.takeEnvironmentNotice?.(state.address);
|
|
177
|
-
if (notice !== undefined) {
|
|
178
|
-
const text = systemReminder(notice);
|
|
179
|
-
const message = { role: "user", content: [{ type: "text", text }], timestamp: Date.now() };
|
|
180
|
-
injectionTokens.set(ENVIRONMENT_INJECTOR_ID, estimateTokens(text));
|
|
181
|
-
context.appendMessage(message, { kind: "injection", injectorId: ENVIRONMENT_INJECTOR_ID, variant: "status" });
|
|
182
|
-
}
|
|
183
171
|
return injectionTokens;
|
|
184
172
|
}
|
|
185
|
-
const ENVIRONMENT_INJECTOR_ID = "environments";
|
|
186
173
|
// ── Pure message helpers ─────────────────────────────────────────────────────────────────
|
|
187
174
|
export function lastAssistant(messages) {
|
|
188
175
|
for (let i = messages.length - 1; i >= 0; i--) {
|
package/dist/agent/runner.js
CHANGED
package/dist/agent/session.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InjectionManager } from "../capabilities/injection.ts";
|
|
1
2
|
import type { Environment } from "../tool/environment.ts";
|
|
2
3
|
import type { ChatModel } from "../llm/define-model.ts";
|
|
3
4
|
import type { ThinkingLevel } from "../llm/model.ts";
|
|
@@ -251,8 +252,7 @@ export declare class Session implements SessionPort {
|
|
|
251
252
|
/** The root environment — where tools run unless a call names another `target`. */
|
|
252
253
|
readonly environment: Environment;
|
|
253
254
|
private environmentTable;
|
|
254
|
-
private environmentNotice;
|
|
255
|
-
private readonly environmentNoticeDelivered;
|
|
255
|
+
private readonly environmentNotice;
|
|
256
256
|
private readonly sandboxTtlMs;
|
|
257
257
|
readonly store?: SessionStore;
|
|
258
258
|
readonly events: EventSink;
|
|
@@ -343,6 +343,8 @@ export declare class Session implements SessionPort {
|
|
|
343
343
|
private keepalivesFor;
|
|
344
344
|
/** Every named environment of this session, root first. A table of one in the usual case. */
|
|
345
345
|
get environments(): EnvironmentTable;
|
|
346
|
+
/** @internal Add the session-owned injectors to each run's manager. */
|
|
347
|
+
registerSessionInjectors(manager: InjectionManager): void;
|
|
346
348
|
/** Queue a status note for every frame's next turn boundary (replaces any undelivered one). */
|
|
347
349
|
setEnvironmentNotice(text: string): void;
|
|
348
350
|
/**
|
package/dist/agent/session.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SandboxKeepalive } from "./sandbox-keepalive.js";
|
|
2
|
+
import { EnvironmentNoticeInjector } from "./environment-notice-injector.js";
|
|
2
3
|
import { recoverOrphanedTurns } from "./lifecycle-recovery.js";
|
|
3
4
|
import { readSessionTails } from "../events/projection.js";
|
|
4
5
|
import { PermissionManager } from "../permission/manager.js";
|
|
@@ -62,8 +63,7 @@ export class Session {
|
|
|
62
63
|
/** The root environment — where tools run unless a call names another `target`. */
|
|
63
64
|
environment;
|
|
64
65
|
environmentTable;
|
|
65
|
-
environmentNotice;
|
|
66
|
-
environmentNoticeDelivered = new Set();
|
|
66
|
+
environmentNotice = new EnvironmentNoticeInjector();
|
|
67
67
|
sandboxTtlMs;
|
|
68
68
|
store;
|
|
69
69
|
events;
|
|
@@ -289,10 +289,13 @@ export class Session {
|
|
|
289
289
|
get environments() {
|
|
290
290
|
return this.environmentTable;
|
|
291
291
|
}
|
|
292
|
+
/** @internal Add the session-owned injectors to each run's manager. */
|
|
293
|
+
registerSessionInjectors(manager) {
|
|
294
|
+
manager.register(this.environmentNotice);
|
|
295
|
+
}
|
|
292
296
|
/** Queue a status note for every frame's next turn boundary (replaces any undelivered one). */
|
|
293
297
|
setEnvironmentNotice(text) {
|
|
294
|
-
this.environmentNotice
|
|
295
|
-
this.environmentNoticeDelivered.clear();
|
|
298
|
+
this.environmentNotice.publish(text);
|
|
296
299
|
}
|
|
297
300
|
/**
|
|
298
301
|
* The environment status note `address` has not seen yet, marking it seen — or undefined.
|
|
@@ -300,10 +303,7 @@ export class Session {
|
|
|
300
303
|
* changing the system prompt, so the cached prefix holds.
|
|
301
304
|
*/
|
|
302
305
|
takeEnvironmentNotice(address) {
|
|
303
|
-
|
|
304
|
-
return undefined;
|
|
305
|
-
this.environmentNoticeDelivered.add(address);
|
|
306
|
-
return this.environmentNotice;
|
|
306
|
+
return this.environmentNotice.take(address);
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
309
309
|
* Change what environments this session HAS — the one deliberate way to: reopening with a
|
package/dist/agent/toolset.js
CHANGED
|
@@ -94,8 +94,7 @@ const targetConflictWarned = new WeakMap();
|
|
|
94
94
|
*/
|
|
95
95
|
function withEnvironmentTargets(state, tools) {
|
|
96
96
|
const frame = frameEnvironmentsFor(state);
|
|
97
|
-
|
|
98
|
-
if (frame === undefined || frame.reachable.size <= 1)
|
|
97
|
+
if (frame === undefined)
|
|
99
98
|
return tools;
|
|
100
99
|
let changed = false;
|
|
101
100
|
const out = tools.map((tool) => {
|
|
@@ -103,7 +102,7 @@ function withEnvironmentTargets(state, tools) {
|
|
|
103
102
|
if (outcome.kind === "unchanged")
|
|
104
103
|
return tool;
|
|
105
104
|
changed = true;
|
|
106
|
-
if (outcome.kind === "conflict") {
|
|
105
|
+
if (outcome.kind === "conflict" && frame.reachable.size > 1) {
|
|
107
106
|
const warned = targetConflictWarned.get(state) ?? new Set();
|
|
108
107
|
targetConflictWarned.set(state, warned);
|
|
109
108
|
if (!warned.has(tool.schema.name)) {
|
|
@@ -35,7 +35,7 @@ Every script must begin with \`export const meta = {...}\`:
|
|
|
35
35
|
The \`meta\` object must be a PURE LITERAL — no variables, function calls, spreads, or template interpolation. Required: \`name\`, \`description\`. Optional: \`title\`, \`whenToUse\`, \`phases\`. Use the SAME phase titles in meta.phases as in your phase() calls — titles are matched exactly.
|
|
36
36
|
|
|
37
37
|
Script body hooks:
|
|
38
|
-
- agent(prompt, opts?): Promise<any> — spawn one subagent and run it to completion. Without a schema, returns its final text as a string. With opts.schema (a JSON Schema), the subagent is forced to call a StructuredOutput tool whose argument matches the schema; agent() validates it and resolves the parsed object (nudging + retrying on mismatch). opts: { label?, phase?, schema?, model?, agentType? }. opts.label overrides the display label. opts.phase assigns this agent to a progress group — use it inside pipeline()/parallel() stages instead of relying on global phase() state. opts.model overrides the model for this one agent; omit it to inherit the default. opts.agentType selects which subagent type runs the agent. Available types: ${agentList}. Omit it to use the default. opts.isolation:'worktree' runs the agent in an isolated git worktree (a separate working copy, auto-removed if it makes no changes) — use it ONLY when agents mutate files in parallel and would otherwise conflict;
|
|
38
|
+
- agent(prompt, opts?): Promise<any> — spawn one subagent and run it to completion. Without a schema, returns its final text as a string. With opts.schema (a JSON Schema), the subagent is forced to call a StructuredOutput tool whose argument matches the schema; agent() validates it and resolves the parsed object (nudging + retrying on mismatch). opts: { label?, phase?, schema?, model?, agentType? }. opts.label overrides the display label. opts.phase assigns this agent to a progress group — use it inside pipeline()/parallel() stages instead of relying on global phase() state. opts.model overrides the model for this one agent; omit it to inherit the default. opts.agentType selects which subagent type runs the agent. Available types: ${agentList}. Omit it to use the default. opts.isolation:'worktree' runs the agent in an isolated git worktree (a separate working copy, auto-removed if it makes no changes) — use it ONLY when agents mutate files in parallel and would otherwise conflict; the step fails before the subagent starts if the environment cannot create the worktree.
|
|
39
39
|
- parallel(thunks): Promise<any[]> — run () => agent(...) thunks concurrently. This is a BARRIER: it awaits all thunks. A thunk that throws resolves to null in the result array (the call never rejects), so .filter(Boolean) before using results. At most 4096 thunks per call.
|
|
40
40
|
- pipeline(items, stage1, stage2, ...): Promise<any[]> — run each item through all stages independently, with NO barrier between stages. Item A can be in stage 3 while item B is still in stage 1. This is the DEFAULT for multi-stage work. Each stage callback receives (prevResult, originalItem, index). A stage that throws drops that item to null and skips its remaining stages. At most 4096 items per call.
|
|
41
41
|
- phase(title): void — start a new phase; subsequent agent() calls are grouped under it.
|
|
@@ -52,19 +52,13 @@ export function buildWorkflowTool(spawner, parent) {
|
|
|
52
52
|
// Publish + journal the stable identity before any work runs, so the orchestration
|
|
53
53
|
// event can be joined to this child's Session AgentEvents and interruption is resumable.
|
|
54
54
|
onStart({ agentId, address });
|
|
55
|
-
// Optional worktree isolation — degrade (with a log, never silently) if unsupported.
|
|
56
55
|
let runEnvironment = parent.environment;
|
|
57
56
|
let cleanupWorktree;
|
|
58
57
|
if (isolation === "worktree") {
|
|
59
|
-
const wt = await createWorktree(parent.environment, { label: agentId });
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
emitProgress({ type: "log", message: `🌳 ${agentId}: isolated worktree at ${wt.cwd}` });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
emitProgress({ type: "log", message: `isolation:'worktree' unavailable on environment '${parent.environment.name}' — running in the shared workspace` });
|
|
67
|
-
}
|
|
58
|
+
const wt = await createWorktree(parent.environment, { label: agentId, required: true });
|
|
59
|
+
runEnvironment = wt.environment;
|
|
60
|
+
cleanupWorktree = wt.cleanup;
|
|
61
|
+
emitProgress({ type: "log", message: `🌳 ${agentId}: isolated worktree at ${wt.cwd}` });
|
|
68
62
|
}
|
|
69
63
|
// Per-agent abort: workflow signal OR an absolute stall timeout.
|
|
70
64
|
const controller = new AbortController();
|
package/dist/agent/worktree.d.ts
CHANGED
|
@@ -26,13 +26,17 @@ export declare const WORKTREES_DIR = ".operon/worktrees";
|
|
|
26
26
|
* capabilities — git runs through `environment.exec`, and the scoped environment comes from
|
|
27
27
|
* `environment.withCwd`. It is therefore backend-agnostic: any environment whose target host
|
|
28
28
|
* has git (local, ssh, sandbox) can isolate. Whether isolation happens is decided at
|
|
29
|
-
* runtime by git itself
|
|
30
|
-
*
|
|
31
|
-
* workspace (surfacing that isolation was unavailable rather than failing silently).
|
|
29
|
+
* runtime by git itself. By default an unavailable worktree returns `null`. Callers
|
|
30
|
+
* requesting isolation use `required: true` to receive the underlying failure.
|
|
32
31
|
* Cleanup removes the worktree only if the agent left it clean; a dirty worktree is
|
|
33
32
|
* kept for inspection.
|
|
34
33
|
*/
|
|
34
|
+
export declare function createWorktree(environment: Environment, options: {
|
|
35
|
+
label?: string;
|
|
36
|
+
required: true;
|
|
37
|
+
}): Promise<WorktreeHandle>;
|
|
35
38
|
export declare function createWorktree(environment: Environment, options?: {
|
|
36
39
|
label?: string;
|
|
40
|
+
required?: boolean;
|
|
37
41
|
}): Promise<WorktreeHandle | null>;
|
|
38
42
|
//# sourceMappingURL=worktree.d.ts.map
|
package/dist/agent/worktree.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { errorMessage } from "../loop/errors.js";
|
|
2
3
|
/**
|
|
3
4
|
* Where isolated worktrees are created, relative to the repository root.
|
|
4
5
|
*
|
|
@@ -8,23 +9,19 @@ import { randomBytes } from "node:crypto";
|
|
|
8
9
|
* abandoned worktree is a checkout, so it shows up as untracked otherwise.
|
|
9
10
|
*/
|
|
10
11
|
export const WORKTREES_DIR = ".operon/worktrees";
|
|
11
|
-
/**
|
|
12
|
-
* Create an isolated git worktree for a subagent and return an environment scoped to it.
|
|
13
|
-
*
|
|
14
|
-
* This is workflow/orchestration policy built entirely on an environment's existing
|
|
15
|
-
* capabilities — git runs through `environment.exec`, and the scoped environment comes from
|
|
16
|
-
* `environment.withCwd`. It is therefore backend-agnostic: any environment whose target host
|
|
17
|
-
* has git (local, ssh, sandbox) can isolate. Whether isolation happens is decided at
|
|
18
|
-
* runtime by git itself — a host without git, or a cwd that isn't a repo, makes the
|
|
19
|
-
* git command fail and we return `null`, and the caller degrades to the shared
|
|
20
|
-
* workspace (surfacing that isolation was unavailable rather than failing silently).
|
|
21
|
-
* Cleanup removes the worktree only if the agent left it clean; a dirty worktree is
|
|
22
|
-
* kept for inspection.
|
|
23
|
-
*/
|
|
24
12
|
export async function createWorktree(environment, options) {
|
|
25
|
-
const
|
|
13
|
+
const cwd = environment.getcwd();
|
|
14
|
+
function unavailable(reason) {
|
|
15
|
+
if (options?.required)
|
|
16
|
+
throw new Error(`Cannot create an isolated worktree in "${cwd}": ${reason}`);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const repo = await runGit(environment, ["-C", cwd, "rev-parse", "--show-toplevel"]);
|
|
20
|
+
if ("error" in repo)
|
|
21
|
+
return unavailable(repo.error);
|
|
22
|
+
const root = repo.ok.trim();
|
|
26
23
|
if (!root)
|
|
27
|
-
return
|
|
24
|
+
return unavailable("Git returned an empty repository root.");
|
|
28
25
|
const id = randomBytes(4).toString("hex");
|
|
29
26
|
const safeLabel = (options?.label ?? "wt").replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "wt";
|
|
30
27
|
const branch = `wf/${safeLabel}-${id}`;
|
|
@@ -34,11 +31,11 @@ export async function createWorktree(environment, options) {
|
|
|
34
31
|
// own repository, so the stale name was visible to every one of them.
|
|
35
32
|
const wtPath = environment.normpath(`${root}/${WORKTREES_DIR}/${safeLabel}-${id}`);
|
|
36
33
|
const added = await runGit(environment, ["-C", root, "worktree", "add", "--quiet", "-b", branch, wtPath, "HEAD"]);
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
34
|
+
if ("error" in added)
|
|
35
|
+
return unavailable(added.error);
|
|
39
36
|
const cleanup = async () => {
|
|
40
37
|
const status = await runGit(environment, ["-C", wtPath, "status", "--porcelain"]);
|
|
41
|
-
if (
|
|
38
|
+
if ("ok" in status && status.ok.trim() === "") {
|
|
42
39
|
await runGit(environment, ["-C", root, "worktree", "remove", "--force", wtPath]);
|
|
43
40
|
await runGit(environment, ["-C", root, "branch", "-D", branch]);
|
|
44
41
|
}
|
|
@@ -47,10 +44,15 @@ export async function createWorktree(environment, options) {
|
|
|
47
44
|
};
|
|
48
45
|
return { environment: environment.withCwd(wtPath), cwd: wtPath, cleanup };
|
|
49
46
|
}
|
|
50
|
-
/** Run `git <args>` on the environment's host; `ok` is stdout on exit 0, undefined otherwise. */
|
|
51
47
|
async function runGit(environment, args) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
try {
|
|
49
|
+
const result = await environment.commands.run(["git", ...args]);
|
|
50
|
+
if (result.exitCode === 0)
|
|
51
|
+
return { ok: result.stdout };
|
|
52
|
+
return { error: result.stderr.trim() || `Git exited with status ${result.exitCode ?? "unknown"}.` };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return { error: errorMessage(error) };
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
//# sourceMappingURL=worktree.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Message } from "../protocol/index.ts";
|
|
2
2
|
import type { PromptOrigin } from "../store/origin.ts";
|
|
3
3
|
export interface InjectionContext {
|
|
4
|
+
/** Defaults to a fresh turn. Compaction also runs injectors to restore context. */
|
|
5
|
+
readonly trigger?: "turn" | "compaction";
|
|
4
6
|
readonly history: readonly Message[];
|
|
5
7
|
readonly sessionId: string;
|
|
6
8
|
readonly address: string;
|
package/dist/loop/run-turn.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface RunTurnInput {
|
|
|
22
22
|
readonly signal: AbortSignal;
|
|
23
23
|
readonly model: ChatModel;
|
|
24
24
|
readonly environment: Environment;
|
|
25
|
-
/** The frame's
|
|
25
|
+
/** The frame's routing table (see `ToolCallStepContext`). */
|
|
26
26
|
readonly environments?: FrameEnvironments;
|
|
27
27
|
readonly background?: BackgroundSpawner;
|
|
28
28
|
/** Client interactive-question channel; forwarded to tool contexts (AskUserQuestion). */
|
package/dist/loop/tool-call.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ export interface ToolCallStepContext {
|
|
|
18
18
|
readonly model: ChatModel;
|
|
19
19
|
readonly environment: Environment;
|
|
20
20
|
/**
|
|
21
|
-
* The environments this frame can address.
|
|
22
|
-
*
|
|
21
|
+
* The environments this frame can address. An explicit target must be reachable even
|
|
22
|
+
* when the frame has only its home.
|
|
23
23
|
*/
|
|
24
24
|
readonly environments?: FrameEnvironments;
|
|
25
25
|
readonly tools: ReadonlyMap<string, Tool>;
|
package/dist/loop/tool-call.js
CHANGED
|
@@ -203,8 +203,7 @@ async function prepareCall(step, call) {
|
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Settle where an environment-scoped call runs: its `target`, else the frame's home. The
|
|
206
|
-
* argument is taken out either way, so the tool never sees it.
|
|
207
|
-
* environment-scoped, or a frame with one environment, passes through untouched.
|
|
206
|
+
* argument is taken out either way, so the tool never sees it.
|
|
208
207
|
*/
|
|
209
208
|
function selectCallEnvironment(step, tool, toolName, args) {
|
|
210
209
|
const frame = step.environments;
|
|
@@ -236,6 +235,9 @@ function selectCallEnvironment(step, tool, toolName, args) {
|
|
|
236
235
|
// Declared but not connected in this open: refuse rather than fall back to another machine.
|
|
237
236
|
return { error: `Environment "${name}" is not connected right now, so ${toolName} cannot run there. Nothing was run. Use another environment or ask the user to reconnect "${name}".` };
|
|
238
237
|
}
|
|
238
|
+
// Single-environment calls keep the existing event, approval and scheduling semantics.
|
|
239
|
+
if (frame.declared.length === 1)
|
|
240
|
+
return { args: rest };
|
|
239
241
|
return {
|
|
240
242
|
args: rest,
|
|
241
243
|
callEnv: { name, environment: entry.environment, identity: entry.identity, root: name === frame.root },
|
package/dist/loop/turn-step.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface ExecuteStepDeps {
|
|
|
28
28
|
readonly signal: AbortSignal;
|
|
29
29
|
readonly model: ChatModel;
|
|
30
30
|
readonly environment: Environment;
|
|
31
|
-
/** The frame's
|
|
31
|
+
/** The frame's routing table (see `ToolCallStepContext`). */
|
|
32
32
|
readonly environments?: FrameEnvironments;
|
|
33
33
|
readonly background?: BackgroundSpawner;
|
|
34
34
|
/** Client interactive-question channel; forwarded to tool contexts (AskUserQuestion). */
|
|
@@ -131,7 +131,7 @@ export declare function snapshotDrift(declared: EnvironmentSnapshot, live: Envir
|
|
|
131
131
|
* The environments ONE frame (root agent or subagent) can address, as the tool-call layer needs
|
|
132
132
|
* them. `home` is where a call without `target` runs; its entry carries the frame's ACTUAL
|
|
133
133
|
* environment (a workflow worktree, say), which may differ from the table's entry of that name.
|
|
134
|
-
*
|
|
134
|
+
* Also used to validate explicit targets in single-environment sessions.
|
|
135
135
|
*/
|
|
136
136
|
export interface FrameEnvironments {
|
|
137
137
|
readonly home: string;
|
|
@@ -144,10 +144,8 @@ export interface FrameEnvironments {
|
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Build a frame's view of the table. `homeEnvironment` is the frame's own instance; `reachable`
|
|
147
|
-
* limits the names (undefined = the whole table).
|
|
148
|
-
*
|
|
149
|
-
* session that reaches only its home still gets a view: it is offered no `target` and no list,
|
|
150
|
-
* but a call that names another environment is refused instead of silently running at home.
|
|
147
|
+
* limits the names (undefined = the whole table). A single reachable environment is enough
|
|
148
|
+
* to validate a call even though the model is offered no target parameter or environment list.
|
|
151
149
|
*/
|
|
152
150
|
export declare function frameEnvironmentsOf(table: EnvironmentTable | undefined, home: string, homeEnvironment: Environment, reachable?: readonly string[]): FrameEnvironments | undefined;
|
|
153
151
|
/**
|
|
@@ -184,13 +184,11 @@ export function snapshotDrift(declared, live) {
|
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
186
|
* Build a frame's view of the table. `homeEnvironment` is the frame's own instance; `reachable`
|
|
187
|
-
* limits the names (undefined = the whole table).
|
|
188
|
-
*
|
|
189
|
-
* session that reaches only its home still gets a view: it is offered no `target` and no list,
|
|
190
|
-
* but a call that names another environment is refused instead of silently running at home.
|
|
187
|
+
* limits the names (undefined = the whole table). A single reachable environment is enough
|
|
188
|
+
* to validate a call even though the model is offered no target parameter or environment list.
|
|
191
189
|
*/
|
|
192
190
|
export function frameEnvironmentsOf(table, home, homeEnvironment, reachable) {
|
|
193
|
-
if (table === undefined
|
|
191
|
+
if (table === undefined)
|
|
194
192
|
return undefined;
|
|
195
193
|
const allowed = reachable === undefined ? undefined : new Set(reachable);
|
|
196
194
|
const map = new Map();
|
|
@@ -30,6 +30,9 @@ export function withTargetParameter(tool, frame) {
|
|
|
30
30
|
else if (properties !== undefined && Object.hasOwn(properties, TARGET_PARAMETER)) {
|
|
31
31
|
outcome = { kind: "conflict", tool: notScoped(tool) };
|
|
32
32
|
}
|
|
33
|
+
else if (names.length <= 1) {
|
|
34
|
+
outcome = { kind: "unchanged", tool };
|
|
35
|
+
}
|
|
33
36
|
else {
|
|
34
37
|
const target = {
|
|
35
38
|
type: "string",
|