@0perator/operator 0.1.35 → 0.1.36

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/cli.js CHANGED
@@ -19,7 +19,7 @@ import { expandFileMentions } from "./util/mentions.js";
19
19
  import { join } from "node:path";
20
20
  import { homedir, hostname } from "node:os";
21
21
  import { createHash } from "node:crypto";
22
- const VERSION = "0.1.35";
22
+ const VERSION = "0.1.36";
23
23
  // operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
24
24
  const settings = loadSettings();
25
25
  // Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
@@ -195,6 +195,11 @@ function Root() {
195
195
  // decision here and <ApprovalPrompt> renders it; the keystroke resolves the promise. "allow always"
196
196
  // adds the tool to a per-session set so it stops prompting. (No approver ⇒ policy fail-safe denies.)
197
197
  const [approval, setApproval] = useState(null);
198
+ // ask_user bridge: the model's clarification question, parked here until the owner picks an option.
199
+ const [question, setQuestion] = useState(null);
200
+ const askUser = useCallback((q, options) => new Promise((resolve) => {
201
+ setQuestion({ question: q, options, resolve: (a) => { setQuestion(null); resolve(a); } });
202
+ }), []);
198
203
  const alwaysAllowRef = useRef(new Set());
199
204
  // Pending gated approvals by id. Both the local keystroke and a remote follower's approval_response
200
205
  // route through settleApproval — FIRST answer wins (§7); the map delete makes it idempotent.
@@ -234,6 +239,7 @@ function Root() {
234
239
  recall: settings.memory.recall,
235
240
  permissions: fgPermissions, // owner's policy + computer tools forced to "ask" when enabled (else bypass)
236
241
  approve: approveFn, // renders the in-TUI approval prompt for any "ask" decision
242
+ askUser, // registers the ask_user tool so the model can put a clarifying question to the owner
237
243
  telemetry: settings.telemetry, // local-only metrics by default
238
244
  eventSink, eventActor: EVENT_ACTOR, sessionId: SESSION_ID, // frozen event stream (tool/control audit)
239
245
  // Foreground only: lets Aurora delegate via spawn_agent. The bg factory below OMITS this, so a
@@ -742,7 +748,7 @@ function Root() {
742
748
  const liveMetrics = active
743
749
  ? `${SPIN[Math.floor(elapsed * 4) % SPIN.length]} ${fmtMeta(elapsed, liveTok)}`
744
750
  : metrics;
745
- return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, route: route, ctxPct: ctxPct, version: VERSION, metrics: liveMetrics, authUser: authUser, tier: EVENT_ACTOR.tier, planMode: planMode, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, approval: approval, onApprovalDecide: (allow, always) => {
751
+ return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, route: route, ctxPct: ctxPct, version: VERSION, metrics: liveMetrics, authUser: authUser, tier: EVENT_ACTOR.tier, planMode: planMode, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, approval: approval, question: question, onApprovalDecide: (allow, always) => {
746
752
  const cur = approval;
747
753
  if (cur)
748
754
  settleApproval(cur.id, allow, always); // first-wins with any remote follower answer
package/dist/session.js CHANGED
@@ -39,6 +39,37 @@ function makeSpawnTool(handler) {
39
39
  },
40
40
  };
41
41
  }
42
+ // The `ask_user` tool — the model pauses to ask the owner a structured multiple-choice question and gets
43
+ // the chosen option back as the tool result. safe:false (an interaction, not a speculative read). The
44
+ // handler (the shell) renders the prompt and blocks until the owner answers.
45
+ function makeAskTool(handler) {
46
+ return {
47
+ name: "ask_user",
48
+ safe: false,
49
+ description: "Ask the owner a single, clarifying multiple-choice question when the task is genuinely ambiguous " +
50
+ "and a wrong assumption would waste real work. Blocks until they choose, then returns the chosen " +
51
+ "option. Use SPARINGLY — prefer a sensible default and proceeding; never ask what you can determine " +
52
+ "from the code or the request. Provide 2-4 concrete, mutually-exclusive options.",
53
+ parameters: {
54
+ type: "object",
55
+ properties: {
56
+ question: { type: "string", description: "The clarifying question, one sentence." },
57
+ options: { type: "array", items: { type: "string" }, description: "2-4 concrete choices." },
58
+ },
59
+ required: ["question", "options"],
60
+ },
61
+ run: async (args) => {
62
+ const question = String(args.question ?? "").trim();
63
+ const options = Array.isArray(args.options) ? args.options.map((o) => String(o)).filter(Boolean) : [];
64
+ if (!question)
65
+ return "error: ask_user needs a question";
66
+ if (options.length < 2)
67
+ return "error: ask_user needs at least 2 options";
68
+ const answer = await handler(question, options.slice(0, 4));
69
+ return `The user chose: ${answer}`;
70
+ },
71
+ };
72
+ }
42
73
  const SUMMARY_MAX_TOKENS = 1200; // room for Aurora's reasoning before the summary content lands
43
74
  export class Session {
44
75
  convo = new Conversation();
@@ -69,7 +100,14 @@ export class Session {
69
100
  // Per-session tool registry: the base set, plus `spawn_agent` when the shell provides a delegate
70
101
  // handler (foreground only). Both the executor (dispatch) and localSchemas (what the model sees)
71
102
  // are built from the same map, so the tool is advertised iff it's runnable.
72
- const reg = cfg.spawnAgent ? new Map(registry).set("spawn_agent", makeSpawnTool(cfg.spawnAgent)) : registry;
103
+ let reg = registry;
104
+ if (cfg.spawnAgent || cfg.askUser) {
105
+ reg = new Map(registry);
106
+ if (cfg.spawnAgent)
107
+ reg.set("spawn_agent", makeSpawnTool(cfg.spawnAgent));
108
+ if (cfg.askUser)
109
+ reg.set("ask_user", makeAskTool(cfg.askUser));
110
+ }
73
111
  this.executor = new Executor(reg);
74
112
  this.localSchemas = toSchemas(reg);
75
113
  this.inner = cfg.router ?? new AuroraRouter();
package/dist/ui/App.js CHANGED
@@ -8,11 +8,12 @@ import { ThinkingSpinner } from "./ThinkingSpinner.js";
8
8
  import { StepSpinner, RecoverSpinner } from "./ActivitySpinner.js";
9
9
  import { BgPanel } from "./BgPanel.js";
10
10
  import { ApprovalPrompt } from "./ApprovalPrompt.js";
11
+ import { QuestionPrompt } from "./QuestionPrompt.js";
11
12
  export function App(props) {
12
- const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, tier, planMode, bgAgents, onSubmit, onQueue, onInterrupt, approval = null, onApprovalDecide } = props;
13
+ const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, tier, planMode, bgAgents, onSubmit, onQueue, onInterrupt, approval = null, onApprovalDecide, question = null } = props;
13
14
  const thinking = status === "thinking" || status === "streaming";
14
15
  const showSpinner = status === "recovering" || status === "executing" || thinking;
15
16
  return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Transcript, { entries: messages, live: live }), showSpinner && (_jsx(Box, { marginTop: 1, marginBottom: 1, children: status === "recovering" ? _jsx(RecoverSpinner, { active: true, label: stepLabel })
16
17
  : status === "executing" ? _jsx(StepSpinner, { active: true, label: stepLabel })
17
- : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), _jsx(BgPanel, { agents: bgAgents }), _jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }) }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, user: authUser, tier: tier, planMode: planMode }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle", suspended: !!approval }), _jsx(InputRule, {})] }));
18
+ : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), _jsx(BgPanel, { agents: bgAgents }), _jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }) }), _jsx(QuestionPrompt, { pending: question }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, user: authUser, tier: tier, planMode: planMode }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle", suspended: !!approval || !!question }), _jsx(InputRule, {})] }));
18
19
  }
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text, useInput } from "ink";
3
+ export function QuestionPrompt({ pending }) {
4
+ useInput((input, key) => {
5
+ if (!pending)
6
+ return;
7
+ if (key.ctrl && input.toLowerCase() === "c") {
8
+ pending.resolve(pending.options[0]);
9
+ return;
10
+ } // bail = first option
11
+ const n = Number(input);
12
+ if (Number.isInteger(n) && n >= 1 && n <= pending.options.length)
13
+ pending.resolve(pending.options[n - 1]);
14
+ }, { isActive: !!pending });
15
+ if (!pending)
16
+ return null;
17
+ return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, children: ["? ", _jsx(Text, { color: "white", children: pending.question })] }), pending.options.map((o, i) => (_jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", i + 1, "]"] }), " ", o] }, i))), _jsx(Text, { dimColor: true, children: " press 1-" + pending.options.length + " to choose" })] }));
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
5
5
  "type": "module",
6
6
  "bin": {