@0perator/operator 0.2.0 → 0.2.2-next.0

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.
Files changed (117) hide show
  1. package/README.md +5 -4
  2. package/dist/auth/byo.js +1 -1
  3. package/dist/auth/commands.js +15 -5
  4. package/dist/auth/identity.js +1 -0
  5. package/dist/auth/staff.js +55 -0
  6. package/dist/autonomy/agent-cli.js +1 -1
  7. package/dist/autonomy/delegate-mode.js +2 -2
  8. package/dist/autonomy/delegate.js +41 -14
  9. package/dist/autonomy/headless.js +37 -10
  10. package/dist/autonomy/index.js +2 -4
  11. package/dist/autonomy/pr-isolation.js +92 -0
  12. package/dist/autonomy/pr-preflight.js +474 -0
  13. package/dist/autonomy/session-factory.js +13 -12
  14. package/dist/autonomy/subagent-model.js +17 -7
  15. package/dist/background/capacity.js +136 -0
  16. package/dist/background/evidence.js +42 -0
  17. package/dist/background/index.js +311 -44
  18. package/dist/background/lane-phase.js +60 -0
  19. package/dist/background/lane-summary.js +151 -0
  20. package/dist/background/notices.js +12 -3
  21. package/dist/background/synthesis.js +25 -0
  22. package/dist/browser/capture.js +505 -0
  23. package/dist/browser/engine.js +4 -3
  24. package/dist/browser/page-capture.js +167 -0
  25. package/dist/browser/png.js +116 -0
  26. package/dist/browser/visual-compare.js +229 -0
  27. package/dist/bus/beam-drop.js +55 -0
  28. package/dist/bus/inbox.js +157 -7
  29. package/dist/cli.js +316 -120
  30. package/dist/config/features.js +3 -3
  31. package/dist/config/managed.js +40 -1
  32. package/dist/config/persona.js +80 -29
  33. package/dist/config/product-hosts.js +2 -0
  34. package/dist/config/settings.js +289 -31
  35. package/dist/config/skills-index.js +37 -14
  36. package/dist/config/staff-prompt.js +12 -0
  37. package/dist/engine/agent.js +52 -41
  38. package/dist/engine/aurora.js +54 -13
  39. package/dist/engine/batch-scheduler.js +4 -13
  40. package/dist/engine/compaction.js +1 -1
  41. package/dist/engine/continuation.js +66 -32
  42. package/dist/engine/decision-points.js +2 -3
  43. package/dist/engine/fanout.js +16 -0
  44. package/dist/engine/identity.js +42 -0
  45. package/dist/engine/loop-guard.js +26 -83
  46. package/dist/engine/messages.js +2 -2
  47. package/dist/engine/moa.js +23 -1
  48. package/dist/engine/native-vision-node.js +72 -0
  49. package/dist/engine/native-vision.js +103 -0
  50. package/dist/engine/net-error.js +15 -0
  51. package/dist/engine/rolling-summary.js +142 -93
  52. package/dist/engine/verify-gate.js +37 -7
  53. package/dist/engine/waterfall.js +33 -0
  54. package/dist/gateway-cli.js +24 -4
  55. package/dist/memory/live-progress.js +4 -5
  56. package/dist/memory/session-index.js +3 -3
  57. package/dist/moa/codeact-lane.js +98 -0
  58. package/dist/moa/codeact-sandbox.js +409 -0
  59. package/dist/moa/codeact.js +140 -0
  60. package/dist/permissions/artifact-visibility.js +10 -0
  61. package/dist/permissions/index.js +2 -1
  62. package/dist/permissions/policy.js +9 -2
  63. package/dist/permissions/tier.js +13 -3
  64. package/dist/products/craft.js +92 -3
  65. package/dist/products/temple.js +20 -1
  66. package/dist/products/voice.js +112 -0
  67. package/dist/remote/grants.js +119 -0
  68. package/dist/remote/host.js +33 -5
  69. package/dist/router/free-models.js +5 -9
  70. package/dist/router/models.js +80 -26
  71. package/dist/router/provider-models.js +78 -0
  72. package/dist/router/router.js +15 -3
  73. package/dist/selfimprove/index.js +8 -6
  74. package/dist/selfimprove/lessons.js +23 -0
  75. package/dist/services/preflight.js +35 -91
  76. package/dist/session.js +316 -125
  77. package/dist/skills/catalogue.js +5 -2
  78. package/dist/skills/finder.js +4 -4
  79. package/dist/skills/install-guard.js +68 -0
  80. package/dist/skills/install.js +67 -0
  81. package/dist/toolchain/manifest.json +13 -13
  82. package/dist/tools/background-result.js +1 -1
  83. package/dist/tools/beam.js +246 -0
  84. package/dist/tools/classes.js +103 -0
  85. package/dist/tools/contract.js +1 -1
  86. package/dist/tools/craft.js +36 -2
  87. package/dist/tools/deferred.js +7 -3
  88. package/dist/tools/doc-text.js +1 -1
  89. package/dist/tools/executor.js +25 -15
  90. package/dist/tools/generation-gateway.js +94 -0
  91. package/dist/tools/registry.js +135 -158
  92. package/dist/tools/sandbox.js +6 -6
  93. package/dist/ui/App.js +17 -6
  94. package/dist/ui/ApprovalPrompt.js +1 -1
  95. package/dist/ui/BgPanel.js +15 -10
  96. package/dist/ui/Composer.js +44 -2
  97. package/dist/ui/Header.js +1 -6
  98. package/dist/ui/StatusRule.js +20 -8
  99. package/dist/ui/ToolStep.js +3 -3
  100. package/dist/ui/Transcript.js +41 -14
  101. package/dist/ui/batchLine.js +4 -4
  102. package/dist/ui/editdiff.js +2 -4
  103. package/dist/ui/format.js +4 -20
  104. package/dist/ui/liveTools.js +3 -3
  105. package/dist/ui/modelPicker.js +10 -6
  106. package/dist/ui/opsMode.js +20 -0
  107. package/dist/ui/phase.js +4 -2
  108. package/dist/ui/slashCommands.js +1 -0
  109. package/dist/ui/types.js +0 -2
  110. package/dist/ui/voice.js +185 -0
  111. package/dist/update-check.js +17 -6
  112. package/dist/update.js +1 -2
  113. package/dist/util/audio-io.js +82 -0
  114. package/dist/util/slash.js +2 -2
  115. package/dist/vision/pairs.js +239 -0
  116. package/package.json +1 -1
  117. package/dist/tools/mutating.js +0 -15
@@ -0,0 +1,136 @@
1
+ // Smart slots: how many sub-agent lanes run at once comes from the router's live capacity for the delegate route
2
+ // (portal/src/router/capacity.ts), not a fixed number. A lane starts only once the router has RESERVED a unit for it,
3
+ // so two spawns can never both take the last free unit, and every request the lane makes carries the reservation and
4
+ // goes to the leg it was given. A backend that comes up grows the pool on the next look; one that goes away shrinks it
5
+ // for new lanes only (a running lane keeps its reservation). An endpoint without the capacity API (a direct
6
+ // llama-server, a vendor) puts the scheduler back on the static cap it always had.
7
+ import { authHeaders } from "../engine/aurora.js";
8
+ export class CapacityUnavailable extends Error {
9
+ transient;
10
+ /** transient: the router did not answer in time or the connection dropped. It is busy, not absent, so the
11
+ * scheduler retries instead of falling back to the static cap. */
12
+ constructor(why, transient = false) {
13
+ super(why);
14
+ this.transient = transient;
15
+ this.name = "CapacityUnavailable";
16
+ }
17
+ }
18
+ /** A cap no live pool may exceed: each lane is a process-local session with its own context and tools. */
19
+ export const MAX_LANES = 8;
20
+ export const RESERVATION_TTL_MS = 120_000;
21
+ /** The hard ceiling on running lanes: KODE_ENDPOINT_SLOTS when set (an owner's explicit cap), else MAX_LANES. */
22
+ export function laneCeiling(env = process.env) {
23
+ const n = Number(env.KODE_ENDPOINT_SLOTS);
24
+ return Number.isFinite(n) && n >= 1 ? Math.min(MAX_LANES, Math.floor(n)) : MAX_LANES;
25
+ }
26
+ /** How many lanes may run: live = what is running plus what the router has free (bounded by the ceiling); static = the
27
+ * configured cap. Never below what is already running — shrinking only stops new lanes. */
28
+ export function laneBudget(mode, running, ceiling) {
29
+ if (mode.kind === "static")
30
+ return Math.max(running, Math.min(ceiling, mode.lanes));
31
+ const s = mode.snapshot;
32
+ if (!s)
33
+ return Math.max(running, 1);
34
+ const room = s.unbounded ? ceiling : running + s.free;
35
+ return Math.max(running, Math.min(ceiling, room));
36
+ }
37
+ /** "subagent 4/6 busy · flash 3/4, planner 1/2 · kimi down" for the lanes header. */
38
+ export function poolLine(s) {
39
+ const up = s.legs.filter((l) => l.healthy);
40
+ const down = s.legs.filter((l) => !l.healthy).map((l) => l.name);
41
+ const legs = up.map((l) => (l.maxInflight !== undefined ? `${l.name} ${l.maxInflight - (l.free ?? 0)}/${l.maxInflight}` : `${l.name} open`));
42
+ const head = s.total ? `${s.route} ${s.total - s.free}/${s.total} busy` : `${s.route} pool`;
43
+ return [head, legs.join(", "), down.length ? `${down.join(", ")} down` : ""].filter(Boolean).join(" · ");
44
+ }
45
+ /** The capacity API of the router at `base` for `route`. `spare` is the main turn's route: the router keeps one unit of
46
+ * the leg main lands on free. */
47
+ export function routerCapacity(o) {
48
+ const base = o.base.replace(/\/v1\/?$/, "").replace(/\/+$/, "");
49
+ const f = o.fetch ?? ((u, i) => fetch(u, i));
50
+ const headers = () => ({ "content-type": "application/json", ...authHeaders({ base, model: o.route }) });
51
+ const call = async (path, body) => {
52
+ let r;
53
+ try {
54
+ // 10 s: these are tiny requests, but on a busy box the router's reply can take a few seconds.
55
+ r = await f(`${base}${path}`, { method: body === undefined ? "GET" : "POST", headers: headers(), ...(body === undefined ? {} : { body: JSON.stringify(body) }), signal: AbortSignal.timeout(o.timeoutMs ?? 10_000) });
56
+ }
57
+ catch (e) {
58
+ throw new CapacityUnavailable(`capacity API unreachable: ${e.message}`, true);
59
+ }
60
+ // An older router or a vendor (404/405), a refused key, or a router without this route: no live capacity here.
61
+ if ([401, 403, 404, 405].includes(r.status))
62
+ throw new CapacityUnavailable(`no capacity API for ${o.route} at ${base} (HTTP ${r.status})`);
63
+ return r;
64
+ };
65
+ const snapshotOf = (j) => {
66
+ const s = j;
67
+ return s && Array.isArray(s.legs) && typeof s.free === "number" ? s : undefined;
68
+ };
69
+ return {
70
+ base, route: o.route,
71
+ async snapshot() {
72
+ const r = await call(`/v1/capacity?route=${encodeURIComponent(o.route)}`);
73
+ const s = r.ok ? snapshotOf(await r.json().catch(() => undefined)) : undefined;
74
+ if (!s)
75
+ throw new CapacityUnavailable(`capacity API answered HTTP ${r.status}`);
76
+ return s;
77
+ },
78
+ async reserve(session) {
79
+ const spare = o.spare?.();
80
+ const r = await call("/v1/capacity/reserve", { route: o.route, session, ttlMs: RESERVATION_TTL_MS, ...(spare ? { spare } : {}) });
81
+ const j = await r.json().catch(() => ({}));
82
+ if (r.ok && j.leaseId && j.leg)
83
+ return { ok: true, leaseId: j.leaseId, leg: j.leg };
84
+ if (r.status === 409)
85
+ return { ok: false, reason: j.error?.message ?? `${o.route} is busy`, snapshot: snapshotOf(j.capacity) };
86
+ throw new CapacityUnavailable(`reserve answered HTTP ${r.status}`);
87
+ },
88
+ async renew(leaseId) {
89
+ try {
90
+ return (await call("/v1/capacity/renew", { leaseId, ttlMs: RESERVATION_TTL_MS })).ok;
91
+ }
92
+ catch {
93
+ return false;
94
+ }
95
+ },
96
+ async release(leaseId) {
97
+ try {
98
+ await call("/v1/capacity/release", { leaseId });
99
+ }
100
+ catch { /* the TTL gives it back */ }
101
+ },
102
+ };
103
+ }
104
+ /** The base a model's requests go to first and the name it is asked for there. */
105
+ export function capacityTarget(p) {
106
+ const ep = p?.endpoint ?? p?.endpoints?.[0];
107
+ if (!p || !ep)
108
+ return undefined;
109
+ return { base: ep.replace(/\/v1\/?$/, "").replace(/\/+$/, ""), route: p.endpointModels?.[0] ?? p.model ?? p.id };
110
+ }
111
+ /** The capacity source for the delegate model, or undefined when it has no endpoint to ask. `mainModel` is read on every
112
+ * reserve: when main's requests go to the same router, its route is the one whose leg keeps a unit for the main turn. */
113
+ export function delegateCapacity(registry, delegate, mainModel, fetch) {
114
+ const t = capacityTarget(registry.find((p) => p.id === delegate));
115
+ if (!t)
116
+ return undefined;
117
+ const spare = () => {
118
+ const m = capacityTarget(registry.find((p) => p.id === mainModel()));
119
+ return m && m.base === t.base ? m.route : undefined;
120
+ };
121
+ return routerCapacity({ ...t, spare, fetch });
122
+ }
123
+ /** The owner's delegate route as a capacity source, only once its router answers the capacity API for it: undefined
124
+ * for an unset route, one with no endpoint, or an endpoint that is not the router (the caller keeps what it had). */
125
+ export async function liveDelegateRoute(registry, route, mainModel, fetch) {
126
+ const source = route ? delegateCapacity(registry, route, mainModel, fetch) : undefined;
127
+ if (!source)
128
+ return undefined;
129
+ try {
130
+ await source.snapshot();
131
+ return source;
132
+ }
133
+ catch {
134
+ return undefined;
135
+ }
136
+ }
@@ -0,0 +1,42 @@
1
+ // Evidence-size guard. Sibling agents handed the same large input each pay its full prefill (11/27: a status turn
2
+ // prefilled 561K tokens because three agents re-read the same 210 KB digest). Two sources: identical large blocks in their
3
+ // briefs, and the same file read by several of them. Pure: the manager records, this groups.
4
+ import { createHash } from "node:crypto";
5
+ /** Shared input at or above this many tokens (≈ chars/4) is worth a warning. */
6
+ export const EVIDENCE_TOKENS = 50_000;
7
+ const BLOCK_MIN_CHARS = 1_000;
8
+ const hash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 16);
9
+ /** One record per large paragraph of a brief: pasted context shows up as the same paragraphs in several briefs. */
10
+ export function briefRecords(agent, brief) {
11
+ return brief.split(/\n\s*\n/).filter((p) => p.length >= BLOCK_MIN_CHARS).map((p) => ({ agent, key: `brief:${hash(p)}`, label: "brief context", chars: p.length }));
12
+ }
13
+ /** A file read: keyed by path, so partial reads of one file still count as the same evidence. */
14
+ export function readRecord(agent, path, chars) {
15
+ return { agent, key: `file:${path}`, label: path.split("/").pop() || path, chars };
16
+ }
17
+ /** Inputs that two or more agents each received at ≥ `minTokens`: brief blocks shared by the same set of agents are
18
+ * summed (a digest pasted into three briefs is many paragraphs), files are taken per path at each agent's largest read. */
19
+ export function evidenceOverlap(records, minTokens = EVIDENCE_TOKENS) {
20
+ const byKey = new Map();
21
+ for (const r of records) {
22
+ const e = byKey.get(r.key) ?? { label: r.label, per: new Map() };
23
+ e.per.set(r.agent, Math.max(e.per.get(r.agent) ?? 0, r.chars));
24
+ byKey.set(r.key, e);
25
+ }
26
+ const groups = new Map();
27
+ for (const [key, e] of byKey) {
28
+ if (e.per.size < 2)
29
+ continue;
30
+ const agents = [...e.per.keys()].sort();
31
+ const chars = Math.min(...e.per.values());
32
+ const g = key.startsWith("brief:") ? `brief|${agents.join(",")}` : key;
33
+ const prev = groups.get(g);
34
+ groups.set(g, prev ? { ...prev, chars: prev.chars + chars } : { label: e.label, agents, chars });
35
+ }
36
+ return [...groups.values()].filter((o) => o.chars / 4 >= minTokens).sort((a, b) => b.chars - a.chars);
37
+ }
38
+ /** "3 agents re-reading the same 210 KB digest.md: give each a distinct slice". */
39
+ export function overlapLine(o) {
40
+ const size = o.chars >= 1_000_000 ? `${(o.chars / 1_000_000).toFixed(1)} MB` : `${Math.round(o.chars / 1000)} KB`;
41
+ return `${o.agents.length} agents re-reading the same ${size} ${o.label} (${o.agents.join(", ")}): give each a distinct slice`;
42
+ }