moi-computer 0.6.0 → 0.7.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.
@@ -1 +1 @@
1
- import{Xc as t}from"/chunk-9y2zbzqz.js";if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function e(r){let{mount:a}=await import("/chunk-bv6vrvqf.js");a(r)}globalThis.__init=e;
1
+ import{Xc as t}from"/chunk-9y2zbzqz.js";if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function e(r){let{mount:a}=await import("/chunk-175bm057.js");a(r)}globalThis.__init=e;
package/dist/index.html CHANGED
@@ -21,7 +21,7 @@
21
21
  }
22
22
  </script>
23
23
 
24
- <link rel="stylesheet" crossorigin href="/chunk-agtetn7n.css"><script type="module" crossorigin src="/chunk-n6t40enm.js"></script></head>
24
+ <link rel="stylesheet" crossorigin href="/chunk-agtetn7n.css"><script type="module" crossorigin src="/chunk-w3tnv51j.js"></script></head>
25
25
  <body>
26
26
  <div id="root"></div>
27
27
 
package/lib/format.ts CHANGED
@@ -58,13 +58,27 @@ export type Part =
58
58
  | { type: 'source-document'; mediaType: string; title: string; sourceId: string }
59
59
  | { type: 'data'; name: string; data: unknown }
60
60
 
61
+ // Why a synthetic turn exists. Set by adapters — from the backend's own
62
+ // synthetic flag or from lib/system-messages.ts text classification. The UI
63
+ // hides every synthetic turn; the reason is kept for debugging and future
64
+ // "show system messages" affordances.
65
+ export type SyntheticTurnReason =
66
+ | 'skill-body'
67
+ | 'system-reminder'
68
+ | 'hook-output'
69
+ | 'slash-command'
70
+ | 'interrupt'
71
+ | 'other'
72
+
61
73
  export type TurnOrigin =
62
74
  | { kind: 'user-input' }
63
75
  | { kind: 'tool-return'; toolCallId: string }
64
- | {
65
- kind: 'synthetic'
66
- reason: 'skill-body' | 'system-reminder' | 'hook-output' | 'slash-command' | 'other'
67
- }
76
+ | { kind: 'synthetic'; reason: SyntheticTurnReason }
77
+ // A backend notification (e.g. a background-task completion) rewritten to
78
+ // readable text by lib/system-messages.ts. Rendered as plain text in the
79
+ // flow for now — a dedicated notification block is planned; key it off
80
+ // this origin.
81
+ | { kind: 'notification' }
68
82
  | { kind: 'subagent-prompt'; parentToolCallId: string }
69
83
  | { kind: 'inter-session' }
70
84
  | { kind: 'replay' }
@@ -0,0 +1,241 @@
1
+ // Provider-agnostic filtering of system machinery that agent backends leave
2
+ // in user-role message text: slash-command records, interrupt markers, local
3
+ // command output, injected reminder/hook envelopes. Chat bubbles must show
4
+ // only what a person actually typed; everything else is transcript plumbing
5
+ // the backend wrote for itself.
6
+ //
7
+ // The layer is a flat rule registry over plain text — it knows nothing about
8
+ // any harness's wire types, so every adapter (and the client, if it ever
9
+ // needs to) can share it. Two granularities:
10
+ //
11
+ // - `filterSystemText` one text block → cleaned text ('' when the whole
12
+ // block is machinery)
13
+ // - `classifySystemMessage` all of a message's text blocks → a synthetic-turn
14
+ // reason when the message as a whole is machinery
15
+ //
16
+ // Adapters keep a hide-classified message's raw text and mark the turn
17
+ // `origin: { kind: 'synthetic', reason }` — the same treatment the Claude SDK's
18
+ // own `isSynthetic` injections get — so nothing renders but nothing is lost.
19
+ // A `notify`-classified message instead SURFACES: its machinery is rewritten
20
+ // to a short readable sentence and the turn lands as
21
+ // `origin: { kind: 'notification' }`, plain text in the flow (a dedicated
22
+ // notification block in the UI is planned; the origin is its hook).
23
+ //
24
+ // Adding rules: append to SYSTEM_TEXT_RULES with a `<provider>:<what>` id.
25
+ // Registry order is priority — the first matching hide/notify rule decides the
26
+ // block. `hide`/`notify` patterns must match the WHOLE block (`^…$`), and
27
+ // tag-shaped ones require every element complete (open + close), so a person
28
+ // typing a tag name, pasting an unterminated fragment, or quoting a record
29
+ // with commentary around it keeps their bubble. Prose-anchored rules (the
30
+ // caveat, the compaction summary) are prefix matches by necessity — the
31
+ // accepted tradeoff is that pasting that exact sentence at position 0 hides
32
+ // the message. Keep `hide`/`notify` regexes non-global (`.test` on a /g
33
+ // regex is stateful) and `strip` regexes global.
34
+ //
35
+ // Current rules cover Claude Code. Sources: the patterns were verified against
36
+ // the `claude` CLI binary's strings and live `~/.claude/projects/*.jsonl`
37
+ // transcripts (see harness/claude-code/NOTES.md §4). OpenClaw's inbound-meta
38
+ // stripper stays in server/harness/openclaw/strip.ts — it mirrors upstream
39
+ // code verbatim and is synced against it, so it does not fold into this
40
+ // registry.
41
+ import type { SyntheticTurnReason } from './format'
42
+
43
+ export type SystemTextRule = {
44
+ // Stable `<provider>:<what>` id, for tests and debugging.
45
+ id: string
46
+ // The synthetic-turn reason a consumed match maps onto (lib/format.ts).
47
+ reason: SyntheticTurnReason
48
+ } &
49
+ // The whole text block is machinery when `test` matches.
50
+ (
51
+ | { action: 'hide'; test: RegExp }
52
+ // Machinery embedded in otherwise-real text: remove every `pattern` match,
53
+ // keep the rest. A block left empty counts as fully consumed.
54
+ | { action: 'strip'; pattern: RegExp }
55
+ // The whole block is machinery worth SHOWING: `render` turns the raw
56
+ // payload into a short readable sentence for the chat flow.
57
+ | { action: 'notify'; test: RegExp; render: (text: string) => string }
58
+ )
59
+
60
+ function xmlField(text: string, tag: string): string | undefined {
61
+ const m = text.match(new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`))
62
+ return m?.[1].trim() || undefined
63
+ }
64
+
65
+ // `<summary>` is already a human sentence ("Background command "…" completed
66
+ // (exit code 0)"); fall back to `<status>` (completed | failed | stopped)
67
+ // when a producer omits it.
68
+ function renderTaskNotification(text: string): string {
69
+ const summary = xmlField(text, 'summary')
70
+ if (summary) return summary
71
+ const status = xmlField(text, 'status')
72
+ return status ? `Background task ${status}` : 'Background task update'
73
+ }
74
+
75
+ export const SYSTEM_TEXT_RULES: readonly SystemTextRule[] = [
76
+ // -- Claude Code: whole-message records ------------------------------------
77
+ // Slash-command invocation, e.g. `<command-name>/clear</command-name>
78
+ // <command-message>clear</command-message><command-args></command-args>`.
79
+ // Tag order varies across CLI versions; `<command-contents>` carries older
80
+ // expanded-command payloads. The block must be NOTHING BUT complete
81
+ // `<command-*>…</command-*>` elements — a typed message that merely starts
82
+ // with the tag name, or a pasted record followed by a question, keeps its
83
+ // bubble.
84
+ {
85
+ id: 'claude-code:slash-command',
86
+ reason: 'slash-command',
87
+ action: 'hide',
88
+ test: /^\s*(<command-(name|message|args|contents)>[\s\S]*?<\/command-\2>\s*)+$/
89
+ },
90
+ // Output of a local slash command, e.g. `<local-command-stdout>Compacted.
91
+ // ...</local-command-stdout>` — the other half of the invocation record.
92
+ {
93
+ id: 'claude-code:local-command-output',
94
+ reason: 'slash-command',
95
+ action: 'hide',
96
+ test: /^\s*(<local-command-(stdout|stderr)>[\s\S]*?<\/local-command-\2>\s*)+$/
97
+ },
98
+ // Marker the CLI writes when the user aborts a turn (Esc / moi's stop).
99
+ // Full-block match only: someone quoting the marker inside a longer
100
+ // message keeps their bubble.
101
+ {
102
+ id: 'claude-code:interrupt',
103
+ reason: 'interrupt',
104
+ action: 'hide',
105
+ test: /^\s*\[Request interrupted by user( for tool use)?\]\s*$/
106
+ },
107
+ // `!command` bash mode: the input echo and its captured output
108
+ // (`<bash-stdout>…</bash-stdout><bash-stderr>…</bash-stderr>` ride in one
109
+ // message).
110
+ {
111
+ id: 'claude-code:bash-mode',
112
+ reason: 'other',
113
+ action: 'hide',
114
+ test: /^\s*(<bash-(input|stdout|stderr)>[\s\S]*?<\/bash-\2>\s*)+$/
115
+ },
116
+ // `#note` memory mode.
117
+ {
118
+ id: 'claude-code:memory-input',
119
+ reason: 'other',
120
+ action: 'hide',
121
+ test: /^\s*<user-memory-input>[\s\S]*?<\/user-memory-input>\s*$/
122
+ },
123
+ // Background-task completion notices delivered as user turns — surfaced
124
+ // as readable text rather than hidden. Local CC is the bare tag block;
125
+ // cloud harnesses prepend a NOT-USER-INPUT preamble. The test requires a
126
+ // COMPLETE `<task-notification>…</task-notification>` message: a person
127
+ // typing the tag name (or an unterminated fragment) keeps their bubble.
128
+ {
129
+ id: 'claude-code:task-notification',
130
+ reason: 'other',
131
+ action: 'notify',
132
+ test: /^\s*(\[SYSTEM NOTIFICATION - NOT USER INPUT\][\s\S]*)?<task-notification>[\s\S]*<\/task-notification>\s*$/,
133
+ render: renderTaskNotification
134
+ },
135
+ // Preamble injected before replayed local-command messages. `isMeta` in
136
+ // current CLI versions (so usually pre-hidden), but older transcripts
137
+ // carry it unflagged.
138
+ {
139
+ id: 'claude-code:local-command-caveat',
140
+ reason: 'other',
141
+ action: 'hide',
142
+ test: /^\s*Caveat: The messages below were generated by the user while running local commands\./
143
+ },
144
+ // Post-compaction continuation summary. Wording after the first sentence
145
+ // differs across CLI versions; the anchor sentence is stable.
146
+ {
147
+ id: 'claude-code:compact-continuation',
148
+ reason: 'other',
149
+ action: 'hide',
150
+ test: /^\s*This session is being continued from a previous conversation that ran out of context\./
151
+ },
152
+ // -- Claude Code: envelopes embedded in real messages ----------------------
153
+ // Ambient context reminders attached to (or around) typed text. moi's own
154
+ // envelope is stripped more precisely by lib/moi-context.ts before this
155
+ // rule sees the text; this catches every other reminder.
156
+ {
157
+ id: 'claude-code:system-reminder',
158
+ reason: 'system-reminder',
159
+ action: 'strip',
160
+ pattern: /<system-reminder>[\s\S]*?<\/system-reminder>\s*/g
161
+ },
162
+ // UserPromptSubmit hook stdout, appended to the message it ran for.
163
+ {
164
+ id: 'claude-code:prompt-submit-hook',
165
+ reason: 'hook-output',
166
+ action: 'strip',
167
+ pattern: /<user-prompt-submit-hook>[\s\S]*?<\/user-prompt-submit-hook>\s*/g
168
+ }
169
+ ]
170
+
171
+ export type SystemTextFilter = {
172
+ // What remains for display — '' when the block was entirely machinery,
173
+ // the readable rendering when a `notify` rule consumed it.
174
+ text: string
175
+ // Rules that consumed the block or stripped something from it, in
176
+ // application order (first entry names the dominant reason; its `action`
177
+ // says whether the block was hidden, rewritten, or partially stripped).
178
+ matched: SystemTextRule[]
179
+ }
180
+
181
+ export function filterSystemText(
182
+ text: string,
183
+ rules: readonly SystemTextRule[] = SYSTEM_TEXT_RULES
184
+ ): SystemTextFilter {
185
+ for (const rule of rules) {
186
+ if (rule.action === 'hide' && rule.test.test(text)) return { text: '', matched: [rule] }
187
+ if (rule.action === 'notify' && rule.test.test(text)) {
188
+ return { text: rule.render(text), matched: [rule] }
189
+ }
190
+ }
191
+ let out = text
192
+ const matched: SystemTextRule[] = []
193
+ for (const rule of rules) {
194
+ if (rule.action !== 'strip') continue
195
+ const next = out.replace(rule.pattern, '')
196
+ if (next !== out) {
197
+ matched.push(rule)
198
+ out = next
199
+ }
200
+ }
201
+ // Only a touched block gets its edges trimmed — untouched user text keeps
202
+ // its exact spacing.
203
+ return { text: matched.length > 0 ? out.trim() : out, matched }
204
+ }
205
+
206
+ export type SystemMessageVerdict =
207
+ // Transcript plumbing: keep the raw parts, mark the turn synthetic, hide.
208
+ | { kind: 'hide'; reason: SyntheticTurnReason; rules: SystemTextRule[] }
209
+ // A backend notification: show `text` as an `origin: 'notification'` turn.
210
+ | { kind: 'notification'; text: string; rules: SystemTextRule[] }
211
+
212
+ /**
213
+ * Decide whether a message is, in aggregate, all machinery: every text block
214
+ * either matched a hide/notify rule or was stripped down to nothing, and at
215
+ * least one rule fired. Blocks that were already blank neither veto nor
216
+ * count. Any notify match makes the whole message a notification (its
217
+ * rendered texts joined); real surviving text makes it a normal message.
218
+ */
219
+ export function classifySystemMessage(
220
+ texts: readonly string[],
221
+ rules: readonly SystemTextRule[] = SYSTEM_TEXT_RULES
222
+ ): SystemMessageVerdict | undefined {
223
+ const matched: SystemTextRule[] = []
224
+ const rendered: string[] = []
225
+ for (const text of texts) {
226
+ const f = filterSystemText(text, rules)
227
+ if (f.matched[0]?.action === 'notify') {
228
+ if (f.text.trim()) rendered.push(f.text)
229
+ matched.push(...f.matched)
230
+ continue
231
+ }
232
+ if (f.text.trim() !== '') return undefined
233
+ matched.push(...f.matched)
234
+ }
235
+ if (rendered.length > 0) {
236
+ return { kind: 'notification', text: rendered.join('\n\n'), rules: matched }
237
+ }
238
+ return matched.length > 0
239
+ ? { kind: 'hide', reason: matched[0].reason, rules: matched }
240
+ : undefined
241
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
@@ -0,0 +1,16 @@
1
+ // Is the `moi` CLI being run by a coding agent rather than a human at a
2
+ // terminal? Two tiers, following the sentry-cli SENTRY_PIPELINE lesson —
3
+ // announcement over sniffing:
4
+ //
5
+ // - MOI_AGENT=1 is moi's own announcement, injected into every agent session
6
+ // the server spawns (Claude Code and Codex harnesses). Exact for
7
+ // first-party agents — and necessary, because the Claude Code harness
8
+ // deliberately strips CLAUDECODE from its children.
9
+ // - The rest are third-party markers set by agent runtimes in the shells
10
+ // they spawn: Claude Code (CLAUDECODE), OpenAI Codex (CODEX_SANDBOX),
11
+ // Cursor (CURSOR_TRACE_ID). Best-effort — absence proves nothing.
12
+ const AGENT_ENV_MARKERS = ['MOI_AGENT', 'CLAUDECODE', 'CODEX_SANDBOX', 'CURSOR_TRACE_ID']
13
+
14
+ export function isAgentCaller(env: Record<string, string | undefined> = process.env): boolean {
15
+ return AGENT_ENV_MARKERS.some(marker => !!env[marker])
16
+ }