@0perator/operator 0.1.336 → 0.1.338
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/autonomy/delegate.js +1 -1
- package/dist/config/persona.js +2 -3
- package/dist/engine/messages.js +26 -3
- package/dist/session.js +15 -8
- package/dist/tools/registry.js +2 -2
- package/package.json +1 -1
|
@@ -108,7 +108,7 @@ function sendWithTimeout(send, ms, interrupt) {
|
|
|
108
108
|
const msg = (e) => (e instanceof Error ? e.message : String(e));
|
|
109
109
|
// ── The `delegate_task` tool (registry wires run: runDelegateTask) ──────────
|
|
110
110
|
/**
|
|
111
|
-
* Run `args.task` on a sub-agent backed by `args.model` (default "scout") and return its final answer, or an
|
|
111
|
+
* Run `args.task` on a sub-agent backed by `args.model` (default: settings autonomy.delegateModel, else "scout") and return its final answer, or an
|
|
112
112
|
* `error: ...` string (the tool contract: never throws). Result size is bounded downstream — the executor's
|
|
113
113
|
* capToolResult spills anything over 40KB to disk and hands the planner a re-readable pointer.
|
|
114
114
|
*/
|
package/dist/config/persona.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { readFileSync, appendFileSync, mkdirSync } from "node:fs";
|
|
6
6
|
import { join, dirname } from "node:path";
|
|
7
7
|
import { operatorPath } from "./home.js";
|
|
8
|
-
import { scratchDirFor } from "./scratch.js";
|
|
9
8
|
import { renderHarnessContext } from "./operator-harness.js";
|
|
10
9
|
import { renderToolCatalogue } from "../tools/registry.js";
|
|
11
10
|
import { renderSkillsIndex } from "./skills-index.js";
|
|
@@ -206,8 +205,8 @@ export function basePersona(cwd = process.cwd(), opts = {}) {
|
|
|
206
205
|
`find, and verify by running.) I record the non-obvious WHY in the repo's _ai-docs/, and commit clean: ` +
|
|
207
206
|
`a conventional \`type(scope): subject\` with explicit paths (never a blanket add in a shared checkout) ` +
|
|
208
207
|
`and no AI / Co-Authored-By / Claude-Session trailers.` +
|
|
209
|
-
`\n## This machine\nWorking dir:
|
|
210
|
-
`\nScratch dir
|
|
208
|
+
`\n## This machine\nWorking dir and scratch dir: named in the session context at the top of the conversation.` +
|
|
209
|
+
`\nScratch dir (also \`$OPERATOR_SCRATCH\` in every shell) — temporary scripts, probe ` +
|
|
211
210
|
`output, downloads to inspect, intermediate files: ALWAYS here, never /tmp and never the repo root. It is ` +
|
|
212
211
|
`git-ignored and swept after a week, so nothing you keep belongs in it; name files \`<subject>-<thing>\`.` +
|
|
213
212
|
ctxLine +
|
package/dist/engine/messages.js
CHANGED
|
@@ -89,12 +89,35 @@ export function sanitizeToolCallArgs(messages) {
|
|
|
89
89
|
});
|
|
90
90
|
return changed ? out : messages;
|
|
91
91
|
}
|
|
92
|
+
// Per-session facts (working dir, scratch dir) ride between these tags in the system prompt string, and
|
|
93
|
+
// placeSessionContext moves them onto the first user message. Chat templates render tool schemas AFTER the
|
|
94
|
+
// system text, so anything that differs between sessions inside the system message makes the server re-prefill
|
|
95
|
+
// every tool schema (~20K tokens) for each new session or delegated sub-agent. Out of it, [system + tools] is
|
|
96
|
+
// byte-identical across sessions on the same model and stays in the server's prompt cache.
|
|
97
|
+
export const SESSION_CONTEXT_OPEN = "\n<session-context>\n";
|
|
98
|
+
export const SESSION_CONTEXT_CLOSE = "\n</session-context>";
|
|
99
|
+
/** Moves the tagged session context out of the system prompt and in front of the first user message. Text
|
|
100
|
+
* appended after the closing tag (a think directive, a turn directive, MOA drafts) stays in the system prompt.
|
|
101
|
+
* With no user message to carry it, the system prompt is returned untouched. */
|
|
102
|
+
export function placeSessionContext(systemPrompt, conversation) {
|
|
103
|
+
const open = systemPrompt?.indexOf(SESSION_CONTEXT_OPEN) ?? -1;
|
|
104
|
+
const close = open >= 0 ? systemPrompt.indexOf(SESSION_CONTEXT_CLOSE, open) : -1;
|
|
105
|
+
const first = conversation.findIndex((m) => m.role === "user");
|
|
106
|
+
if (close < 0 || first < 0)
|
|
107
|
+
return { system: systemPrompt, conversation };
|
|
108
|
+
const sys = systemPrompt;
|
|
109
|
+
const context = sys.slice(open + SESSION_CONTEXT_OPEN.length, close);
|
|
110
|
+
const system = sys.slice(0, open) + sys.slice(close + SESSION_CONTEXT_CLOSE.length);
|
|
111
|
+
const carried = conversation.map((m, i) => i === first ? { ...m, content: `<session-context>\n${context}\n</session-context>\n\n${m.content}` } : m);
|
|
112
|
+
return { system: system || undefined, conversation: carried };
|
|
113
|
+
}
|
|
92
114
|
/** Prepends the system prompt (if any), repairs interrupted tool pairs, neutralizes any unparseable tool-call
|
|
93
115
|
* arguments (so a poisoned history never 500s the server), and validates the result. */
|
|
94
116
|
export function buildMessages(systemPrompt, conversation) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
:
|
|
117
|
+
const placed = placeSessionContext(systemPrompt, conversation);
|
|
118
|
+
const withSystem = placed.system
|
|
119
|
+
? [{ role: "system", content: placed.system }, ...placed.conversation]
|
|
120
|
+
: [...placed.conversation];
|
|
98
121
|
const messages = sanitizeToolCallArgs(repairToolPairs(withSystem));
|
|
99
122
|
assertValidMessages(messages);
|
|
100
123
|
return messages;
|
package/dist/session.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// that maps these callbacks onto React state; a test can drive the same `send()` directly.
|
|
4
4
|
import { runTurn, TurnAbortedError } from "./engine/agent.js";
|
|
5
5
|
import { recordTruncation } from "./observability/blackbox.js";
|
|
6
|
-
import { Conversation } from "./engine/messages.js";
|
|
6
|
+
import { Conversation, placeSessionContext, SESSION_CONTEXT_OPEN, SESSION_CONTEXT_CLOSE } from "./engine/messages.js";
|
|
7
|
+
import { scratchDirFor } from "./config/scratch.js";
|
|
7
8
|
import { chat, health, requiresOperatorToken, operatorTrustedUrl } from "./engine/aurora.js";
|
|
8
9
|
import { compact, fitToWindow, turnStarts, SUMMARY_INSTRUCTION, stripTrailingOrphanToolCall, pickSummaryContent, renderAnchorIndex, verbatimUserTail, applyAnchorVerification } from "./engine/compaction.js";
|
|
9
10
|
import { globalTokenMeter, endpointKey } from "./engine/token-meter.js";
|
|
@@ -492,9 +493,15 @@ export class Session {
|
|
|
492
493
|
const name = p ? `${p.label}${p.params ? ` ${p.params}` : ""}` : this.modelId;
|
|
493
494
|
return `\n\n## Active model\nThis session is served by ${name}${p?.box ? ` on ${p.box}` : ""} (model id \`${this.modelId}\`). ` +
|
|
494
495
|
`This is authoritative: it overrides any model named elsewhere in this prompt or in project files, and it changes ` +
|
|
495
|
-
`when the owner runs /model. Asked which model you run on, say you are Operator running on ${name}
|
|
496
|
-
|
|
497
|
-
|
|
496
|
+
`when the owner runs /model. Asked which model you run on, say you are Operator running on ${name}.`;
|
|
497
|
+
}
|
|
498
|
+
/** This session's working and scratch dirs, tagged so buildMessages carries them on the first user message
|
|
499
|
+
* rather than in the system prompt (see engine/messages.ts SESSION_CONTEXT_OPEN for why). */
|
|
500
|
+
sessionContextBlock() {
|
|
501
|
+
const cwd = this.cwd ?? process.cwd();
|
|
502
|
+
return `${SESSION_CONTEXT_OPEN}Working directory: ${cwd}\nScratch dir: ${scratchDirFor(cwd)}\nRelative paths and shell ` +
|
|
503
|
+
`commands resolve in the working directory. This is authoritative over any working dir named elsewhere; create ` +
|
|
504
|
+
`files there unless the owner names another path.${SESSION_CONTEXT_CLOSE}`;
|
|
498
505
|
}
|
|
499
506
|
/** The effective system prompt: the base persona plus any memory recalled this session, plus any
|
|
500
507
|
* active skill. Injected as ONE system prompt — never a second system message, which 400s llama.cpp's
|
|
@@ -505,7 +512,7 @@ export class Session {
|
|
|
505
512
|
: this.systemPrompt;
|
|
506
513
|
if (this.activeSkillBlock)
|
|
507
514
|
base = (base ?? "") + this.activeSkillBlock;
|
|
508
|
-
base = (base ?? "") + this.activeModelBlock();
|
|
515
|
+
base = (base ?? "") + this.activeModelBlock() + this.sessionContextBlock();
|
|
509
516
|
if (!this.planMode)
|
|
510
517
|
return base;
|
|
511
518
|
// Plan mode: the model researches read-only and proposes a plan; the read-only enforcement is in
|
|
@@ -895,10 +902,10 @@ export class Session {
|
|
|
895
902
|
// message. The server prefix-matches to the end of span and prefills only the instruction, instead of
|
|
896
903
|
// re-prefilling the whole span from scratch (the old system-less/tool-less summaryPrompt path did the
|
|
897
904
|
// latter — the documented cost trap). Empty content falls back to Aurora's reasoning channel.
|
|
898
|
-
const
|
|
905
|
+
const placed = placeSessionContext(this.lastSys ?? this.sys(), stripTrailingOrphanToolCall(span));
|
|
899
906
|
const messages = [
|
|
900
|
-
...(
|
|
901
|
-
...
|
|
907
|
+
...(placed.system ? [{ role: "system", content: placed.system }] : []),
|
|
908
|
+
...placed.conversation,
|
|
902
909
|
{ role: "user", content: SUMMARY_INSTRUCTION },
|
|
903
910
|
];
|
|
904
911
|
// A small-context active model (e.g. a self-hosted 8K Venice) can't summarize its OWN overflow — the
|
package/dist/tools/registry.js
CHANGED
|
@@ -2792,10 +2792,10 @@ const TOOLS = [
|
|
|
2792
2792
|
},
|
|
2793
2793
|
{
|
|
2794
2794
|
name: "delegate_task", safe: false,
|
|
2795
|
-
description: `Hand ONE self-contained subtask to a sub-agent running on a chosen model and get its final answer back (blocks until it finishes). The sub-agent is a full headless Operator session with its own tools, but NO memory of this conversation and it cannot ask you questions — so \`task\` must carry everything it needs (paths, constraints, the exact output you want). \`model\` is any /model id
|
|
2795
|
+
description: `Hand ONE self-contained subtask to a sub-agent running on a chosen model and get its final answer back (blocks until it finishes). The sub-agent is a full headless Operator session with its own tools, but NO memory of this conversation and it cannot ask you questions — so \`task\` must carry everything it needs (paths, constraints, the exact output you want). \`model\` is any /model id; OMIT IT to use the owner's configured default sub-agent (settings autonomy.delegateModel), which is the right choice almost always. Name a model only when the subtask needs a specific one, and never pick a model you have not seen answer in this fleet: an unloaded model fails the delegation. Anything TOOL-HEAVY — reviewing a remote/GitHub repo, multi-file exploration, web research, debugging, a repo audit — needs a strong tool-driver such as "cortana"; small models (e.g. "scout", 4B) drive tools unreliably and are often not loaded. Other fleet models: venice-24b, qwen3.8-flash, operator-1m. YOU CAN ALSO DELEGATE TO ANY CLOUD PROVIDER THE OWNER HAS CONNECTED (a stored vendor key): Claude via "claude-sonnet" (full tool-using), and any BYO provider — ${BYO_DELEGATE_PROVIDERS} — registered with "operator auth byo-model" (e.g. an OpenAI/Gemini/Groq/DeepSeek model id). A provider with NO stored key is refused with the exact command to store it, so a failed delegation is never silent — pick "cortana" if you're unsure a cloud key is connected. Use delegation to farm out an independent chunk while you keep planning; do not delegate what you can do in one tool call. Sub-agents cannot delegate further. The sub-agent runs with the owner's permission policy and can mutate the workspace.`,
|
|
2796
2796
|
parameters: { type: "object", properties: {
|
|
2797
2797
|
task: { type: "string", description: "the complete, self-contained subtask — the sub-agent sees only this" },
|
|
2798
|
-
model: { type: "string", description: "registry model id to run it on
|
|
2798
|
+
model: { type: "string", description: "registry model id to run it on; omit for the owner's configured default sub-agent" },
|
|
2799
2799
|
}, required: ["task"] },
|
|
2800
2800
|
run: (a) => runDelegateTask(a),
|
|
2801
2801
|
},
|