@0perator/operator 0.1.34 → 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
@@ -15,10 +15,11 @@ import { BackgroundAgents } from "./background/index.js";
15
15
  import { loadSettings } from "./config/settings.js";
16
16
  import { EventSink } from "./telemetry/events.js";
17
17
  import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
18
+ import { expandFileMentions } from "./util/mentions.js";
18
19
  import { join } from "node:path";
19
20
  import { homedir, hostname } from "node:os";
20
21
  import { createHash } from "node:crypto";
21
- const VERSION = "0.1.34";
22
+ const VERSION = "0.1.36";
22
23
  // operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
23
24
  const settings = loadSettings();
24
25
  // Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
@@ -194,6 +195,11 @@ function Root() {
194
195
  // decision here and <ApprovalPrompt> renders it; the keystroke resolves the promise. "allow always"
195
196
  // adds the tool to a per-session set so it stops prompting. (No approver ⇒ policy fail-safe denies.)
196
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
+ }), []);
197
203
  const alwaysAllowRef = useRef(new Set());
198
204
  // Pending gated approvals by id. Both the local keystroke and a remote follower's approval_response
199
205
  // route through settleApproval — FIRST answer wins (§7); the map delete makes it idempotent.
@@ -233,6 +239,7 @@ function Root() {
233
239
  recall: settings.memory.recall,
234
240
  permissions: fgPermissions, // owner's policy + computer tools forced to "ask" when enabled (else bypass)
235
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
236
243
  telemetry: settings.telemetry, // local-only metrics by default
237
244
  eventSink, eventActor: EVENT_ACTOR, sessionId: SESSION_ID, // frozen event stream (tool/control audit)
238
245
  // Foreground only: lets Aurora delegate via spawn_agent. The bg factory below OMITS this, so a
@@ -370,7 +377,7 @@ function Root() {
370
377
  setElapsed(0);
371
378
  setStat("thinking");
372
379
  try {
373
- const outcome = await session.send(text, {
380
+ const outcome = await session.send(expandFileMentions(text), {
374
381
  onRoute: (label, pct) => { setRoute(label); setCtxPct(pct); remoteRef.current?.setStatus(pct, label); },
375
382
  onDelta: (chunk) => {
376
383
  liveText.current += chunk;
@@ -741,7 +748,7 @@ function Root() {
741
748
  const liveMetrics = active
742
749
  ? `${SPIN[Math.floor(elapsed * 4) % SPIN.length]} ${fmtMeta(elapsed, liveTok)}`
743
750
  : metrics;
744
- 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) => {
745
752
  const cur = approval;
746
753
  if (cur)
747
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
+ }
@@ -0,0 +1,34 @@
1
+ // @file mentions (Claude-Code parity): when the owner types `@path`, inline that file's content into the
2
+ // SENT prompt (the visible message keeps the @path as typed). Only tokens that resolve to a real file are
3
+ // expanded — `@someone` that isn't a path is left untouched — and each file is bounded + oversized/dir
4
+ // paths are skipped, so a stray `@node_modules/...` can't blow the context. Matched at a word boundary so
5
+ // email addresses don't trigger it. Pure + node-lazy-free at module load isn't needed (CLI-only caller).
6
+ import { readFileSync, statSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { homedir } from "node:os";
9
+ const MENTION_RE = /(?:^|\s)@([^\s`'"]+)/g;
10
+ const MAX_FILE_BYTES = 256 * 1024; // skip anything larger — a mention shouldn't pull a huge blob
11
+ const INLINE_CAP = 32 * 1024; // per-file cap on what we actually inline
12
+ /** Return `text` with each `@path` that resolves to a real file appended as a fenced, labeled block.
13
+ * Unresolvable `@tokens` are left as-is. `cwd` defaults to process.cwd(); injectable for tests. */
14
+ export function expandFileMentions(text, cwd = process.cwd()) {
15
+ const blocks = [];
16
+ const seen = new Set();
17
+ let m;
18
+ MENTION_RE.lastIndex = 0;
19
+ while ((m = MENTION_RE.exec(text))) {
20
+ const raw = m[1];
21
+ const p = raw.startsWith("~/") ? join(homedir(), raw.slice(2)) : raw.startsWith("/") ? raw : join(cwd, raw);
22
+ if (seen.has(p))
23
+ continue;
24
+ try {
25
+ const st = statSync(p);
26
+ if (!st.isFile() || st.size > MAX_FILE_BYTES)
27
+ continue;
28
+ seen.add(p);
29
+ blocks.push(`## @${raw} (inlined)\n\`\`\`\n${readFileSync(p, "utf8").slice(0, INLINE_CAP)}\n\`\`\``);
30
+ }
31
+ catch { /* not a real file — leave the @token as literal text */ }
32
+ }
33
+ return blocks.length ? `${text}\n\n${blocks.join("\n\n")}` : text;
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.34",
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": {