@0perator/operator 0.1.33 → 0.1.35

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.33";
22
+ const VERSION = "0.1.35";
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).
@@ -149,6 +150,7 @@ const HELP = [
149
150
  " /services ensure/inspect the service lever (aurora+autopilot+searxng); /services stop",
150
151
  " /audit [n] recent tool + control-plane events from the audit trail (default 15)",
151
152
  " /dashboard launch the live swarm console (watches every Operator session)",
153
+ " /plan plan mode: read-only research + propose a plan (/plan again to execute)",
152
154
  " /compact force-compact the conversation now",
153
155
  " /remember <note> store a note to recall in future sessions",
154
156
  " /memory [query] show remembered notes (all, or matching query)",
@@ -185,6 +187,7 @@ function Root() {
185
187
  // setLive re-render that already happens, so there's no performance cost and no animation timer.
186
188
  const [bgAgents, setBgAgents] = useState([]);
187
189
  const [authUser, setAuthUser] = useState(""); // signed-in identity for the status rule
190
+ const [planMode, setPlanMode] = useState(false); // /plan: read-only research + propose, shown as a status badge
188
191
  const [elapsed, setElapsed] = useState(0); // live seconds since the current turn started (ticked by a
189
192
  const turnStartRef = useRef(0); // timer, so the clock advances even during a long reasoning
190
193
  // phase where no content tokens stream — that was the "timer stuck" bug (Ink only re-renders on deltas).
@@ -368,7 +371,7 @@ function Root() {
368
371
  setElapsed(0);
369
372
  setStat("thinking");
370
373
  try {
371
- const outcome = await session.send(text, {
374
+ const outcome = await session.send(expandFileMentions(text), {
372
375
  onRoute: (label, pct) => { setRoute(label); setCtxPct(pct); remoteRef.current?.setStatus(pct, label); },
373
376
  onDelta: (chunk) => {
374
377
  liveText.current += chunk;
@@ -555,6 +558,15 @@ function Root() {
555
558
  sys("endpoints:\n" + s.endpoints().map((e) => ` ${h[e.name] ? "●" : "○"} ${e.name} ${e.base} ${e.model} ctx ${e.ctxWindow.toLocaleString()}`).join("\n"));
556
559
  break;
557
560
  }
561
+ case "plan": {
562
+ const on = !s.inPlanMode();
563
+ s.setPlanMode(on);
564
+ setPlanMode(on);
565
+ sys(on
566
+ ? "◔ plan mode ON — I'll research read-only and propose a plan; writes/edits/shell mutations are blocked. /plan again to approve + execute."
567
+ : "plan mode OFF — back to normal execution.");
568
+ break;
569
+ }
558
570
  case "audit": {
559
571
  // The human-supervisor view of the frozen event stream: recent tool decisions + control events
560
572
  // (tier denials, signature lines, RC) straight from the audit JSONL. Read-only.
@@ -730,7 +742,7 @@ function Root() {
730
742
  const liveMetrics = active
731
743
  ? `${SPIN[Math.floor(elapsed * 4) % SPIN.length]} ${fmtMeta(elapsed, liveTok)}`
732
744
  : metrics;
733
- 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, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, approval: approval, onApprovalDecide: (allow, always) => {
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) => {
734
746
  const cur = approval;
735
747
  if (cur)
736
748
  settleApproval(cur.id, allow, always); // first-wins with any remote follower answer
package/dist/session.js CHANGED
@@ -63,6 +63,7 @@ export class Session {
63
63
  memory;
64
64
  wantRecall;
65
65
  recallBlock = ""; // memory recalled on the first turn, folded into the system prompt thereafter
66
+ planMode = false; // /plan: research read-only + propose a plan, no mutations until the owner approves
66
67
  recalled = false;
67
68
  constructor(cfg = {}) {
68
69
  // Per-session tool registry: the base set, plus `spawn_agent` when the shell provides a delegate
@@ -91,14 +92,40 @@ export class Session {
91
92
  /** The effective system prompt: the base persona plus any memory recalled this session. Injected as
92
93
  * ONE system prompt — never a second system message, which 400s llama.cpp's chat template. */
93
94
  sys() {
94
- if (!this.recallBlock)
95
- return this.systemPrompt;
96
- return this.systemPrompt ? `${this.systemPrompt}\n\n${this.recallBlock}` : this.recallBlock;
95
+ const base = this.recallBlock
96
+ ? (this.systemPrompt ? `${this.systemPrompt}\n\n${this.recallBlock}` : this.recallBlock)
97
+ : this.systemPrompt;
98
+ if (!this.planMode)
99
+ return base;
100
+ // Plan mode: the model researches read-only and proposes a plan; the read-only enforcement is in
101
+ // buildTools (mutating tools are denied), and this directive shapes the output shape.
102
+ const plan = `\n\n## PLAN MODE (active)\nYou are in plan mode. Investigate with READ-ONLY tools only ` +
103
+ `(read/grep/list/search) — file writes, edits, shell mutations and git are BLOCKED and will be ` +
104
+ `refused. Do NOT attempt to change anything. When you understand the task, STOP and present a ` +
105
+ `concise, numbered plan of the exact steps you would take, then wait. The owner exits plan mode ` +
106
+ `(/plan) to let you execute.`;
107
+ return (base ?? "") + plan;
97
108
  }
98
109
  /** Compose the tool executor: local tools + MCP (composite) with the permission/audit layer on top.
99
- * withPermissions returns the composite UNCHANGED when the policy is inert (bypass) — zero overhead. */
110
+ * withPermissions returns the composite UNCHANGED when the policy is inert (bypass) — zero overhead.
111
+ * In plan mode a read-only gated policy (no approver → mutating tools fail-safe deny) overrides the
112
+ * normal policy, so nothing can be modified regardless of the owner's mode/tier. */
100
113
  buildTools() {
101
- return withPermissions(withMcp(this.executor, this.hub), this.policy, { approve: this.approve, sink: this.eventSink, actor: this.eventActor, session: this.sessionId });
114
+ const policy = this.planMode
115
+ ? new PermissionPolicy({ mode: "gated", tier: this.policy.currentTier() }) // read-only: safe tools allow, mutating ask→deny (no approve fn)
116
+ : this.policy;
117
+ const approve = this.planMode ? undefined : this.approve; // no approver in plan mode = hard read-only
118
+ return withPermissions(withMcp(this.executor, this.hub), policy, { approve, sink: this.eventSink, actor: this.eventActor, session: this.sessionId });
119
+ }
120
+ /** Enter/leave plan mode (/plan). Read-only research + a proposed plan until the owner approves. */
121
+ setPlanMode(on) {
122
+ if (this.planMode === on)
123
+ return;
124
+ this.planMode = on;
125
+ this.tools = this.buildTools();
126
+ }
127
+ inPlanMode() {
128
+ return this.planMode;
102
129
  }
103
130
  /** Is the currently-selected endpoint reachable? Lets the shell fail clearly before a turn. */
104
131
  health() {
package/dist/ui/App.js CHANGED
@@ -9,10 +9,10 @@ import { StepSpinner, RecoverSpinner } from "./ActivitySpinner.js";
9
9
  import { BgPanel } from "./BgPanel.js";
10
10
  import { ApprovalPrompt } from "./ApprovalPrompt.js";
11
11
  export function App(props) {
12
- const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, tier, bgAgents, onSubmit, onQueue, onInterrupt, approval = null, onApprovalDecide } = 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
13
  const thinking = status === "thinking" || status === "streaming";
14
14
  const showSpinner = status === "recovering" || status === "executing" || thinking;
15
15
  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
16
  : 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 }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle", suspended: !!approval }), _jsx(InputRule, {})] }));
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
18
  }
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Text } from "ink";
3
- export function StatusRule({ route, ctxPct, version, build, user, tier }) {
3
+ export function StatusRule({ route, ctxPct, version, build, user, tier, planMode }) {
4
4
  const who = user ? `⬤ ${user} · ` : "";
5
5
  const seat = tier && tier !== "admin" ? `⛨ ${tier} · ` : ""; // a narrowed seat is visible; the owner's admin is not
6
- // Info block: seat · identity · route · ctx% · version. Kept as one string so the width math is exact.
7
- const info = `${seat}${who}${route} · ${Math.round(ctxPct)}% · v${version}${build ? ` ·${build}` : ""}`;
6
+ const plan = planMode ? `◔ plan · ` : ""; // read-only research mode is visible while active
7
+ // Info block: plan · seat · identity · route · ctx% · version. One string so the width math is exact.
8
+ const info = `${plan}${seat}${who}${route} · ${Math.round(ctxPct)}% · v${version}${build ? ` ·${build}` : ""}`;
8
9
  // The full right-hand content, styled below in segments (✷ magenta, OPERATOR bold, info dim). This
9
10
  // plain string is only used to measure width so the leading rule fills precisely.
10
11
  const right = `✷ OPERATOR · ${info} ─`;
@@ -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.33",
3
+ "version": "0.1.35",
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": {