@0perator/operator 0.2.1 → 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.
- package/README.md +1 -1
- package/dist/auth/byo.js +1 -1
- package/dist/auth/commands.js +8 -2
- package/dist/autonomy/agent-cli.js +1 -1
- package/dist/autonomy/headless.js +30 -6
- package/dist/autonomy/pr-isolation.js +92 -0
- package/dist/autonomy/pr-preflight.js +474 -0
- package/dist/autonomy/session-factory.js +2 -0
- package/dist/browser/capture.js +505 -0
- package/dist/browser/engine.js +4 -3
- package/dist/browser/page-capture.js +167 -0
- package/dist/browser/png.js +116 -0
- package/dist/browser/visual-compare.js +229 -0
- package/dist/bus/beam-drop.js +55 -0
- package/dist/bus/inbox.js +7 -1
- package/dist/cli.js +126 -25
- package/dist/config/managed.js +40 -1
- package/dist/config/persona.js +51 -26
- package/dist/config/product-hosts.js +2 -0
- package/dist/config/settings.js +30 -13
- package/dist/config/skills-index.js +37 -14
- package/dist/engine/agent.js +1 -1
- package/dist/engine/aurora.js +18 -9
- package/dist/engine/continuation.js +36 -0
- package/dist/engine/identity.js +42 -0
- package/dist/engine/moa.js +7 -0
- package/dist/engine/net-error.js +15 -0
- package/dist/engine/rolling-summary.js +142 -93
- package/dist/engine/waterfall.js +33 -0
- package/dist/gateway-cli.js +10 -1
- package/dist/memory/session-index.js +3 -3
- package/dist/permissions/index.js +2 -1
- package/dist/permissions/policy.js +9 -2
- package/dist/permissions/tier.js +9 -1
- package/dist/products/craft.js +90 -1
- package/dist/products/temple.js +20 -1
- package/dist/products/voice.js +112 -0
- package/dist/router/free-models.js +5 -9
- package/dist/router/models.js +58 -14
- package/dist/router/provider-models.js +78 -0
- package/dist/router/router.js +15 -3
- package/dist/selfimprove/lessons.js +23 -0
- package/dist/session.js +192 -87
- package/dist/skills/catalogue.js +5 -2
- package/dist/skills/finder.js +4 -4
- package/dist/skills/install-guard.js +1 -1
- package/dist/tools/beam.js +246 -0
- package/dist/tools/craft.js +23 -0
- package/dist/tools/deferred.js +7 -3
- package/dist/tools/doc-text.js +1 -1
- package/dist/tools/registry.js +55 -9
- package/dist/tools/sandbox.js +6 -6
- package/dist/ui/App.js +3 -3
- package/dist/ui/ApprovalPrompt.js +1 -1
- package/dist/ui/Composer.js +44 -2
- package/dist/ui/StatusRule.js +2 -1
- package/dist/ui/Transcript.js +5 -0
- package/dist/ui/modelPicker.js +10 -6
- package/dist/ui/phase.js +4 -2
- package/dist/ui/slashCommands.js +1 -0
- package/dist/ui/voice.js +185 -0
- package/dist/update.js +1 -2
- package/dist/util/audio-io.js +82 -0
- package/dist/util/slash.js +2 -2
- package/dist/vision/pairs.js +239 -0
- package/package.json +1 -1
|
@@ -1,115 +1,164 @@
|
|
|
1
|
-
// Rolling session summary —
|
|
2
|
-
//
|
|
3
|
-
// and
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
1
|
+
// Rolling session summary — compaction whose cost is bounded by construction.
|
|
2
|
+
// The conversation is summarized AS IT GOES, in bounded passes: each pass reads the next chunk of messages nothing has
|
|
3
|
+
// covered yet and writes a short note for that chunk alone. The notes
|
|
4
|
+
// are appended, never rewritten, so a fact is digested once — measured 11/24: a chain that REWROTE one summary per
|
|
5
|
+
// pass kept 3 of 8 planted facts in its prose after 11 passes on a 2B model; one request over the same span kept 8.
|
|
6
|
+
// A pass never reads the whole conversation, so its cost is set by the chunk, not by how long the session is, which
|
|
7
|
+
// model runs it, or whether the server still holds the conversation in its prompt cache. Passes run in the background
|
|
8
|
+
// between turns; at compaction the notes are the summary, and only the uncovered tail is read live, in one request.
|
|
9
|
+
// When the notes outgrow their cap (a long session, or several compactions) one pass folds their older half into a
|
|
10
|
+
// single summary; the newer half is left as written.
|
|
11
|
+
// The watermark is a message count (how many leading messages the notes cover) plus a fingerprint of that prefix, so
|
|
12
|
+
// a conversation that was replaced under it (a resumed session) is never trusted.
|
|
13
|
+
import { writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
9
14
|
import { join, dirname } from "node:path";
|
|
10
15
|
import { operatorPath } from "../config/home.js";
|
|
11
|
-
|
|
12
|
-
const SUMMARY_FILE = join(
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import { SUMMARY_INSTRUCTION, applyAnchorVerification } from "./compaction.js";
|
|
17
|
+
const SUMMARY_FILE = join(operatorPath("session-memory"), "summary.md");
|
|
18
|
+
const CHARS_PER_TOKEN = 4; // the same prior as estimateTokensHeuristic: sizes here are bounds on a prompt, not a meter
|
|
19
|
+
export function rollingBudget(ctxWindow, summaryTokens) {
|
|
20
|
+
const chunkTokens = Math.max(2000, Math.min(16_000, Math.floor(ctxWindow / 16)));
|
|
21
|
+
return {
|
|
22
|
+
chunkTokens, dueTokens: Math.floor(chunkTokens / 2), liveTokens: Math.max(chunkTokens, Math.floor(ctxWindow / 2)),
|
|
23
|
+
noteTokens: Math.floor(summaryTokens / 4), capTokens: Math.max(2 * summaryTokens, Math.min(8192, Math.floor(ctxWindow / 32))), summaryTokens,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const clip = (s, cap) => s.length <= cap ? s : `${s.slice(0, Math.floor(cap * 0.7))}\n[… ${s.length - cap} chars clipped …]\n${s.slice(-(Math.floor(cap * 0.3) - 40))}`;
|
|
27
|
+
/** One message as the summarizer reads it. No message takes more than a quarter of a chunk: one huge tool output
|
|
28
|
+
* cannot be the whole pass (its identifiers still reach the compacted note through compact()'s anchor index). */
|
|
29
|
+
function renderMsg(m, b) {
|
|
30
|
+
let s = `${m.role}: ${m.content ?? ""}`;
|
|
31
|
+
for (const tc of m.tool_calls ?? [])
|
|
32
|
+
s += `\n→ ${tc.function?.name ?? ""}(${tc.function?.arguments ?? ""})`;
|
|
33
|
+
return clip(s, b.chunkTokens * CHARS_PER_TOKEN / 4);
|
|
34
|
+
}
|
|
35
|
+
/** The next chunk of `conversation[from, to)`: at least one message, then as many as fit `capTokens` (a background
|
|
36
|
+
* pass: one chunk; a live one: b.liveTokens). */
|
|
37
|
+
export function takeChunk(conversation, from, to, b, capTokens = b.chunkTokens) {
|
|
38
|
+
const cap = capTokens * CHARS_PER_TOKEN;
|
|
39
|
+
const parts = [];
|
|
40
|
+
let used = 0;
|
|
41
|
+
let end = from;
|
|
42
|
+
while (end < to) {
|
|
43
|
+
const r = renderMsg(conversation[end], b);
|
|
44
|
+
if (parts.length && used + r.length + 1 > cap)
|
|
45
|
+
break;
|
|
46
|
+
parts.push(r);
|
|
47
|
+
used += r.length + 1;
|
|
48
|
+
end++;
|
|
49
|
+
}
|
|
50
|
+
return { end, text: parts.join("\n"), tokens: Math.ceil(used / CHARS_PER_TOKEN) };
|
|
51
|
+
}
|
|
52
|
+
/** Tokens of `conversation[from, to)` as the summarizer would read them (every message clipped as in a chunk). */
|
|
53
|
+
export function uncoveredTokens(conversation, from, to, b) {
|
|
54
|
+
let chars = 0;
|
|
55
|
+
for (let i = from; i < to; i++)
|
|
56
|
+
chars += renderMsg(conversation[i], b).length + 1;
|
|
57
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
58
|
+
}
|
|
59
|
+
/** The notes inside an earlier compaction's message (compact(): header line, the summary, then the mechanical anchor
|
|
60
|
+
* / user-voice blocks, which compact() derives again from the span). They are adopted as the notes so far instead of
|
|
61
|
+
* being digested again. Undefined when `head` is not a compacted summary. */
|
|
62
|
+
export function adoptedNotes(head) {
|
|
63
|
+
if (!head?.startsWith("[Compacted summary"))
|
|
64
|
+
return undefined;
|
|
65
|
+
return head.slice(head.indexOf("\n") + 1).split(/\n\n(?:ANCHORS \(mechanically extracted|USER VOICE \(verbatim)/)[0];
|
|
66
|
+
}
|
|
67
|
+
/** Whether the notes have outgrown their cap and the next pass folds them. */
|
|
68
|
+
export const notesOverCap = (notes, b) => notes.length > b.capTokens * CHARS_PER_TOKEN;
|
|
69
|
+
/** What turns the summary contract compaction has always used (SUMMARY_INSTRUCTION, nine sections) into the contract
|
|
70
|
+
* for ONE chunk's note. Reused, not rewritten, and the chunk is all the model is shown — both measured 11/24 on a 2B
|
|
71
|
+
* model: a purpose-made FACTS-first format transcribed tool logs until its budget ran out (1 of 8 planted facts
|
|
72
|
+
* kept), and with the earlier notes shown as context it wrote the same note again for every later chunk. */
|
|
73
|
+
export const NOTE_SCOPE = " The conversation above is ONE PART of a longer one that is summarized part by part: write the note for these " +
|
|
74
|
+
"messages alone. A tool result is evidence, not content: keep from it what the assistant used or a later turn will " +
|
|
75
|
+
"need (the path, the version, the failing line), never a transcript of a log, a listing or a file body.";
|
|
76
|
+
/** A note pass's whole request: the chunk and the contract — nothing whose size depends on the session. */
|
|
77
|
+
export function notePrompt(chunkText, b, noteTokens = b.noteTokens) {
|
|
78
|
+
return `${chunkText}\n\n${SUMMARY_INSTRUCTION}${NOTE_SCOPE} Keep the note under ${Math.floor(noteTokens / 2)} words.`;
|
|
79
|
+
}
|
|
80
|
+
/** What a fold rewrites and what it leaves alone: the older half of the notes (cut between two notes) is folded, the
|
|
81
|
+
* newer half — what the next turns depend on, and the current state — is never touched by the model. */
|
|
82
|
+
export function foldSplit(notes) {
|
|
83
|
+
const cut = notes.lastIndexOf("\n\n", Math.floor(notes.length / 2));
|
|
84
|
+
const i = cut > 0 ? cut : Math.floor(notes.length / 2);
|
|
85
|
+
return [notes.slice(0, i), notes.slice(i).trimStart()];
|
|
86
|
+
}
|
|
87
|
+
/** A fold pass's whole request: the older half of the notes, as the '[Compacted summary …]' SUMMARY_INSTRUCTION
|
|
88
|
+
* already says to carry every concrete value forward from. Bounded: half the cap plus one live note. */
|
|
89
|
+
export function foldPrompt(old, b) {
|
|
90
|
+
return `[Compacted summary — the running notes of the conversation so far, oldest first]\n${clip(old, (b.capTokens + b.summaryTokens) * CHARS_PER_TOKEN)}\n\n` +
|
|
91
|
+
`${SUMMARY_INSTRUCTION} Keep the whole note under ${Math.floor(b.summaryTokens / 2)} words: tighten prose, never drop a concrete value.`;
|
|
92
|
+
}
|
|
93
|
+
/** The notes after a fold: [what the model made of the older half] + [the newer half, as it was]. The fold is held to
|
|
94
|
+
* compaction's own proof (applyAnchorVerification): every identifier the older notes held and the fold dropped is
|
|
95
|
+
* appended verbatim, by code — measured 11/24, a 2B model folded 14K chars of notes into 1K and kept none of 8
|
|
96
|
+
* planted facts. Always under the cap (the oldest text goes first), so a fold is never due again at once. */
|
|
97
|
+
export function foldedNotes(old, folded, recent, b) {
|
|
98
|
+
const [durable, state] = splitState(folded.slice(0, b.summaryTokens * CHARS_PER_TOKEN));
|
|
99
|
+
const m = { role: "user", content: durable.trim() };
|
|
100
|
+
applyAnchorVerification(m, [{ role: "user", content: old }], [m, { role: "user", content: recent }]);
|
|
101
|
+
return appendNote(`${m.content}\n\n${state}`, recent).slice(-b.capTokens * CHARS_PER_TOKEN);
|
|
102
|
+
}
|
|
103
|
+
/** A note's durable sections, and its state: from the last PENDING heading (however the model dresses it) to the end. */
|
|
104
|
+
function splitState(s) {
|
|
105
|
+
const heads = [...s.matchAll(/^[\s#*\d.)]*PENDING\b/gm)];
|
|
106
|
+
const i = heads.length ? heads[heads.length - 1].index : -1;
|
|
107
|
+
return i < 0 ? [s, ""] : [s.slice(0, i), s.slice(i)];
|
|
108
|
+
}
|
|
109
|
+
/** The notes after one more: the new note's durable sections (1-6) are appended; its state — from the PENDING heading
|
|
110
|
+
* to the end: PENDING, CURRENT, NEXT STEP — replaces the old state, so the notes always end with the conversation as
|
|
111
|
+
* it now stands and never carry a stale "still open". A note with no PENDING heading leaves the old state in place. */
|
|
112
|
+
export function appendNote(notes, note) {
|
|
113
|
+
const [durable, state] = splitState(notes);
|
|
114
|
+
const [added, now] = splitState(note);
|
|
115
|
+
return [durable, added, now || state].map((p) => p.trim()).filter(Boolean).join("\n\n");
|
|
116
|
+
}
|
|
19
117
|
export class RollingSummarizer {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
summaryCache = "";
|
|
24
|
-
dirty = false;
|
|
25
|
-
// GW-27-U2: how many user-turns the CURRENT cached summary covers (turnCount at fire time).
|
|
26
|
-
// Without this, /compact cannot tell a summary that covers the whole evicted span from one that
|
|
27
|
-
// predates the newest N quiet turns — and silently drops the uncovered ones.
|
|
28
|
-
coveredThroughTurns = 0;
|
|
118
|
+
summary = "";
|
|
119
|
+
covered = 0;
|
|
120
|
+
mark = "";
|
|
29
121
|
path;
|
|
30
122
|
constructor(opts = {}) {
|
|
31
|
-
this.opts = { ...DEFAULTS, ...opts };
|
|
32
123
|
this.path = opts.summaryPath ?? SUMMARY_FILE;
|
|
33
|
-
// Load existing summary if present
|
|
34
|
-
if (existsSync(this.path)) {
|
|
35
|
-
this.summaryCache = readFileSync(this.path, "utf8");
|
|
36
|
-
}
|
|
37
124
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!this.opts.enabled)
|
|
41
|
-
return false;
|
|
42
|
-
this.lastUpdateTokens += outputTokens;
|
|
43
|
-
this.lastUpdateBatches += toolBatches;
|
|
44
|
-
// Check if we should trigger a summary
|
|
45
|
-
const minTokens = this.opts.minTokensSinceUpdate ?? DEFAULTS.minTokensSinceUpdate ?? 5000;
|
|
46
|
-
const minBatches = this.opts.minToolBatches ?? DEFAULTS.minToolBatches ?? 3;
|
|
47
|
-
const tokensOk = this.lastUpdateTokens >= minTokens;
|
|
48
|
-
const batchesOk = this.lastUpdateBatches >= minBatches;
|
|
49
|
-
if (tokensOk && batchesOk) {
|
|
50
|
-
this.dirty = true;
|
|
51
|
-
// Reset counters — the caller fires the actual summarize
|
|
52
|
-
this.lastUpdateTokens = 0;
|
|
53
|
-
this.lastUpdateBatches = 0;
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
125
|
+
static fingerprint(conversation, n) {
|
|
126
|
+
return `${n}:${conversation[0]?.content.slice(0, 80) ?? ""}:${conversation.slice(Math.max(0, n - 32), n).map((m) => m.role[0]).join("")}`;
|
|
57
127
|
}
|
|
58
|
-
/**
|
|
59
|
-
* user-turns the produced summary covers so /compact can verify coverage before trusting it
|
|
60
|
-
* (GW-27-U2). Omitted => coverage unknown => treated as covering nothing: safe, just falls back
|
|
61
|
-
* to the live summarize path. */
|
|
62
|
-
markSummaryFired(turnsCovered) {
|
|
63
|
-
this.dirty = false;
|
|
64
|
-
this.coveredThroughTurns = typeof turnsCovered === "number" ? turnsCovered : 0;
|
|
65
|
-
}
|
|
66
|
-
/** The fire-watermark: user-turns covered by the cached summary (0 = never fired / unknown). */
|
|
67
|
-
getCoveredThrough() {
|
|
68
|
-
return this.coveredThroughTurns;
|
|
69
|
-
}
|
|
70
|
-
/** Get the current cached summary (for /compact to use). Empty string if none. */
|
|
128
|
+
/** The notes on the first coveredCount(conversation) messages ("" when there are none). */
|
|
71
129
|
getSummary() {
|
|
72
|
-
return this.
|
|
130
|
+
return this.summary;
|
|
73
131
|
}
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
|
|
132
|
+
/** How many leading messages of THIS conversation the notes cover. 0 — and the notes dropped — when the
|
|
133
|
+
* conversation is not the one it was written from. */
|
|
134
|
+
coveredCount(conversation) {
|
|
135
|
+
if (!this.covered)
|
|
136
|
+
return 0;
|
|
137
|
+
if (this.covered > conversation.length || RollingSummarizer.fingerprint(conversation, this.covered) !== this.mark)
|
|
138
|
+
this.clear();
|
|
139
|
+
return this.covered;
|
|
79
140
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
writeSummary() {
|
|
141
|
+
/** A pass finished: `summary` (the notes) now covers the first `n` messages of `conversation`. */
|
|
142
|
+
advance(summary, conversation, n) {
|
|
143
|
+
this.summary = summary;
|
|
144
|
+
this.covered = n;
|
|
145
|
+
this.mark = RollingSummarizer.fingerprint(conversation, n);
|
|
86
146
|
try {
|
|
87
|
-
// dirname(this.path), not the global dir: a per-session path (ACP, bots, delegate) lives elsewhere
|
|
88
|
-
//
|
|
147
|
+
// dirname(this.path), not the global dir: a per-session path (ACP, bots, delegate) lives elsewhere. The summary
|
|
148
|
+
// is a digest of the conversation, so owner-only.
|
|
89
149
|
mkdirSync(dirname(this.path), { recursive: true, mode: 0o700 });
|
|
90
|
-
writeFileSync(this.path,
|
|
150
|
+
writeFileSync(this.path, summary, { encoding: "utf8", mode: 0o600 });
|
|
91
151
|
}
|
|
92
152
|
catch { /* best-effort — summary persistence never blocks a turn */ }
|
|
93
153
|
}
|
|
94
|
-
/**
|
|
95
|
-
truncate(maxChars) {
|
|
96
|
-
const cap = maxChars || (this.opts?.maxSummaryChars ?? DEFAULTS.maxSummaryChars) || 4000;
|
|
97
|
-
if (this.summaryCache.length <= cap)
|
|
98
|
-
return this.summaryCache;
|
|
99
|
-
// Keep the tail — newer info is more relevant
|
|
100
|
-
return this.summaryCache.slice(-(cap - 50)) + "\n\n[summary truncated — older context in live conversation]";
|
|
101
|
-
}
|
|
102
|
-
/** Clear the rolling summary (for /new session). */
|
|
154
|
+
/** Forget the summary (a new session, or a compaction that folded it into the conversation). */
|
|
103
155
|
clear() {
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.lastUpdateTokens = 0;
|
|
108
|
-
this.lastUpdateBatches = 0;
|
|
156
|
+
this.summary = "";
|
|
157
|
+
this.covered = 0;
|
|
158
|
+
this.mark = "";
|
|
109
159
|
try {
|
|
110
|
-
if (existsSync(this.path))
|
|
160
|
+
if (existsSync(this.path))
|
|
111
161
|
writeFileSync(this.path, "", "utf8");
|
|
112
|
-
}
|
|
113
162
|
}
|
|
114
163
|
catch { /* best-effort */ }
|
|
115
164
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { inferType } from "./grandmaster.js";
|
|
2
|
+
export const WATERFALL_MODEL_ID = "waterfall";
|
|
3
|
+
export const EXTERNAL_EXECUTOR = "external-executor";
|
|
4
|
+
export const WATERFALL_SEATS = {
|
|
5
|
+
operator: { planner: "operator-planner", executor: "operator-executor" },
|
|
6
|
+
dexter: { planner: "dexter-planner", executor: "dexter-executor" },
|
|
7
|
+
moa: { planner: "moa-planner", executor: "moa-executor" },
|
|
8
|
+
};
|
|
9
|
+
/** A message this short with no work verb reads as conversation: one model answers it. */
|
|
10
|
+
const DIRECT_MAX_CHARS = 280;
|
|
11
|
+
/** The tier for a turn. The turn router decides when it answered (direct → operator; work: code edits → dexter,
|
|
12
|
+
* anything else → moa). Without it (a customer's box has no local router, or it was down/slow), the keyword rules
|
|
13
|
+
* decide, so a tier is always chosen and the turn never waits on a missing service. */
|
|
14
|
+
export function waterfallTier(text, route) {
|
|
15
|
+
if (route) {
|
|
16
|
+
if (route.route === "direct")
|
|
17
|
+
return { tier: "operator", by: "router" };
|
|
18
|
+
return { tier: route.role === "code-edit" ? "dexter" : "moa", by: "router" };
|
|
19
|
+
}
|
|
20
|
+
const kind = inferType(text);
|
|
21
|
+
if (kind === "code-edit")
|
|
22
|
+
return { tier: "dexter", by: "keywords" };
|
|
23
|
+
if (kind === "generic" && text.trim().length <= DIRECT_MAX_CHARS)
|
|
24
|
+
return { tier: "operator", by: "keywords" };
|
|
25
|
+
return { tier: "moa", by: "keywords" };
|
|
26
|
+
}
|
|
27
|
+
/** The planner team for a tier, or undefined for operator (one model, no plan). */
|
|
28
|
+
export function waterfallTeam(tier, opts = {}) {
|
|
29
|
+
if (tier === "operator")
|
|
30
|
+
return undefined;
|
|
31
|
+
const seats = WATERFALL_SEATS[tier];
|
|
32
|
+
return { planner: { id: seats.planner }, specialist: seats.executor, external: true, ...(opts.codeact ? { codeact: true } : {}) };
|
|
33
|
+
}
|
package/dist/gateway-cli.js
CHANGED
|
@@ -78,8 +78,17 @@ function gatewayBinary(home) {
|
|
|
78
78
|
catch { /* no link */ }
|
|
79
79
|
return { line: dangling ? `not linked (${link} → ${readlinkSync(link)} dangles)` : "not linked", toolchain: "unmanaged (legacy resolution: the gateway's PATH)" };
|
|
80
80
|
}
|
|
81
|
-
/** The executable image a live pid has mapped: the first txt entry lsof reports (-a: lsof
|
|
81
|
+
/** The executable image a live pid has mapped: /proc/<pid>/exe on Linux, else the first txt entry lsof reports (-a: lsof
|
|
82
|
+
* ORs its selectors without it). */
|
|
82
83
|
function mappedExecutable(pid) {
|
|
84
|
+
if (process.platform === "linux") {
|
|
85
|
+
try {
|
|
86
|
+
return readlinkSync(`/proc/${pid}/exe`);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
83
92
|
const r = spawnSync("/usr/sbin/lsof", ["-nP", "-a", "-p", String(pid), "-d", "txt", "-Fn"], { encoding: "utf8", timeout: 5000 });
|
|
84
93
|
return r.status === 0 ? r.stdout.split("\n").find((l) => l.startsWith("n"))?.slice(1) : undefined;
|
|
85
94
|
}
|
|
@@ -204,13 +204,12 @@ class JsonBackend {
|
|
|
204
204
|
// ---------------------------------------------------------------------------
|
|
205
205
|
let _backend = null;
|
|
206
206
|
let _backendHome = null;
|
|
207
|
-
async function openSqlite(
|
|
207
|
+
async function openSqlite() {
|
|
208
208
|
try {
|
|
209
209
|
const sqlite = await nodeImport("node:sqlite");
|
|
210
210
|
if (!sqlite?.DatabaseSync)
|
|
211
211
|
return null;
|
|
212
212
|
const dbPath = operatorPath("state", "state.db");
|
|
213
|
-
fs.mkdirSync(operatorPath("state"), { recursive: true });
|
|
214
213
|
const db = new sqlite.DatabaseSync(dbPath);
|
|
215
214
|
db.exec("CREATE TABLE IF NOT EXISTS sessions_meta (id TEXT PRIMARY KEY, mtime REAL NOT NULL)");
|
|
216
215
|
db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS sessions_fts USING fts5(id UNINDEXED, body)");
|
|
@@ -229,7 +228,8 @@ async function backend() {
|
|
|
229
228
|
_backend = null;
|
|
230
229
|
}
|
|
231
230
|
const { fs } = await fsp();
|
|
232
|
-
|
|
231
|
+
fs.mkdirSync(operatorPath("state"), { recursive: true });
|
|
232
|
+
_backend = (await openSqlite()) ?? new JsonBackend(operatorPath("state", "session-index.json"), fs);
|
|
233
233
|
_backendHome = home;
|
|
234
234
|
return _backend;
|
|
235
235
|
}
|
|
@@ -93,7 +93,8 @@ export function withPermissions(inner, policy, opts = {}) {
|
|
|
93
93
|
else {
|
|
94
94
|
if (line)
|
|
95
95
|
sinkNow()?.emit({ kind: "control", session, actor, control: { event: "signature_required", detail: `${line}: ${name}` } });
|
|
96
|
-
|
|
96
|
+
const ctx = policy.asksEachCall(name) ? { line: `${policy.currentTier()} seat`, once: true } : undefined;
|
|
97
|
+
approved = opts.approve ? await opts.approve(name, args, ctx) : false; // no approver ⇒ fail-safe deny
|
|
97
98
|
if (!approved) {
|
|
98
99
|
tool({ name, args: digest, decision, outcome: "denied", approved: false, ...batch }, argHash);
|
|
99
100
|
return refuse(DENIED(name, opts.approve ? "user" : "no-approver"));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// zero gates, zero overhead — programmatic/embedded callers opt in explicitly), but the SHIPPED
|
|
4
4
|
// settings default is "gated" (2026-10-23): mutating tools ask the user to Allow/Deny on spawn,
|
|
5
5
|
// Claude Code-style; shift+tab or settings leave it (permissions/modes.ts). "audit" allows-but-records.
|
|
6
|
-
import { registrySafeTools, tierAllows } from "./tier.js";
|
|
6
|
+
import { registrySafeTools, tierAllows, tierAsks } from "./tier.js";
|
|
7
7
|
import { signatureLine } from "./signature.js";
|
|
8
8
|
// Read-only tools (registry `safe: true`) — never gated unless a rule says otherwise. DERIVED from the
|
|
9
9
|
// registry, never hand-copied: the old 5-item copy drifted and gated/plan/dream/manual denied 12 safe tools.
|
|
@@ -90,6 +90,10 @@ export class PermissionPolicy {
|
|
|
90
90
|
allowsTool(name) {
|
|
91
91
|
return tierAllows(this.tier, name);
|
|
92
92
|
}
|
|
93
|
+
/** True iff this seat may call `name` only with a fresh approval each time: the approval is never remembered. */
|
|
94
|
+
asksEachCall(name) {
|
|
95
|
+
return tierAsks(this.tier, name);
|
|
96
|
+
}
|
|
93
97
|
/** Which human-signature line a call crosses (money/prod/destructive), or null. Live only while
|
|
94
98
|
* enforcing (never for the fully-inert local owner). The wrapper reports this on an approval. */
|
|
95
99
|
signatureLineFor(name, args) {
|
|
@@ -105,12 +109,15 @@ export class PermissionPolicy {
|
|
|
105
109
|
}
|
|
106
110
|
/** The decision for one tool call. Precedence: tier ceiling (a denied tool can't be granted by any
|
|
107
111
|
* rule) → human-signature line (money/prod/destructive always ask, beating a rule/mode; under plan
|
|
108
|
-
* review the approved plan answers — see planAnswer) →
|
|
112
|
+
* review the approved plan answers — see planAnswer) → tier ask (a seat's approval-only tools) → per-tool rule →
|
|
113
|
+
* allowlist pattern match → mode. */
|
|
109
114
|
decide(name, args) {
|
|
110
115
|
if (!this.allowsTool(name))
|
|
111
116
|
return "deny"; // tier ceiling — absolute, above rules and mode
|
|
112
117
|
if (this.signatureLineFor(name, args))
|
|
113
118
|
return "ask"; // human-signature line — always a human, beats rules
|
|
119
|
+
if (tierAsks(this.tier, name))
|
|
120
|
+
return "ask"; // granted to this seat only with approval, each call
|
|
114
121
|
const rule = this.rules[name];
|
|
115
122
|
if (rule)
|
|
116
123
|
return rule; // explicit override within the tier
|
package/dist/permissions/tier.js
CHANGED
|
@@ -26,7 +26,11 @@ const ENTERPRISE_MUTATING = [
|
|
|
26
26
|
"memory_store", "skill_save",
|
|
27
27
|
"artifact_create", "craft_update", "craft_delete",
|
|
28
28
|
];
|
|
29
|
-
|
|
29
|
+
// Enterprise seat, granted only with approval: every call asks, whatever the mode, rules or allow patterns
|
|
30
|
+
// (policy.ts decide). The Beam drop tools fetch over the LAN and write ~/Beam/in (open, get) or send a signed receipt
|
|
31
|
+
// (ack); owner decision 2026-11-30. beam_send (file egress) stays outside the seat, like file_upload.
|
|
32
|
+
const ENTERPRISE_ASK = ["beam_open", "beam_get", "beam_ack"];
|
|
33
|
+
const ENTERPRISE_ALLOW = new Set([...SAFE_TOOLS, ...ENTERPRISE_MUTATING, ...ENTERPRISE_ASK]);
|
|
30
34
|
// Readonly seat: inspection only = the registry-safe tools minus READONLY_SAFE_EXCLUDED. Every member is
|
|
31
35
|
// registry `safe: true`, so no workspace-mutating tool can be in it — widening it means marking a tool safe
|
|
32
36
|
// in the registry, which a dedicated permissions test holds to account.
|
|
@@ -45,3 +49,7 @@ export function tierAllows(tier, tool) {
|
|
|
45
49
|
default: return false;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
52
|
+
/** Whether `tier` may call `tool` only with a fresh approval each time. */
|
|
53
|
+
export function tierAsks(tier, tool) {
|
|
54
|
+
return tier === "enterprise" && ENTERPRISE_ASK.includes(tool);
|
|
55
|
+
}
|
package/dist/products/craft.js
CHANGED
|
@@ -97,5 +97,94 @@ export async function craftDelete(args, auth) {
|
|
|
97
97
|
const r = await temple.remove(id, auth);
|
|
98
98
|
return r.ok ? `deleted craft ${id}` : `error: ${r.error}`;
|
|
99
99
|
}
|
|
100
|
+
// ── rooms: working on one craft with other agents and its owner (temple.room) ──────────────────────────────────────
|
|
101
|
+
const ROOM_ACTIONS = ["join", "get", "post", "task_add", "claim", "release", "task_state", "edit", "wait", "link"];
|
|
102
|
+
function roomText(r, recent = 12) {
|
|
103
|
+
const tasks = r.tasks.map((t) => `- ${t.id} [${t.state}] ${t.title}${t.target ? ` · ${t.target}` : ""}${t.owner_handle ? ` · ${t.owner_handle}${t.lease_until ? ` (lease until ${t.lease_until})` : ""}` : ""} · rev ${t.rev}`);
|
|
104
|
+
const said = r.events.filter((e) => e.kind === "message" || e.kind === "conflict").slice(-recent)
|
|
105
|
+
.map((e) => ` #${e.seq} ${e.handle ?? "?"}${e.author_kind === "human" ? " (person)" : ""}: ${e.kind === "conflict" ? `conflict on ${str(e.data.path)}` : e.body}`);
|
|
106
|
+
return [`room of ${r.artifact.id} · "${r.artifact.title}" · v${r.artifact.version} · you can ${r.access} · cursor ${r.cursor}`,
|
|
107
|
+
`people: ${r.participants.map((p) => `${p.handle} (${p.kind})`).join(", ") || "none yet"}`,
|
|
108
|
+
`tasks:\n${tasks.join("\n") || " none"}`, said.length ? `recent:\n${said.join("\n")}` : "recent: nothing said yet",
|
|
109
|
+
`page for people: ${temple.room.link(r.artifact.id)}`].join("\n");
|
|
110
|
+
}
|
|
111
|
+
/** One tool for the room: join/get/post/task_add/claim/release/task_state/edit/wait/link. */
|
|
112
|
+
export async function craftRoom(args, auth) {
|
|
113
|
+
const action = str(args.action);
|
|
114
|
+
const id = str(args.id);
|
|
115
|
+
if (!ROOM_ACTIONS.includes(action))
|
|
116
|
+
return `error: craft_room needs \`action\`: ${ROOM_ACTIONS.join(" | ")}`;
|
|
117
|
+
if (!id)
|
|
118
|
+
return "error: craft_room needs `id` (the craft's id)";
|
|
119
|
+
if (action === "link")
|
|
120
|
+
return temple.room.link(id);
|
|
121
|
+
const denied = gate(auth);
|
|
122
|
+
if (denied)
|
|
123
|
+
return `error: ${denied}`;
|
|
124
|
+
const handle = str(args.handle) || "operator";
|
|
125
|
+
const taskId = str(args.task_id);
|
|
126
|
+
const need = (k) => `error: craft_room ${action} needs \`${k}\``;
|
|
127
|
+
switch (action) {
|
|
128
|
+
case "join":
|
|
129
|
+
case "get": {
|
|
130
|
+
const r = action === "join" ? await temple.room.join(id, handle, auth) : await temple.room.get(id, undefined, auth);
|
|
131
|
+
return r.ok ? roomText(r.value) : `error: ${r.error}`;
|
|
132
|
+
}
|
|
133
|
+
case "post": {
|
|
134
|
+
if (!str(args.body))
|
|
135
|
+
return need("body");
|
|
136
|
+
const r = await temple.room.post(id, handle, str(args.body), auth);
|
|
137
|
+
return r.ok ? `posted #${r.value.seq} as ${handle}` : `error: ${r.error}`;
|
|
138
|
+
}
|
|
139
|
+
case "task_add": {
|
|
140
|
+
if (!str(args.title))
|
|
141
|
+
return need("title");
|
|
142
|
+
const r = await temple.room.taskAdd(id, handle, { title: str(args.title), detail: str(args.detail) || undefined, target: str(args.target) || undefined }, auth);
|
|
143
|
+
return r.ok ? `added task ${r.value.id}${r.value.target ? ` on ${r.value.target}` : ""}` : `error: ${r.error}`;
|
|
144
|
+
}
|
|
145
|
+
case "claim":
|
|
146
|
+
case "release": {
|
|
147
|
+
if (!taskId)
|
|
148
|
+
return need("task_id");
|
|
149
|
+
const r = action === "claim" ? await temple.room.claim(id, handle, taskId, auth) : await temple.room.release(id, handle, taskId, auth);
|
|
150
|
+
if (!r.ok)
|
|
151
|
+
return r.code === "claimed" ? `error: ${r.error} — pick another task, or wait (craft_room wait) and try again` : `error: ${r.error}`;
|
|
152
|
+
return action === "claim" ? `you hold ${r.value.target ?? `task ${r.value.id}`} until ${r.value.lease_until ?? "you release it"} (rev ${r.value.rev}); each edit renews it` : `released task ${r.value.id}`;
|
|
153
|
+
}
|
|
154
|
+
case "task_state": {
|
|
155
|
+
const state = str(args.state);
|
|
156
|
+
if (!taskId || !/^(review|done|blocked|open)$/.test(state))
|
|
157
|
+
return need("task_id` and `state` (review | done | blocked | open)");
|
|
158
|
+
const r = await temple.room.taskState(id, handle, taskId, state, Number(args.rev), str(args.note) || undefined, auth);
|
|
159
|
+
if (!r.ok)
|
|
160
|
+
return r.code === "stale_task" ? `error: ${r.error} — craft_room get, then retry with the task's current rev` : `error: ${r.error}`;
|
|
161
|
+
return `task ${r.value.id} is ${r.value.state} (rev ${r.value.rev})`;
|
|
162
|
+
}
|
|
163
|
+
case "edit": {
|
|
164
|
+
const path = str(args.path);
|
|
165
|
+
const base = Number(args.base_version);
|
|
166
|
+
if (!path || typeof args.content !== "string" || !Number.isInteger(base))
|
|
167
|
+
return need("path`, `content` and `base_version");
|
|
168
|
+
const r = await temple.room.edit(id, handle, path, args.content, base, auth);
|
|
169
|
+
if (r.ok)
|
|
170
|
+
return `saved ${path} as v${r.value.artifact.version}${r.value.rebased_from ? ` (applied on top of others' changes since v${r.value.rebased_from})` : ""}`;
|
|
171
|
+
if (r.code === "version_conflict") {
|
|
172
|
+
const live = (r.live ?? {});
|
|
173
|
+
return `conflict: ${path} changed in v${live.changed_in ?? "?"}${live.by ? ` by ${live.by}` : ""} after your base v${base}. Nothing was written. ` +
|
|
174
|
+
`Merge your change into the live file below and edit again with base_version ${live.version}.\n--- live ${path} (v${live.version}) ---\n${live.content ?? "(not shown: binary or over 256 KB; read it from the craft)"}`;
|
|
175
|
+
}
|
|
176
|
+
return `error: ${r.error}`;
|
|
177
|
+
}
|
|
178
|
+
case "wait": {
|
|
179
|
+
const r = await temple.room.wait(id, Number(args.after) || 0, Math.min(Math.max(Number(args.timeout_secs) || 20, 1), 25), auth);
|
|
180
|
+
if (!r.ok)
|
|
181
|
+
return `error: ${r.error}`;
|
|
182
|
+
if (!r.value.events.length)
|
|
183
|
+
return `nothing new (cursor ${r.value.cursor})`;
|
|
184
|
+
return r.value.events.map((e) => `#${e.seq} ${e.kind} ${e.handle ?? ""}: ${e.body || JSON.stringify(e.data)}`).join("\n") + `\ncursor ${r.value.cursor}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return `error: unknown action ${action}`;
|
|
188
|
+
}
|
|
100
189
|
// Exposed for tests (pure helpers that don't touch the network).
|
|
101
|
-
export const _internal = { resolveScopes };
|
|
190
|
+
export const _internal = { resolveScopes, roomText };
|
package/dist/products/temple.js
CHANGED
|
@@ -56,7 +56,12 @@ export async function templeCall(tool, args, opts = {}) {
|
|
|
56
56
|
const err = value?.error;
|
|
57
57
|
if (rpc.result?.isError || err) {
|
|
58
58
|
const msg = err?.message ?? (typeof value === "string" ? value : "the artifact surface refused the call");
|
|
59
|
-
|
|
59
|
+
const out = { ok: false, error: err?.code === "unauthorized" ? `${msg} — sign in again (\`operator auth login\`)` : msg };
|
|
60
|
+
if (err?.code)
|
|
61
|
+
out.code = err.code;
|
|
62
|
+
if (err?.live !== undefined)
|
|
63
|
+
out.live = err.live;
|
|
64
|
+
return out;
|
|
60
65
|
}
|
|
61
66
|
return { ok: true, value: value };
|
|
62
67
|
}
|
|
@@ -228,3 +233,17 @@ export const read = (id, auth) => templeCall("temple_read", { id }, { auth });
|
|
|
228
233
|
export const list = (limit = 20, auth) => templeCall("temple_list", { limit: Math.min(Math.max(limit, 1), 100) }, { auth });
|
|
229
234
|
export const remove = (id, auth) => templeCall("temple_delete", { id }, { auth });
|
|
230
235
|
export const format = { line };
|
|
236
|
+
export const room = {
|
|
237
|
+
join: (id, handle, auth) => templeCall("temple_room_join", { id, handle, kind: "agent" }, { auth }),
|
|
238
|
+
get: (id, after, auth) => templeCall("temple_room_get", after === undefined ? { id } : { id, after }, { auth }),
|
|
239
|
+
post: (id, handle, body, auth) => templeCall("temple_room_post", { id, handle, body }, { auth }),
|
|
240
|
+
taskAdd: (id, handle, task, auth) => templeCall("temple_room_task_add", { id, handle, ...task }, { auth }),
|
|
241
|
+
claim: (id, handle, task_id, auth) => templeCall("temple_room_claim", { id, handle, task_id }, { auth }),
|
|
242
|
+
release: (id, handle, task_id, auth) => templeCall("temple_room_release", { id, handle, task_id }, { auth }),
|
|
243
|
+
taskState: (id, handle, task_id, state, rev, note, auth) => templeCall("temple_room_task_state", { id, handle, task_id, state, rev, ...(note ? { note } : {}) }, { auth }),
|
|
244
|
+
edit: (id, handle, path, content, base_version, auth) => templeCall("temple_room_edit", { id, handle, path, content, base_version }, { auth, timeoutMs: 120_000 }),
|
|
245
|
+
/** Long-poll: events after `after`, waiting up to `timeoutSecs` (Temple caps it at 25). */
|
|
246
|
+
wait: (id, after, timeoutSecs = 20, auth) => templeCall("temple_room_wait", { id, after, timeout_secs: timeoutSecs }, { auth, timeoutMs: (timeoutSecs + 15) * 1000 }),
|
|
247
|
+
/** The room page for a person, on the product's own host (`0perator.co/c/<id>/room`). */
|
|
248
|
+
link: (id) => `${shareUrl(id)}/room`,
|
|
249
|
+
};
|