@moxxy/cli 0.25.0 → 0.27.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/dist/bin.js +97802 -130158
- package/package.json +4 -4
- package/dist/bin.js.map +0 -1
- package/dist/public/app.js +0 -54
- package/dist/public/index.html +0 -178
- package/dist/read-handler.js.map +0 -1
- package/dist/sidecar.js +0 -541
- package/dist/sidecar.js.map +0 -1
package/dist/public/index.html
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<!-- Defense-in-depth, mirrors the HTTP CSP header in channel.ts serveFile.
|
|
7
|
-
Scripts are 'self' only (no inline); the inline <style> below needs
|
|
8
|
-
style-src 'unsafe-inline'; connect-src permits the surface WebSocket. -->
|
|
9
|
-
<meta
|
|
10
|
-
http-equiv="Content-Security-Policy"
|
|
11
|
-
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' ws: wss:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
|
|
12
|
-
/>
|
|
13
|
-
<meta name="referrer" content="no-referrer" />
|
|
14
|
-
<title>moxxy</title>
|
|
15
|
-
<!--moxxy:base-->
|
|
16
|
-
<style>
|
|
17
|
-
:root {
|
|
18
|
-
--bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
|
|
19
|
-
--fg: #e6e9ef; --muted: #8b93a7; --accent: #5b8cff; --ok: #3fb950;
|
|
20
|
-
--warn: #d29922; --danger: #f85149; --radius: 10px;
|
|
21
|
-
}
|
|
22
|
-
* { box-sizing: border-box; }
|
|
23
|
-
body { margin: 0; background: var(--bg); color: var(--fg);
|
|
24
|
-
font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
|
|
25
|
-
.app { max-width: 760px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
|
|
26
|
-
header { display: flex; align-items: center; justify-content: space-between;
|
|
27
|
-
padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
|
|
28
|
-
header .status { font-weight: 400; font-size: 13px; color: var(--muted); }
|
|
29
|
-
header .status.ok { color: var(--ok); }
|
|
30
|
-
header .back { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
|
|
31
|
-
border-radius: 8px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; margin-right: 10px; }
|
|
32
|
-
main { flex: 1; padding: 18px; display: flex; flex-direction: column; gap: 18px; }
|
|
33
|
-
.empty { color: var(--muted); text-align: center; padding: 48px 0; }
|
|
34
|
-
footer { padding: 12px 18px; border-top: 1px solid var(--line); }
|
|
35
|
-
footer form { display: flex; gap: 8px; }
|
|
36
|
-
footer input { flex: 1; background: var(--panel2); border: 1px solid var(--line);
|
|
37
|
-
color: var(--fg); border-radius: var(--radius); padding: 10px 12px; font: inherit; }
|
|
38
|
-
footer button { background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
|
|
39
|
-
padding: 0 16px; font: inherit; font-weight: 600; cursor: pointer; }
|
|
40
|
-
.transcript { display: flex; flex-direction: column; gap: 8px; }
|
|
41
|
-
.msg { padding: 9px 12px; border-radius: var(--radius); max-width: 85%; white-space: pre-wrap; }
|
|
42
|
-
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
|
|
43
|
-
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
|
|
44
|
-
.turn-status { color: var(--muted); font-size: 13px; font-style: italic; }
|
|
45
|
-
.turn-status.err { color: var(--danger); font-style: normal; }
|
|
46
|
-
/* view primitives */
|
|
47
|
-
.v-title { font-size: 20px; margin: 0 0 12px; }
|
|
48
|
-
.v-stack { display: flex; flex-direction: column; }
|
|
49
|
-
.v-stack[data-gap="sm"], .v-row[data-gap="sm"] { gap: 6px; }
|
|
50
|
-
.v-stack[data-gap="md"], .v-row[data-gap="md"], .v-grid[data-gap="md"] { gap: 12px; }
|
|
51
|
-
.v-stack[data-gap="lg"], .v-row[data-gap="lg"], .v-grid[data-gap="lg"] { gap: 20px; }
|
|
52
|
-
.v-stack:not([data-gap]) { gap: 10px; }
|
|
53
|
-
.v-row { display: flex; flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
54
|
-
.v-row[data-align="start"] { align-items: flex-start; }
|
|
55
|
-
.v-row[data-align="end"] { align-items: flex-end; }
|
|
56
|
-
.v-row[data-justify="between"] { justify-content: space-between; }
|
|
57
|
-
.v-row[data-justify="center"] { justify-content: center; }
|
|
58
|
-
.v-row[data-justify="end"] { justify-content: flex-end; }
|
|
59
|
-
.v-grid { display: grid; gap: 12px; }
|
|
60
|
-
.v-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
|
|
61
|
-
.v-card[data-accent="success"] { border-left: 3px solid var(--ok); }
|
|
62
|
-
.v-card[data-accent="warn"] { border-left: 3px solid var(--warn); }
|
|
63
|
-
.v-card[data-accent="danger"] { border-left: 3px solid var(--danger); }
|
|
64
|
-
.v-card-title { font-weight: 600; margin-bottom: 8px; }
|
|
65
|
-
.v-divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
|
|
66
|
-
.v-heading { margin: 4px 0; }
|
|
67
|
-
.v-text[data-tone="muted"] { color: var(--muted); }
|
|
68
|
-
.v-text[data-tone="success"] { color: var(--ok); }
|
|
69
|
-
.v-text[data-tone="warn"] { color: var(--warn); }
|
|
70
|
-
.v-text[data-tone="danger"] { color: var(--danger); }
|
|
71
|
-
.v-text[data-weight="bold"] { font-weight: 700; }
|
|
72
|
-
.v-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px;
|
|
73
|
-
background: var(--panel2); border: 1px solid var(--line); }
|
|
74
|
-
.v-badge[data-tone="success"] { color: var(--ok); border-color: var(--ok); }
|
|
75
|
-
.v-badge[data-tone="warn"] { color: var(--warn); border-color: var(--warn); }
|
|
76
|
-
.v-badge[data-tone="danger"] { color: var(--danger); border-color: var(--danger); }
|
|
77
|
-
.v-image { max-width: 100%; border-radius: var(--radius); }
|
|
78
|
-
.v-link { color: var(--accent); }
|
|
79
|
-
.v-list { margin: 0; padding-left: 20px; }
|
|
80
|
-
.v-table { border-collapse: collapse; width: 100%; }
|
|
81
|
-
.v-table th, .v-table td { border: 1px solid var(--line); padding: 7px 10px; }
|
|
82
|
-
.v-table th { background: var(--panel2); }
|
|
83
|
-
.v-form { display: flex; flex-direction: column; gap: 12px; }
|
|
84
|
-
.v-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
|
|
85
|
-
.v-label { font-size: 13px; color: var(--muted); }
|
|
86
|
-
.v-field input, .v-field select { background: var(--panel2); border: 1px solid var(--line);
|
|
87
|
-
color: var(--fg); border-radius: 8px; padding: 8px 10px; font: inherit; }
|
|
88
|
-
.v-check { display: flex; align-items: center; gap: 6px; }
|
|
89
|
-
.v-form-actions { display: flex; gap: 8px; }
|
|
90
|
-
.v-btn { background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
|
|
91
|
-
border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
|
|
92
|
-
.v-btn[data-variant="primary"] { background: var(--accent); color: #fff; border-color: var(--accent); }
|
|
93
|
-
.v-btn[data-variant="danger"] { background: var(--danger); color: #fff; border-color: var(--danger); }
|
|
94
|
-
.v-unknown { color: var(--warn); font-size: 13px; }
|
|
95
|
-
/* loading states */
|
|
96
|
-
.v-spinner { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 8px 0; }
|
|
97
|
-
.v-spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line);
|
|
98
|
-
border-top-color: var(--accent); animation: v-rot 0.8s linear infinite; }
|
|
99
|
-
@keyframes v-rot { to { transform: rotate(360deg); } }
|
|
100
|
-
.v-skeleton { display: flex; flex-direction: column; gap: 10px; }
|
|
101
|
-
.v-skel-row { height: 16px; border-radius: 6px;
|
|
102
|
-
background: linear-gradient(90deg, var(--panel) 25%, var(--panel2) 37%, var(--panel) 63%);
|
|
103
|
-
background-size: 400% 100%; animation: v-shimmer 1.4s ease infinite; }
|
|
104
|
-
.v-skel-row:nth-child(odd) { width: 90%; }
|
|
105
|
-
.v-skel-row:nth-child(3n) { width: 70%; }
|
|
106
|
-
@keyframes v-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
|
|
107
|
-
/* floating chat */
|
|
108
|
-
.chat-fab { position: fixed; right: 20px; bottom: 20px; width: 52px; height: 52px;
|
|
109
|
-
border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 22px;
|
|
110
|
-
cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,0.45); display: flex; align-items: center;
|
|
111
|
-
justify-content: center; z-index: 50; }
|
|
112
|
-
.chat-fab:hover { filter: brightness(1.08); }
|
|
113
|
-
.chat-dot { position: absolute; top: 10px; right: 10px; width: 10px; height: 10px;
|
|
114
|
-
border-radius: 50%; background: var(--danger); border: 2px solid var(--bg); }
|
|
115
|
-
.chat-panel { position: fixed; right: 20px; bottom: 20px; width: min(380px, calc(100vw - 40px));
|
|
116
|
-
height: min(520px, calc(100vh - 40px)); background: var(--panel); border: 1px solid var(--line);
|
|
117
|
-
border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); display: flex; flex-direction: column;
|
|
118
|
-
overflow: hidden; z-index: 50; }
|
|
119
|
-
.chat-head { display: flex; align-items: center; justify-content: space-between;
|
|
120
|
-
padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
|
|
121
|
-
.chat-x { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1;
|
|
122
|
-
cursor: pointer; padding: 0 4px; }
|
|
123
|
-
.chat-x:hover { color: var(--fg); }
|
|
124
|
-
.chat-msgs { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
|
|
125
|
-
.chat-hint { color: var(--muted); font-size: 13px; }
|
|
126
|
-
.chat-msg { padding: 8px 11px; border-radius: 12px; max-width: 88%; white-space: pre-wrap;
|
|
127
|
-
word-break: break-word; font-size: 14px; }
|
|
128
|
-
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
|
|
129
|
-
.chat-msg.assistant { align-self: flex-start; background: var(--panel2); border: 1px solid var(--line); }
|
|
130
|
-
.chat-status { color: var(--muted); font-size: 12px; font-style: italic; }
|
|
131
|
-
.chat-status.err { color: var(--danger); font-style: normal; }
|
|
132
|
-
.chat-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
|
|
133
|
-
.chat-input input { flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
|
|
134
|
-
border-radius: 10px; padding: 9px 11px; font: inherit; }
|
|
135
|
-
.chat-input button { background: var(--accent); color: #fff; border: 0; border-radius: 10px;
|
|
136
|
-
padding: 0 14px; font: inherit; font-weight: 600; cursor: pointer; }
|
|
137
|
-
/* file diff */
|
|
138
|
-
.v-diff { align-self: stretch; border: 1px solid var(--line); border-radius: var(--radius);
|
|
139
|
-
overflow: hidden; background: var(--panel); font-size: 12.5px; }
|
|
140
|
-
.v-diff-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
|
141
|
-
padding: 6px 10px; background: var(--panel2); border-bottom: 1px solid var(--line); }
|
|
142
|
-
.v-diff-path { font-weight: 600; word-break: break-all; }
|
|
143
|
-
.v-diff-sum { color: var(--ok); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
144
|
-
white-space: nowrap; }
|
|
145
|
-
.v-diff-body { overflow-x: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
146
|
-
line-height: 1.45; }
|
|
147
|
-
.v-diff-row { display: flex; white-space: pre; }
|
|
148
|
-
.v-diff-no { flex: 0 0 auto; width: 3.5em; padding: 0 8px; text-align: right; color: var(--muted);
|
|
149
|
-
user-select: none; border-right: 1px solid var(--line); }
|
|
150
|
-
.v-diff-mark { flex: 0 0 auto; width: 1.5em; text-align: center; user-select: none; color: var(--muted); }
|
|
151
|
-
.v-diff-text { flex: 1 1 auto; padding-right: 10px; }
|
|
152
|
-
.v-diff-ctx { color: var(--muted); }
|
|
153
|
-
.v-diff-add { background: rgba(63, 185, 80, 0.16); }
|
|
154
|
-
.v-diff-add .v-diff-mark, .v-diff-add .v-diff-text { color: var(--ok); }
|
|
155
|
-
.v-diff-del { background: rgba(248, 81, 73, 0.16); }
|
|
156
|
-
.v-diff-del .v-diff-mark, .v-diff-del .v-diff-text { color: var(--danger); }
|
|
157
|
-
.v-diff-gap { color: var(--muted); opacity: 0.6; }
|
|
158
|
-
.v-diff-gap .v-diff-mark { color: var(--muted); }
|
|
159
|
-
.v-diff-trunc { padding: 4px 10px; color: var(--warn); font-size: 12px;
|
|
160
|
-
border-top: 1px solid var(--line); background: var(--panel2); }
|
|
161
|
-
/* Screen-reader-only: present in the a11y tree (live-region announcements)
|
|
162
|
-
but visually removed. Standard clip pattern, no layout impact. */
|
|
163
|
-
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0;
|
|
164
|
-
margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
|
|
165
|
-
/* Respect a user's reduced-motion preference: stop the infinite spinner
|
|
166
|
-
and skeleton shimmer (vestibular safety) and neutralize transitions. */
|
|
167
|
-
@media (prefers-reduced-motion: reduce) {
|
|
168
|
-
.v-spin { animation: none; }
|
|
169
|
-
.v-skel-row { animation: none; background: var(--panel2); }
|
|
170
|
-
* { transition: none !important; scroll-behavior: auto !important; }
|
|
171
|
-
}
|
|
172
|
-
</style>
|
|
173
|
-
</head>
|
|
174
|
-
<body>
|
|
175
|
-
<div id="root"></div>
|
|
176
|
-
<script src="app.js"></script>
|
|
177
|
-
</body>
|
|
178
|
-
</html>
|
package/dist/read-handler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../tools-builtin/src/util.ts","../../tools-builtin/src/read-handler.ts"],"names":["fs","MoxxyError"],"mappings":";;;;;;AAeO,SAAS,WAAA,CAAY,KAAa,MAAA,EAAwB;AAC/D,EAAA,IAAS,IAAA,CAAA,UAAA,CAAW,MAAM,CAAA,EAAG,OAAY,eAAU,MAAM,CAAA;AACzD,EAAA,OAAY,IAAA,CAAA,OAAA,CAAQ,KAAK,MAAM,CAAA;AACjC;AAiDO,IAAM,cAAA,GAAiB,KAAK,IAAA,GAAO,IAAA;AAOnC,SAAS,sBAAsB,CAAA,EAAmB;AACvD,EAAA,MAAM,IAAA,GAAO,CAAA,CAAE,UAAA,CAAW,CAAA,CAAE,SAAS,CAAC,CAAA;AACtC,EAAA,IAAI,IAAA,IAAQ,SAAU,IAAA,IAAQ,KAAA,SAAe,CAAA,CAAE,KAAA,CAAM,GAAG,EAAE,CAAA;AAC1D,EAAA,OAAO,CAAA;AACT;AAEO,SAAS,WAAA,CAAY,GAAW,GAAA,EAAqB;AAC1D,EAAA,IAAI,CAAA,CAAE,MAAA,IAAU,GAAA,EAAK,OAAO,CAAA;AAC5B,EAAA,OAAO,sBAAsB,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,GAAG,CAAC,CAAA,GAAI;AAAA,eAAA,EAAoB,CAAA,CAAE,SAAS,GAAG,CAAA,OAAA,CAAA;AACpF;;;AC1DA,eAAsB,WAAA,CAAY,OAAkB,GAAA,EAAmC;AACrF,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,GAAS,CAAA,EAAG,KAAA,GAAQ,KAAK,GAAI,KAAA;AAChD,EAAA,MAAM,QAAA,GAAW,WAAA,CAAY,GAAA,CAAI,GAAA,EAAK,SAAS,CAAA;AAK/C,EAAA,IAAI;AACF,IAAA,MAAM,EAAA,GAAK,GAAA,CAAI,EAAA,GAAK,MAAM,GAAA,CAAI,EAAA,CAAG,IAAA,CAAK,QAAQ,CAAA,GAAI,MAAMA,QAAA,CAAG,IAAA,CAAK,QAAQ,CAAA;AACxE,IAAA,IAAI,EAAA,CAAG,OAAO,cAAA,EAAgB;AAC5B,MAAA,MAAM,IAAIC,UAAAA,CAAW;AAAA,QACnB,IAAA,EAAM,YAAA;AAAA,QACN,OAAA,EAAS,CAAA,4BAAA,EAA0B,EAAA,CAAG,IAAI,eAAe,cAAc,CAAA,2DAAA;AAAA,OACxE,CAAA;AAAA,IACH;AAAA,EACF,SAAS,CAAA,EAAG;AAGV,IAAA,IAAI,CAAA,YAAaA,YAAY,MAAM,CAAA;AAAA,EACrC;AAOA,EAAA,MAAM,OAAO,GAAA,CAAI,EAAA,GACb,MAAM,GAAA,CAAI,EAAA,CAAG,SAAS,QAAA,EAAU,EAAE,UAAU,MAAA,EAAQ,KACnD,MAAMD,QAAA,CAAG,SAAS,QAAQ,CAAA,EAAG,SAAS,MAAM,CAAA;AACjD,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAC7B,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,KAAA,CAAM,MAAA,EAAQ,SAAS,KAAK,CAAA;AACjD,EAAA,MAAM,QAAA,GAAW,OACd,GAAA,CAAI,CAAC,MAAM,CAAA,KAAM,CAAA,EAAG,OAAO,MAAA,GAAS,CAAA,GAAI,CAAC,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAC,IAAK,IAAI,CAAA,CAAE,CAAA,CACtE,IAAA,CAAK,IAAI,CAAA;AACZ,EAAA,OAAO,WAAA,CAAY,UAAU,GAAO,CAAA;AACtC","file":"read-handler.js","sourcesContent":["import * as path from 'node:path';\nimport { MoxxyError } from '@moxxy/sdk';\n\n/**\n * Normalize `target` against `cwd`. Returns an absolute path. **Does not\n * sandbox** — absolute targets and `../` traversal are allowed by design,\n * because the agent often needs to touch paths outside the cwd (`~/.config`,\n * `/etc/...`). Safety against unintended access lives at the permission\n * layer (`PermissionEngine` + the resolver), which prompts the user before\n * any tool runs. Tools that genuinely need to confine to cwd should use\n * `resolveWithinCwd` instead.\n *\n * Renamed from `resolveSafe` to make the contract honest — the old name\n * implied a sandbox it never performed.\n */\nexport function resolvePath(cwd: string, target: string): string {\n if (path.isAbsolute(target)) return path.normalize(target);\n return path.resolve(cwd, target);\n}\n\n/**\n * Like `resolvePath` but throws if the result escapes `cwd`. Use for tools\n * that should be strictly confined (rare).\n */\nexport function resolveWithinCwd(cwd: string, target: string): string {\n const resolved = resolvePath(cwd, target);\n const cwdAbs = path.resolve(cwd);\n const rel = path.relative(cwdAbs, resolved);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new MoxxyError({\n code: 'TOOL_ERROR',\n message: `Path escapes cwd: ${target} (resolved to ${resolved}, outside ${cwdAbs})`,\n });\n }\n return resolved;\n}\n\n/**\n * @deprecated Use `resolvePath` (no behavior change — only honest name).\n * Kept as a thin alias so external callers still compile.\n */\nexport const resolveSafe = resolvePath;\n\n/**\n * Directory names skipped during recursive traversal by the Glob and Grep\n * tools — build outputs and VCS metadata that are never useful search targets.\n * Kept in one place so the two walkers stay in sync.\n */\nexport const IGNORED_DIR_NAMES = new Set(['node_modules', '.git', 'dist', '.turbo']);\n\n/**\n * Max directory depth either walker (Glob, Grep) descends into. Both recurse\n * into real subdirectories; an unbounded recursion over a pathologically deep\n * tree (build artifacts, fuzzers, a symlink-free but genuinely-deep checkout)\n * would otherwise overflow the call stack with an uncatchable RangeError that\n * the per-dir `try/catch` (which only wraps `readdir`) cannot recover from.\n * Shared so the two walkers stay in sync.\n */\nexport const MAX_WALK_DEPTH = 100;\n\n/**\n * Files larger than this are not slurped fully into the heap — a multi-hundred-MB\n * log, a SQLite db, or a media blob would otherwise OOM the process on a path the\n * model invokes constantly (Read/Edit/Write/Grep). Result clamping bounds the\n * OUTPUT, not the per-file working set; this bounds the working set. Shared so\n * every file-reading built-in caps at the same point.\n */\nexport const MAX_FILE_BYTES = 10 * 1024 * 1024;\n\n/**\n * Slicing a string on a UTF-16 code-unit boundary can split an astral-plane\n * char (emoji, some CJK) and leave a lone surrogate that re-encodes to U+FFFD.\n * Drop a trailing lone high surrogate so the truncated text stays valid.\n */\nexport function dropDanglingSurrogate(s: string): string {\n const last = s.charCodeAt(s.length - 1);\n if (last >= 0xd800 && last <= 0xdbff) return s.slice(0, -1);\n return s;\n}\n\nexport function clampString(s: string, max: number): string {\n if (s.length <= max) return s;\n return dropDanglingSurrogate(s.slice(0, max)) + `\\n... [truncated ${s.length - max} chars]`;\n}\n\n/**\n * Cap the length of a model/user-supplied glob before it is compiled to a\n * RegExp. `globToRegExp` only ever emits linear constructs (`.*`, `[^/]*`,\n * `[^/]`), so it can't produce catastrophic backtracking — but an unbounded\n * input would still build an unbounded regex and let an absurd pattern grow\n * the heap. A 4 KB ceiling is far beyond any real glob and degrades to a clean\n * error instead of a silent blowup. Mirrors Grep's `MAX_PATTERN_LEN`.\n */\nexport const MAX_GLOB_LEN = 4_096;\n\n/**\n * Convert a glob pattern (`**`, `*`, `?`) to an anchored RegExp. Shared by\n * the Glob and Grep tools; not exposed externally. Rejects absurdly long\n * inputs rather than compiling them.\n */\nexport function globToRegExp(pattern: string): RegExp {\n if (pattern.length > MAX_GLOB_LEN) {\n throw new MoxxyError({\n code: 'TOOL_ERROR',\n message: `glob pattern too long (${pattern.length} > ${MAX_GLOB_LEN} chars).`,\n });\n }\n const escaped = pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\?/g, '[^/]')\n .replace(/\\*\\*\\//g, '(?:.*/)?')\n .replace(/\\*\\*/g, '.*')\n .replace(/\\*/g, '[^/]*');\n return new RegExp('^' + escaped + '$');\n}\n","import { promises as fs } from 'node:fs';\nimport { MoxxyError, type BrokeredFs } from '@moxxy/sdk';\nimport { clampString, MAX_FILE_BYTES, resolvePath } from './util.js';\n\n/**\n * Pure handler module for the Read tool. Lives in its own file so the\n * worker_threads isolator (`@moxxy/isolator-worker`) can re-import it\n * on the worker side via the `handlerModule` reference declared in\n * `read.ts`.\n *\n * Closures can't cross thread boundaries; module exports can.\n */\nexport interface ReadInput {\n readonly file_path: string;\n readonly offset?: number;\n readonly limit?: number;\n}\n\nexport interface ReadCtxLike {\n readonly cwd: string;\n /** Capability-mediated fs. Present when invoked under an isolator that\n * brokers (`@moxxy/isolator-worker`); absent under `none` / `inproc`. */\n readonly fs?: BrokeredFs;\n}\n\nexport async function readHandler(input: ReadInput, ctx: ReadCtxLike): Promise<string> {\n const { file_path, offset = 0, limit = 2000 } = input;\n const resolved = resolvePath(ctx.cwd, file_path);\n // Refuse to slurp a file that exceeds the working-set cap. Without this the\n // whole file (and a per-line array of it) is materialized in the heap before\n // any output clamp — a multi-hundred-MB log / db / media blob OOM-kills the\n // process on a path the model invokes constantly. (Grep already guards this.)\n try {\n const st = ctx.fs ? await ctx.fs.stat(resolved) : await fs.stat(resolved);\n if (st.size > MAX_FILE_BYTES) {\n throw new MoxxyError({\n code: 'TOOL_ERROR',\n message: `Read: file too large — ${st.size} bytes (max ${MAX_FILE_BYTES}). Use Grep, or narrow with offset/limit on a smaller file.`,\n });\n }\n } catch (e) {\n // Re-throw our own size error; let a genuine stat failure (missing file,\n // perms) fall through to readFile so its error message is preserved.\n if (e instanceof MoxxyError) throw e;\n }\n // Use the brokered fs when the isolator provides one. The broker\n // re-validates the path against the tool's declared `caps.fs.read`\n // on the parent side, so reads outside the cap are denied at the\n // boundary regardless of what's in the input. Without a broker\n // (inproc / none), fall back to direct `node:fs` — input-level\n // cap-check already screened the file_path.\n const text = ctx.fs\n ? await ctx.fs.readFile(resolved, { encoding: 'utf8' })\n : (await fs.readFile(resolved)).toString('utf8');\n const lines = text.split('\\n');\n const sliced = lines.slice(offset, offset + limit);\n const numbered = sliced\n .map((line, i) => `${String(offset + i + 1).padStart(6, ' ')}\\t${line}`)\n .join('\\n');\n return clampString(numbered, 200_000);\n}\n"]}
|